Commit Graph

5836 Commits

Author SHA1 Message Date
Taylor R Campbell
e0aeef2bd3 krb5_sock_to_principal: Respect option [libdefaults] block_dns.
This fixes the one leaky part of:
https://github.com/heimdal/heimdal/issues/1214
2024-01-09 21:19:30 -06:00
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
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
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
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
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
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
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
30e3921ad1 krb5: Fix error condition
‘ret’ can only ever be equal to zero.

Found by Coverity (Samba CID 1518754).

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-02 20:19:54 -05:00
Joseph Sutton
b1f7a63e41 krb5: Fix error code mapping
Found by Coverity (Samba CID 1518726).

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-02 20:19:54 -05:00
Joseph Sutton
b0f196880c krb5: Check result of calling decode_Ticket()
Found by Coverity (Samba CID 241005).

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-02 20:19:54 -05:00
Joseph Sutton
0334d9e55a krb5: Check function return values
Found by Coverity (Samba CID 240644).

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-02 20:19:54 -05:00
Joseph Sutton
e53d594d05 krb5: Check return value of RAND_bytes()
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-02 20:19:54 -05:00
Joseph Sutton
62e63b2da6 krb5: Fix unused variable
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-11-02 20:19:54 -05:00
Nicolas Williams
2a38fa17b5 kdc: Add global disable_pac config param 2023-06-23 13:44:13 -05:00
Joseph Sutton
8640c7c168 krb5: Return appropriate error code 2023-06-20 18:02:15 -05:00
Joseph Sutton
c1bd7772ed third_party/heimdal: Fix deprecation messages
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-06-20 18:02:15 -05:00
Taylor R Campbell
997916e3f6 krb5: Make heimdal_version and heimdal_long_version const.
Pretty sure it is not useful for applications to be able to write to
this.

However, caveat: this could break programs that expect to pass around
&heimdal_version or &heimdal_long_version to functions that expect
pointers to non-const objects even if they don't modify them.
2023-06-20 12:19:48 -05:00
Taylor R Campbell
c69ce29a31 krb5/constants.c: Make some constants constant.
This changes the public header file but I doubt it was ever intended
that applications could change these by writing to them.  (Not sure
why they're not declared as const arrays in any case.)
2023-06-20 12:19:48 -05:00
Taylor R Campbell
29b1faaef6 krb5/send_to_kdc.c: Constify plugin stuff. 2023-06-20 12:19:48 -05:00
Taylor R Campbell
c644d051d8 krb5/pcache.c: Constify plugin stuff. 2023-06-20 12:19:48 -05:00
Taylor R Campbell
1f870603a4 krb5/kuserok.c: Constify plugin stuff. 2023-06-20 12:19:48 -05:00
Taylor R Campbell
2e3dada6fd krb5/krbhst.c: Constify plugin stuff. 2023-06-20 12:19:48 -05:00
Taylor R Campbell
084d638906 krb5/db_plugin.c: Constify plugin stuff. 2023-06-20 12:19:48 -05:00
Taylor R Campbell
da5730a4b0 krb5/aname_to_localname.c: Constify plugin stuff. 2023-06-20 12:19:48 -05:00
Taylor R Campbell
6630cf5889 krb5/plugin.c: Constify. 2023-06-20 12:19:48 -05:00
Taylor R Campbell
b67a083a3c krb5/send_to_kdc.c: Sprinkle const on global data never changed. 2023-06-20 12:19:48 -05:00
Taylor R Campbell
796e420c11 libkrb5, libkdc: Constify salted s2k default iterator counts.
These externs should really be in a .h file shared by definition and
usage sites so the C compiler can verify that they match.
2023-06-20 12:19:48 -05:00
Taylor R Campbell
8f2f159f7f krb/pac.c: Sprinkle const on global data never changed. 2023-06-20 12:19:48 -05:00
Taylor R Campbell
c2c47aec6c krb5/init_creds_pw.c: Sprinkle const on global data not changed. 2023-06-20 12:19:48 -05:00
Taylor R Campbell
35688d030f krb5/get_in_tkt.c: Sprinkle const on global data never changed. 2023-06-20 12:19:48 -05:00
Taylor R Campbell
cf0418d6fc krb5/get_host_realm.c: Sprinkle const on global data never changed. 2023-06-20 12:19:48 -05:00
Taylor R Campbell
5d9723d52d krb5/context.c: Sprinkle const for global data never changed. 2023-06-20 12:19:48 -05:00
Taylor R Campbell
9b61e64c3d krb5/changepw.c: Sprinkle const for global data never changed. 2023-06-20 12:19:48 -05:00
Taylor R Campbell
043bb8f27d krb5/addr_families.c: Sprinkle const for global data never changed. 2023-06-20 12:19:48 -05:00
Taylor R Campbell
2db6c29a3e krb5/mk_error.c: Constify and rk_UNCONST a static buffer.
This is almost certainly intended never to be written to, so let's
let the operating system detect that mistake for us by mapping it in
a .rodata segment mapped read-only that will cause SIGSEGV on write.

fix https://github.com/heimdal/heimdal/issues/1136
2023-06-20 12:19:48 -05:00
Taylor R Campbell
ca1200df03 krb5_decrypt_iov_ivec: Make sure const zero IV is actually const.
This way if anything _does_ write to it, it has the opportunity to be
caught by SIGSEGV, by having zero_ivec in a .rodata segment mapped
read-only.

fix https://github.com/heimdal/heimdal/issues/1135
2023-06-20 12:19:48 -05:00
Jeffrey Altman
c64d4ce968 krb5: krb5_enctype_to_keytype cast krb5_enctype to krb5_keytype
The struct _krb5_key_type.type is krb5_enctype.   Cast it to
krb5_keytype before assigning to the 'krb5_keytype *keytype'
output variable to avoid a warning from Clang 1500 on Darwin.
2023-06-06 09:11:29 -04:00
Taylor R Campbell
a142767598 Fix ctype.h misuse.
Excluded: libtomath and libedit files, most of which appear to be
testing or example code not involved in production, and which are
derived from an upstream that should perhaps have patches submitted
upstream instead.

fix https://github.com/heimdal/heimdal/issues/1111
2023-05-26 14:10:11 -05:00
Nicolas Williams
39f24c4cd4 krb5: Fix crash in resolving "DIR" as a ccache name (Fix #1108) 2023-05-26 13:47:26 -05:00
Jeffrey Altman
61dc4ff8df krb5: fixup crypto.c avoid realloc to trim memory allocation
1b1ff8fdd5 ("krb5: crypto.c avoid realloc
to trim memory allocation") removed the realloc() but failed to assign
'p' to 'result->data'.
2023-05-03 17:18:01 -04:00
Jeffrey Altman
1b1ff8fdd5 krb5: crypto.c avoid realloc to trim memory allocation
decrypt_internal_derived(), decrypt_internal_enc_then_cksum(),
decrypt_internal(), and decrypt_internal_special() execute the
following pattern where 'p' is an allocation of size 'len'

  l = len - n
  memmove(p, p + n, l);
  result->data = realloc(p, l);
  if (result->data == NULL && l != 0) {
      free(p);
      return krb5_enomem(context);
  }
  result->length = l;

which when compiled by gcc 13.0.1-0.12.fc38 or gcc-13.0.1-0.13.fc39
generates the following warning

  warning: pointer 'p' may be used after 'realloc' [-Wuse-after-free]

The C language specification indicates that it is only safe to free()
the pointer passed to realloc() if errno is set to ENOMEM.  Yet the
warning is generated by the following pattern

  l = len - n
  memmove(p, p + n, l);
  errno = 0;
  result->data = realloc(p, l);
  if (result->data == NULL && l != 0) {
      if (errno == ENOMEM)
          free(p);
      return krb5_enomem(context);
  }
  result->length = l;

The value of performing the realloc() is questionable.  realloc()
in many cases will need to perform a second allocation of the
smaller size and then perform a memcpy() which will slow down
the operation without saving much memory.  The allocation is already
very small.

This change avoids the warning by removing the realloc() entirely.
2023-05-03 17:02:34 -04:00
Nicolas Williams
33f90a6604 krb5: Document pkinit_revoke (fix #991) 2023-01-09 23:00:08 -06:00
Nicolas Williams
829f07eed3 krb5: Always fseek before fwrite in storage_stdio 2023-01-09 13:22:13 -06:00