Commit Graph

2392 Commits

Author SHA1 Message Date
Minsoo Choo
aff90c322e Fix spelling 2024-06-16 23:30:48 -04:00
Michael Tokarev
c80c04b235 spelling fixes (underun prefered relase encyption confunder)
[abartlet@samba.org: From Samba debian package at
 https://salsa.debian.org/samba-team/samba/-/blob/master/debian/patches/heimdal-spelling.patch?ref_type=heads]

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2024-06-16 23:28:43 -04:00
Jeffrey Altman
5ba8b7f177 gssapi/mech: -Wcalloc-transposed args
warning: 'calloc' sizes specified with 'sizeof' in the earlier argument
and not in the later argument [-Wcalloc-transposed-args].

Swap the args.
2024-06-04 06:22:37 -04:00
Jeffrey Altman
17f31adbff gssapi/krb5: _gsskrb5_display_name return GSS_C_NT_ANONYMOUS
If the Kerberos v5 principal name is

  WELLKNOWN/ANONYMOUS@WELLKNOWN:ANONYMOUS

and the principal type is KRB5_NT_WELLKNOWN, then gss_display_name()
is expected to return GSS_C_NT_ANONYMOUS instead of
GSS_KRB5_NT_PRINCIPAL_NAME.  This change matches the behavior of
MIT Kerberos.
2024-06-04 06:22:37 -04: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
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
Robert Manner
bcbe816962 spnego/context_storage: undef sc_flags (for hpux)
On hpux this is seems to be a define from sys/signal.h:

which renders the variable name invalid.
2023-02-06 18:17:48 -06:00
Luke Howard
dffa545f81 gss: colaesce DCE_STYLE padding/trailer buffer check 2023-01-17 17:57:30 +11:00
Luke Howard
dc682769c4 gss: use mechglue instead of gssntlm encoders
Replace calls to {en,de}code...() with mechglue equivalents.
2023-01-16 19:11:03 +11:00
Luke Howard
363e7d1e0f gss: don't truncate authtime in gsskrb5_extract_authtime_from_sec_context()
The interface between the krb5 mechanism and the mechglue API
gsskrb5_extract_authtime_from_sec_context() assumed the authtime would fit into
an uint32_t, which is not the case on platforms where time_t is 64-bit.

Fixes: #1073
2023-01-16 09:16:39 +11:00
Luke Howard
98858aa215 gss: add 64-bit int {en,de}coders to mechglue 2023-01-16 09:16:39 +11:00
Luke Howard
fbd091d65e gss: use mechglue instead of gsskrb5 encoders
Replace calls to _gsskrb5_{en,de}code...() with mechglue equivalents.
2023-01-16 09:16:39 +11:00
Nicolas Williams
b87b813fee sanon: Fix export/import_cred mismatch
SANON cred export/import never worked correctly as the export function was
producing the wrong form of token, which was leading gss_import_cred() to
allocate more than 64MB of memory to parse the SANON exported credential.  The
recent change to reduce the default `max_alloc` of krb5_storage exposed this.
2023-01-05 16:58:57 -06:00
Nicolas Williams
5725353a36 negoex: Fix incorrect ENOMEM check in storage_from_memory() 2023-01-04 16:21:34 -06:00
Nicolas Williams
3bdb1167c2 gsskrb5: Explicitly ignore return from _gsskrb5_lifetime_left() 2023-01-04 16:21:11 -06:00
Nicolas Williams
f99145ad78 gsskrb5: Add missing unlock in _gsskrb5_duplicate_cred() failure case 2023-01-04 16:20:32 -06:00
Nicolas Williams
16c9813140 negoex: Quiet a static analyzer false positive 2023-01-04 00:43:43 -06:00
Nicolas Williams
7c519d9c34 negoex: Fix use-after-free 2023-01-04 00:43:43 -06:00
Nicolas Williams
df81ad1c93 spnego: Quiet warning in ret_spnego_context() 2023-01-04 00:43:43 -06:00
Nicolas Williams
78c261f689 gsskrb5: Add missing error check in cred import 2023-01-04 00:43:43 -06:00
Nicolas Williams
882f9fddaa gsskrb5: Fix uninit var in acceptor 2023-01-04 00:43:43 -06:00
Nicolas Williams
67c35bc1ca gsskrb5: Fix NULL deref in init_sec_context 2023-01-04 00:43:43 -06:00
Nicolas Williams
27e5c40a79 gss: Fix leaks 2023-01-04 00:43:43 -06:00
Nicolas Williams
aaff3aa5c5 Do not include config.h in heimbase.h (fix #447)
We can't include config.h in public headers, as config.h is not public.

This reverts part of commit a8f0905b71.
2022-12-08 14:06:03 -06:00
Nicolas Williams
674696151a gss-token: Fix acceptor context leak 2022-12-05 23:01:52 -06:00
Joseph Sutton
2a4210b7e9 gsskrb5: CVE-2022-3437 Pass correct length to _gssapi_verify_pad()
We later subtract 8 when calculating the length of the output message
buffer. If padlength is excessively high, this calculation can underflow
and result in a very large positive value.

Now we properly constrain the value of padlength so underflow shouldn't
be possible.

Samba BUG: https://bugzilla.samba.org/show_bug.cgi?id=15134

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-11-15 17:51:45 -06:00
Joseph Sutton
22749e918f gsskrb5: CVE-2022-3437 Check for overflow in _gsskrb5_get_mech()
If len_len is equal to total_len - 1 (i.e. the input consists only of a
0x60 byte and a length), the expression 'total_len - 1 - len_len - 1',
used as the 'len' parameter to der_get_length(), will overflow to
SIZE_MAX. Then der_get_length() will proceed to read, unconstrained,
whatever data follows in memory. Add a check to ensure that doesn't
happen.

Samba BUG: https://bugzilla.samba.org/show_bug.cgi?id=15134

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-11-15 17:51:45 -06:00
Joseph Sutton
6a48779651 gsskrb5: CVE-2022-3437 Check buffer length against overflow for DES{,3} unwrap
Samba BUG: https://bugzilla.samba.org/show_bug.cgi?id=15134

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-11-15 17:51:45 -06:00
Joseph Sutton
4aca82c7d0 gsskrb5: CVE-2022-3437 Check the result of _gsskrb5_get_mech()
We should make sure that the result of 'total_len - mech_len' won't
overflow, and that we don't memcmp() past the end of the buffer.

Samba BUG: https://bugzilla.samba.org/show_bug.cgi?id=15134

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-11-15 17:51:45 -06:00
Joseph Sutton
ce6d8bbdbb gsskrb5: CVE-2022-3437 Avoid undefined behaviour in _gssapi_verify_pad()
By decrementing 'pad' only when we know it's safe, we ensure we can't
stray backwards past the start of a buffer, which would be undefined
behaviour.

In the previous version of the loop, 'i' is the number of bytes left to
check, and 'pad' is the current byte we're checking. 'pad' was
decremented at the end of each loop iteration. If 'i' was 1 (so we
checked the final byte), 'pad' could potentially be pointing to the
first byte of the input buffer, and the decrement would put it one
byte behind the buffer.

That would be undefined behaviour.

The patch changes it so that 'pad' is the byte we previously checked,
which allows us to ensure that we only decrement it when we know we
have a byte to check.

Samba BUG: https://bugzilla.samba.org/show_bug.cgi?id=15134

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-11-15 17:51:45 -06:00
Joseph Sutton
cc9af5194a gsskrb5: CVE-2022-3437 Don't pass NULL pointers to memcpy() in DES unwrap
Samba BUG: https://bugzilla.samba.org/show_bug.cgi?id=15134

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-11-15 17:51:45 -06:00
Joseph Sutton
e407e0ead6 gsskrb5: CVE-2022-3437 Use constant-time memcmp() in unwrap_des3()
The surrounding checks all use ct_memcmp(), so this one was presumably
meant to as well.

Samba BUG: https://bugzilla.samba.org/show_bug.cgi?id=15134

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-11-15 17:51:45 -06:00
Joseph Sutton
e18b8f111f gsskrb5: CVE-2022-3437 Use constant-time memcmp() for arcfour unwrap
Samba BUG: https://bugzilla.samba.org/show_bug.cgi?id=15134

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-11-15 17:51:45 -06:00
Nicolas Williams
bad07f7738 gss: Fix UB 2022-11-01 16:10:57 -05:00
Nicolas Williams
ea4b822af7 gss: Fix gss-token success exit code 2022-10-06 16:42:33 -05:00
Sergei Trofimovich
e7efa7783a gssapi: add dependency on gkrb5_err.h
Noticed missing target directory dependency as a build failure in
`make --shuffle` mode (added in https://savannah.gnu.org/bugs/index.php?62100):

      CC       test_common.o
    In file included from test_common.c:34:
    krb5/gsskrb5_locl.h:42:10: fatal error: gkrb5_err.h: No such file or directory
       42 | #include <gkrb5_err.h>
          |          ^~~~~~~~~~~~~
    compilation terminated.
    make[3]: *** [Makefile:2347: test_common.o] Error 1 shuffle=1656680590

The change moves gkrb5_err.h and friends to BUILT_SOURCES
to guarantee their presence when main build starts.
2022-09-16 16:13:50 -04:00
Daria Phoebe Brashear
133f517482 rewrite fallthrough to HEIM_FALLTHROUGH to deal with new Apple SDKs
Apple clang version 14.0.0 (clang-1400.0.17.3.1) fails the build
because stds.h defines `fallthrough` as a macro which is then
expanded when base.h evaluates

  # if __has_attribute(fallthrough) && __clang_major__ >= 5

The macOS SDK defines `DISPATCH_FALLTHROUGH` as the macro instead
of `fallthrough`.

This change replaces the use of `fallthrough` in the tree with
`HEIM_FALLTHROUGH` and updates the declaration in configure logic
to define `HEIM_FALLTHROUGH` based upon existing definitions
(if any) of `fallthrough` or `DISPATCH_FALLTHROUGH`.
2022-09-16 15:58:45 -04:00
Joseph Sutton
b19633f9b9 Use constant-time memcmp when comparing sensitive buffers
This helps to avoid timing attacks.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-04-30 13:35:52 -04:00
Luke Howard
69973757ce gss: remove gss_get_instance() 2022-01-30 14:20:05 -05:00
Jeffrey Altman
190263bb7a assert non-NULL ptrs before calling mem funcs
The definitions of memcpy(), memmove(), and memset() state that
the behaviour is undefined if any of the pointer arguments are
NULL, and some compilers are known to make use of this to
optimise away existing NULL checks in the source.

Change-Id: I489bc256e3eac7ff41d91becb0b43aba73dbb3f9
Link: https://www.imperialviolet.org/2016/06/26/nonnull.html
2022-01-24 00:07:51 -05:00
Jeffrey Altman
d35c9b2d67 lib/gssapi/ntlm: _gss_ntlm_inquire_cred dead code removal
do not check 'cred_handle' for GSS-C_NO_CREDENTIAL twice.

Change-Id: I3629aa49b2d20d3444c6ede46715d65b6072484f
2022-01-23 23:11:46 -05:00
Jeffrey Altman
ca4ff365f8 lib/gssapi/mech: gss_mech_switch do not leak 'm'
If there is a memory allocation failure after 'm'
is allocated, 'm' will be leaked; free it.

Change-Id: I625273634af207fac7c489df166cebde4d467cbc
2022-01-23 23:07:36 -05:00
Roland C. Dowdeswell
8dcd05ed4d _gss_ntlm_init_sec_context() mem leaks 2022-01-22 21:54:20 -05:00
Roland C. Dowdeswell
e87fca8091 _gss_ntlm_delete_sec_context() mem leaks 2022-01-22 21:54:20 -05:00
Roland C. Dowdeswell
8526b4c627 fix memory leak near NTLM type2 response 2022-01-22 21:54:20 -05:00
Jeffrey Altman
04527412e3 Follow the Linux kernel's lead on "fallthrough"
The pseudo keyword 'fallthrough' is defined such that case statement
blocks must end with any of these keywords:
 * break;
 * fallthrough;
 * continue;
 * goto <label>;
 * return [expression];
 *
 *  gcc: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#Statement-Attributes

The macro is defined either as

  __attribute__((__fallthrough__))

or as

  do {} while (0)  /* fallthrough */

not including the semicolon.

This change implements the Linux kernel style and updates several locations
where "/*fallthrough*/ and /* FALLTHROUGH */ were not previously replaced.

Externally imported code such as libedit, libtommath and sqlite are
restored to their unaltered state.

Change-Id: I69db8167b0d5884f55d96d72de3059a0235a1ba3
2022-01-21 10:39:47 -05:00
Nicolas Williams
681708f416 gsskrb5: Fix coverity issue 2022-01-20 13:28:57 -06:00
Nicolas Williams
8c5030bcf7 gss: test_context: Fix leak 2022-01-19 12:35:08 -06:00
Nicolas Williams
26054d835c gss: Fix leak in gss-token 2022-01-19 12:33:11 -06:00
Nicolas Williams
f26bc69ded gss: Fix name attr leak in test_context 2022-01-18 12:35:26 -06:00