Commit Graph

30847 Commits

Author SHA1 Message Date
Taylor R Campbell
f051c36471 Pass NI_NUMERICSERV|NI_NUMERICSCOPE if NI_NUMERICHOST to getnameinfo.
This addresses part of https://github.com/heimdal/heimdal/issues/1214
to audit potential network leaks with [libdefaults] block_dns = yes.

NI_NUMERICHOST is _probably_ sufficient -- we probably won't see many
systems using NIS to look up service names by number if we fail to
specify NI_NUMERICSERV, and such systems probably require careful
auditing of their own.  And I don't know of any way NI_NUMERICSCOPE
could trigger network leaks.  But named scope ids are such a niche
option with IPv6 that setting it to forestall concerns can't hurt
much, and it makes reviewing easier if we just unconditionally flip
on all the numeric-only options.
2024-01-09 21:19:30 -06:00
Taylor R Campbell
4d39fe8d04 libroken: Fill in NI_NUMERICSCOPE as 0 if not defined.
This flag has defined by POSIX for years if not decades, but glibc
and Windows apparently still don't have it.

We will use it with getnameinfo, along with all other NI_NUMERICxxx
options, to minimize risk of network leaks with block_dns.
2024-01-09 21:19:30 -06:00
Taylor R Campbell
d73910c588 auditdns: Tidy up minor issues.
- Omit needless semicolon.
- Reject obscene service numbers in getaddrinfo.
- Fix mistake in comment about EAI_NONAME failure branch.

Leftovers from: https://github.com/heimdal/heimdal/pull/1213
2024-01-09 21:19:30 -06:00
Taylor R Campbell
e75e549252 Use AI_NUMERICSERV if block_dns, and use local getaddrinfo to audit.
This change has two parts:

1. Provide our own local implementation of numeric-only getaddrinfo
   in auditdns.c used to audit for DNS leaks, rather than deferring
   to dlsym(RTLD_NEXT, "getaddrinfo"), in terms of inet_pton.

   To keep review and implementation simple, this is limited to
   AI_NUMERICHOST _and_ AI_NUMERICSERV -- this requires that we
   arrange to pass AI_NUMERICSERV in callers too.

2. Wherever we implement block_dns, set AI_NUMERICSERV in addition to
   AI_NUMERICHOST as needed by the new auditdns.c getaddrinfo.

   (In principle this might also avoid other network leaks -- POSIX
   guarantees no name resolution service will be invoked, and gives
   NIS+ as an example.)

   One tiny semantic change to avoid tripping over the auditor:
   kadmin(8) now uses the string "749" rather than the string
   "kerberos-adm".  (Currently we don't audit kadmin(8) for DNS leaks
   but let's avoid leaving a rake to step on.)  Every other caller I
   found is already guaranteed to pass a numeric service rather than
   named service to getaddrinfo.

fix https://github.com/heimdal/heimdal/issues/1212
2024-01-09 16:06:32 -06:00
Joseph Sutton
1d8f4347bb lib/krb5: Fix error message typo
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-01-09 16:06:06 -06:00
Joseph Sutton
597b59dfb7 kdc: Return NEVER_VALID error code if ticket will never be valid
This matches the error generated by Windows.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2024-01-09 16:06:06 -06:00
Stefan Metzmacher
baf1930b6a kdc: don't fail salt_fastuser_crypto with r->req.req_body.cname == NULL for TGS-REQ 2024-01-09 16:06:06 -06:00
Joseph Sutton
4de8b3564e kdc: Fix leak with PK-INIT-Win2k
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2024-01-09 16:06:06 -06:00
Joseph Sutton
71fd391036 kdc: Fix spelling
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2024-01-09 16:06:06 -06:00
Stefan Metzmacher
13d3bcf1d0 cf/make-proto.pl: make JSON:PP optional
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2024-01-08 10:23:25 -06:00
Taylor R Campbell
ad23636db8 Add a test for potential DNS leaks via symbol interposition.
We build variants of kinit and test_acquire_cred that define their
own symbols rk_dns_lookup, gethostbyname, gethostbyname2, and
getaddrinfo to print a message and abort.  For getaddrinfo, we abort
only if the caller failed to specify AI_NUMERICHOST; otherwise we use
dlsym(RTLD_NEXT, "getaddrinfo") instead.

The new test tests/gss/check-nodns is like tests/gss/check-basic, but
uses kinit_auditdns and test_acquire_cred_auditdns to verify that no
DNS resolution happens.

This test should work and be effective on ELF platforms where the
getaddrinfo function is implemented by the symbol `getaddrinfo'.  On
non-ELF platforms it may not be effective -- and on platforms where
the getaddrinfo function is implemented by another symbol (like
`__getaddrinfo50') it may not work, but we can cross that bridge when
we come to it.

Verified manually that the test fails, with the expected error
message and abort, without `block_dns = yes' in krb5-nodns.conf.  No
automatic test of the mechanism for now because it might not work on
some platforms.

XXX check-nodns.in is copypasta of check-basic.in, should factor out
the common parts so they don't get out of sync.
2024-01-08 10:22:02 -06:00
Taylor R Campbell
e2c0d98965 lib/roken/syslog.c: Initialize hostname to avoid DNS lookups.
Previously, the hostname was initialized to `localhost'.  If it was
not cleared by init_syslog, init_logger_addr (via openlog) would
query gethostbyname to find the IP address of `localhost', which will
essentially always be 127.0.0.1.  But if it was cleared by
init_syslog, init_logger_addr would return 127.0.0.1 anyway.

This way, it always returns 127.0.0.1 in the event of no init_syslog
call, and avoids a DNS lookup.  You can always force a DNS lookup by
passing `localhost' to init_syslog explicitly, of course.

I'm not sure if anything even uses this as a fallback in Heimdal, but
let's avoid leaving a rake to step on.
2024-01-08 10:22:02 -06:00
Taylor R Campbell
19505537fd Ensure all calls to rk_dns_lookup are headed by a block_dns check.
Exception: In lib/kafs/common.c, we don't have a krb5_context in
which to check.
2024-01-08 10:22:02 -06:00
Taylor R Campbell
fd77c4000d Ensure all calls to getaddrinfo are headed by a block_dns check.
If block_dns is set, call getaddrinfo with AI_NUMERICHOST set and
AI_CANONNAME clear.

Some paths may not have set AI_CANONNAME, but it's easier to audit
this way when the getaddrinfo prelude is uniform across call sites,
and the compiler can optimize it away.
2024-01-08 10:22:02 -06:00
Taylor R Campbell
fa4c4430f6 krb5.conf(5): New block_dns option.
Documented and verified, not yet implemented.
2024-01-08 10:22:02 -06:00
Nicolas Williams
42e23b1777 roken: Export rk_getpwnam_r() (fix #1097)
Bug and fix reported by https://github.com/esaaprillia.
2024-01-05 11:39:19 -06:00
Jan Palus
ff41f2ae7c cf: link libatomic if needed
heimdal uses 8-byte (64-bits) atomic operations for a while now (ie in
lib/krb5/krcache.c). however some platforms (ie i386, i486, ARM < 7)
don't support them natively and need to be linked against libatomic in
order to implement functionallity from <stdatomic.h>.

if the header was found check 64-bit atomics work without any additional
libraries. if not try to add linking with libatomic. if that fails as
well fallback to -DHEIM_BASE_ATOMICS_FALLBACK

no change for platfroms without <stdatomic.h>

Fixes: #1186
2024-01-04 14:23:17 -06:00
Taylor R Campbell
3171398867 krb5: Fix use-after-free when debug is enabled with http_proxy.
Instead of freeing host->ai on return from submit_request in the
http_proxy path, stash the proxy's ai in another member host->freeai
which will be freed when host is freed.

Assumption: All hosts created in submit_request cease to be used
before any of them are freed, so it's safe to pick one host to hang
the proxy's ai on and free the ai when that host is freed.

fix https://github.com/heimdal/heimdal/issues/1205
2024-01-04 14:00:18 -06:00
Nicolas Williams
f455ea9834 tests: Make make -j8 check work
In the future we should also make it so that `make check` for `tests/db`,
`tests/gss`, and `tests/kdc` first initializes all the realms and starts all
the daemons, then runs the actual checks possibly in parallel, then shuts down
the daemons.  This will require quite a bit of work, so for now we just disable
parallel make in those directories.
2024-01-03 18:48:02 -06:00
Nicolas Williams
3253c49544 hx509: Add support for CSRs w/ BasicConstraints (fix) 2023-11-29 13:16:16 -06:00
Joseph Sutton
1baceedb87 krb5: Clarify documentation for ‘pkinit_revoke’ parameter
If multiple valid CRLs are specified for a particular issuer, only the
first will be checked. The documentation didn’t really hint at this.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:39:18 -05:00
Joseph Sutton
13dbc0a667 krb5: Fix typos in documentation
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:39:18 -05:00
Daria Phoebe Brashear
3c62b6f5d7 kadm5: allow setting password_lifetime to 0 to clear
when [kadmin] password_lifetime is set to 0, it should clear the time
rather than making the freshly-changed password expire immediately
2023-11-28 21:38:17 -05:00
Joseph Sutton
12ed86de90 wind: Fix incorrect coding lines
Commit e172367898 converted all these
files to UTF-8, but didn’t change the coding lines.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:37:56 -05:00
Joseph Sutton
ff079377f2 wind: Do not use invalid escape sequences
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:37:56 -05:00
Joseph Sutton
a9f21ebdac roken: Const-qualify sys_errlist
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:37:56 -05:00
Joseph Sutton
db5c8711b4 kuser: Fix error produced by compiling with FORTIFY_SOURCE=2
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:37:56 -05:00
Joseph Sutton
744678eb03 krb5: Use NULL pointer constant
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:37:56 -05:00
Joseph Sutton
0e9e1a4f31 kdc: Make parameter const
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:37:56 -05:00
Joseph Sutton
ffac143401 kdc: Finish incomplete log message
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:37:56 -05:00
Joseph Sutton
9ba687cf22 kdc: Fix log message
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:37:56 -05:00
Joseph Sutton
68b475fa2e kdc: Finish incomplete warning message
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:37:56 -05:00
Joseph Sutton
079088e543 kdc: Fix incorrect log message
‘list.len’ can be equal to zero.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:37:56 -05:00
Joseph Sutton
e8b42d9d42 hx509: Fix incorrect documentation comment
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:37:56 -05:00
Joseph Sutton
bbe9c83b19 hx509: Remove unused variable
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:37:56 -05:00
Joseph Sutton
59f89e4b15 hx509: Avoid misleading error message
If ‘keyid’ is an empty string, then the numeric error code that gets
appended to this error message may be mistaken for the key ID. Address
this by not mentioning any ID in such cases.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:37:56 -05:00
Joseph Sutton
df6c33ff1e hx509: Use NULL pointer constant
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:37:56 -05:00
Joseph Sutton
e9bc20f5da hcrypto: Fix errors produced by compiling with FORTIFY_SOURCE=2
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:37:56 -05:00
Joseph Sutton
1f88e8c919 wind: Fix code spelling
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:34:35 -05:00
Joseph Sutton
a4b4e982f3 krb5: Fix code spelling
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:34:35 -05:00
Joseph Sutton
7369cbd11c krb5: Fix spelling of error messages
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:34:35 -05:00
Joseph Sutton
91d54fd4c9 kinit: Fix code spelling
This flag has no apparent relation to the process of converting
waterways into canals.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:34:35 -05:00
Joseph Sutton
fbe89adf27 kdc: Fix spelling of error and log messages
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:34:35 -05:00
Joseph Sutton
560c9da844 kdc: Fix code spelling
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:34:35 -05:00
Joseph Sutton
05602c2286 hx509: Fix code spelling
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:34:35 -05:00
Joseph Sutton
ef083a0e2c hx509: Fix code spelling
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:34:35 -05:00
Joseph Sutton
61bf5009a0 hx509: Fix spelling of error messages
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:34:35 -05:00
Joseph Sutton
d9d3dd448d hdb: Fix code spelling
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:34:35 -05:00
Joseph Sutton
7cb320b46a hdb: Fix error messages
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:34:35 -05:00
Joseph Sutton
551f0c32fa base: Fix code spelling
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-28 21:34:35 -05:00