Commit Graph

30509 Commits

Author SHA1 Message Date
Nicolas Williams
aa3355e3bf hcrypto: Remove dead MD2 code 2022-11-17 19:20:08 -06:00
Stefan Metzmacher
8f9c2d115e lib/krb5: remove dead code from pk_verify_host()
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
4baf76220c lib/krb5: remove unused krb5_krbhst_info argument of pk_verify_host()
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
7b3b67be37 lib/krb5: remove unused krb5_krbhst_info argument of pk_rd_pa_reply_enckey()
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
94443d4768 lib/krb5: remove unused krb5_krbhst_info argument of pk_rd_pa_reply_dh()
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
600e126135 lib/krb5: remove unused krb5_krbhst_info argument from _krb5_pk_rd_pa_reply()
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
c5feb63c55 lib/krb5: remove unused krb5_krbhst_info argument of pa_step_f
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
893522a79f lib/krb5: remove unused krb5_krbhst_info argument to pa_step()
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
315592f018 lib/krb5: remove unused krb5_krbhst_info argument of process_pa_data_to_key()
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
a4fc4dcb6a lib/krb5: mark in argument of krb5_init_creds_step() as const
This has no real effect, but make things more clear
and matches the pattern for krb5_sendto_context().

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
fd75c3e23c lib/krb5: let krb5_init_creds_step() return an out_realm
This matches krb5_init_creds_step() from MIT. The only
difference is the type 'krb5_realm' (Heimdal) vs. 'krb5_data' (MIT).

    krb5_error_code KRB5_CALLCONV
    krb5_init_creds_step(krb5_context context,
                         krb5_init_creds_context ctx,
                         krb5_data *in,
                         krb5_data *out,
                         krb5_data *realm,
                         unsigned int *flags);

NOTE: commit 1cdc9d5f3c
"krb5: export krb5_init_creds_step()" exported
krb5_init_creds_step() the first time, but that's
not in any released version, so it should be fine
to fix up the prototype in order to make the
function actually useful for external callers.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
b0bc54c921 lib/krb5: let krb5_init_creds_step() return an allocated out buffer
It should not return pointers to the internal state,
this matches the way the krb5_init_creds_step() works in MIT.

NOTE: commit 1cdc9d5f3c
"krb5: export krb5_init_creds_step()" exported
krb5_init_creds_step() the first time, but that's
not in any released version, so it should be fine
to change the behavior as there can't be any
external users of the function.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
30c978f013 lib/krb5: fix krb5_init_creds_step() interaction with krb5_fast_anon_pkinit_step()
_krb5_fast_anon_pkinit_step() should not set
KRB5_INIT_CREDS_STEP_FLAG_CONTINUE if it doesn't generate any output.

And krb5_init_creds_step() needs to return if
_krb5_fast_anon_pkinit_step() returned with
KRB5_INIT_CREDS_STEP_FLAG_CONTINUE set.
As that means the recursive call to krb5_init_creds_step()
generated output that should be send to a KDC and the
KDC response if needed as input for the next step.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
acaa62636f lib/krb5: krb5_init_creds_get() passes hostinfo=NULL to krb5_init_creds_step()
The current prototype of krb5_init_creds_step() is completely
useless as the caller has no way to know the destination
realm for the out blob.

The only internal caller of krb5_init_creds_step()
passes hostinfo=NULL and this commit makes it more obvious that hostinfo
is always NULL.

NOTE: commit 1cdc9d5f3c
"krb5: export krb5_init_creds_step()" exported
krb5_init_creds_step() the first time, but that's
not in any released version, so it should be fine
to fix up the prototype.

The aim is to remove hostinfo from the krb5_init_creds_step() internals
completely and move krb5_init_creds_step() to a useful prototype
where it returns the destination realm for the out packet.

Which means the prototype will mostly match the one MIT is using:

   krb5_error_code KRB5_CALLCONV
   krb5_init_creds_step(krb5_context context,
                        krb5_init_creds_context ctx,
                        krb5_data *in,
                        krb5_data *out,
                        krb5_data *realm,
                        unsigned int *flags);

Follow up patches demonstrate that the hostinfo related code
in pk_verify_host() is actually dead code as all layers
just passed down the NULL value from krb5_init_creds_get().

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Joseph Sutton
cfb32a638e Introduce macro for common plugin structure elements
Heimdal's HDB plugin interface, and hence Samba's KDC that depends upon
it, doesn't work on 32-bit builds due to structure fields being arranged
in the wrong order. This problem presents itself in the form of
segmentation faults on 32-bit systems, but goes unnoticed on 64-bit
builds thanks to extra structure padding absorbing the errant fields.

This commit reorders the HDB plugin structure fields to prevent crashes
and introduces a common macro to ensure every plugin presents a
consistent interface.

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-11-17 17:15:21 -06:00
Luke Howard
16179383fb asn1: note IMPLICIT CHOICE promoted to EXPLICIT
Record when a CHOICE field is promoted from IMPLICIT to EXPLICIT and convey
this in the ASN.1 compiler's JSON output, so that other tools (e.g. which have
a representation isomorphic to the original ASN.1) may use it.
2022-11-17 17:03:19 -06:00
Luke Howard
5398425cd2 asn1: propagate default values to JSON
Propagate ASN.1 DEFAULT values to ASN.1 compiler JSON output, with the defval
key.
2022-11-17 17:03:19 -06:00
Luke Howard
bc3d9c0115 asn1: JSON output open type IDs
Include open type IDs in JSON output of ASN.1 compiler.
2022-11-17 17:03:19 -06:00
Luke Howard
6a3604caf1 asn1: fix incorrect tag value for UT_UniversalString 2022-11-17 17:03:19 -06:00
Andrew Bartlett
c132e6ff49 lib/base: Avoid compiler warning about use-after-free on Fedora 36
While the local stack pointers could be thought of as "only"
numbers that are not invalidated by the memory they point at
being freed, any use of the pointer after the free is undefined
and so warned about (at best).

gcc version 12.2.1 20220819 (Red Hat 12.2.1-1) (GCC)

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2022-11-17 09:42:48 -05:00
Andrew Bartlett
2c8be80a25 lib/base: Correct realloc() paramters, to allocate one more byte, not 1 byte
The entry condition here is p == pend so this is really just 1 + p - p, eg just 1.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2022-11-17 09:42:48 -05:00
Stefan Metzmacher
7b75136113 lib/krb5: add TGS-REQ PA-DATA e.g. FOR_USER also to the outer req
We can't rely on having every KDC support FAST and should still
support S4U2Self against such a KDC.

We also have the order of the PA-DATA elements "corrected",
KRB5_PADATA_TGS_REQ followed by KRB5_PADATA_FX_FAST and
finally KRB5_PADATA_FOR_USER. While the inner PA-DATA
only contains KRB5_PADATA_FOR_USER.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 09:41:58 -05:00
Stefan Metzmacher
422419ddde kdc: add missing enctype = p[i] assignments to _kdc_find_etype()
This is needed when a service provides support for newer entry.etypes
without having a key for that encryption type yet.

It is triggered with svc_use_strongest_session_key=TRUE.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 08:50:28 -05:00
Joseph Sutton
05e589d247 kdc: Check generate_pac() return code
If the function fails, we should not issue a ticket missing the PAC.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-11-17 07:52:06 -05:00
Volker Lendecke
f4faaeaba3 heimdal: Fix the 32-bit build on FreeBSD
Format string fixes that fail in the Samba build on a 32-bit machine

Signed-off-by: Volker Lendecke <vl@samba.org>
2022-11-16 23:46:46 -05:00
Jeffrey Altman
603e673130 Windows: link against LIBHEIMBASE for json functionality
Change-Id: Ib5ab20ec08b54fd00a6392f7de97a35591a3053b
2022-11-16 22:19:16 -05:00
Joseph Sutton
5e48ec6c88 lib/krb5: Remove __func__ compatibility workaround
As described by the C standard, __func__ is a variable, not a macro.
Hence this #ifndef check does not work as intended, and only serves to
unconditionally disable __func__. A nonoperating __func__ prevents
cmocka operating correctly, so remove this definition.

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>

Change-Id: Ieac3937b9e86f39e84c0c056ffd649e44b292099
2022-11-16 21:40:02 -05:00
Jeffrey Altman
36cf07bc44 Windows: define __func__ in terms of __FUNCTION__
_MSC_VER < 1900 does not provide __func__.   Where it is not
available use __FUNCTION__ instead.

Change-Id: I6624d2d429e90c993ad103cb83e6f61a58a5f800
2022-11-16 21:40:02 -05:00
Jeffrey Altman
a9fca332da lib/asn1: free_type fix HEIM_FALLTHROUGH usage
To function HEIM_FALLTHROUGH should not be embedded in a comment.
2022-11-16 12:23:40 -05:00
Stefan Metzmacher
9d1bfab988 lib/krb5: fix _krb5_get_int64 on 32-bit systems
On systems where 'unsigned long' is 32-bits and the 'size'
parameter is set to 8 and the bytes are:

  0x78 0x00 0x00 0x00 0x00 0x00 0x00 0x00

When 'i' becomes 4 'v' will be 0 again. As 'unsigned long' is only
able to hold 4 bytes.

Change the type of 'v' from 'unsigned long' to 'uint64_t' which
matches the type of the output parameter 'value'.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
CVE: CVE-2022-42898
Samba-BUG: https://bugzilla.samba.org/show_bug.cgi?id=15203
2022-11-16 12:23:40 -05:00
Nicolas Williams
efeab17c03 Update NEWS 2022-11-15 17:53:54 -06:00
Nicolas Williams
9c9dac2b16 asn1: CVE-2022-44640 invalid free in ASN.1 codec
Heimdal's ASN.1 compiler generates code that allows specially
crafted DER encodings of CHOICEs to invoke the wrong free function
on the decoded structure upon decode error.  This is known to impact
the Heimdal KDC, leading to an invalid free() of an address partly
or wholly under the control of the attacker, in turn leading to a
potential remote code execution (RCE) vulnerability.

This error affects the DER codec for all CHOICE types used in
Heimdal, though not all cases will be exploitable.  We have not
completed a thorough analysis of all the Heimdal components
affected, thus the Kerberos client, the X.509 library, and other
parts, may be affected as well.

This bug has been in Heimdal since 2005.  It was first reported by
Douglas Bagnall, though it had been found independently by the
Heimdal maintainers via fuzzing a few weeks earlier.
2022-11-15 17:51:45 -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
Joseph Sutton
b90b219ab8 krb5: CVE-2022-42898 PAC parse integer overflows
Catch overflows that result from adding PAC_INFO_BUFFER_SIZE.

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

Heavily edited by committer Nico Williams <nico@twosigma.com>, original by
Joseph Sutton <josephsutton@catalyst.net.nz>.

Signed-off-by: Nico Williams <nico@twosigma.com>
2022-11-15 17:51:45 -06:00
Nicolas Williams
f727a4bdfd bx509: Fix test moar 2022-11-02 10:57:55 -05:00
Nicolas Williams
e50abd5aa0 cf: Disable broken-getaddrinfo test (fixes check-iprop on OS X) 2022-11-01 16:10:58 -05:00
Nicolas Williams
944c71020e cf: Disable BROKEN_REALLOC workaround 2022-11-01 16:10:57 -05:00
Nicolas Williams
00b065bc80 cf: Do not redefine realloc() when ASAN is used 2022-11-01 16:10:57 -05:00
Nicolas Williams
0f919e89ca base: -Wno-string-concatenation for test_base 2022-11-01 16:10:57 -05:00
Nicolas Williams
3a5e91eca2 hcrypto: Remove MD2 with prejudice
We don't use it anywhere for anything.
2022-11-01 16:10:57 -05:00
Nicolas Williams
bad07f7738 gss: Fix UB 2022-11-01 16:10:57 -05:00
Nicolas Williams
8e9ad6eda2 krb5: Fix UB 2022-11-01 16:10:57 -05:00
Nicolas Williams
5b1c69b424 hcrypto: Fix UB 2022-11-01 16:10:57 -05:00