Commit Graph

30482 Commits

Author SHA1 Message Date
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
Nicolas Williams
e4311f3a82 asn1: Fix UB and incorrect codec for unconstrained INTEGER values of -1 2022-11-01 16:10:57 -05:00
Nicolas Williams
476d216f89 base: Fix UB 2022-11-01 16:10:57 -05:00
Nicolas Williams
07abfdb1a9 roken: Fix UB 2022-11-01 16:10:57 -05:00
Nicolas Williams
3e1befe633 bx509: Make test run with UBSAN 2022-11-01 16:10:57 -05:00
Nicolas Williams
c87192e700 GHA: Make UBSAN build run 2022-11-01 10:23:47 -05:00
Nicolas Williams
553abd456f GHA: Add UBSAN build 2022-11-01 10:00:46 -05:00
Nicolas Williams
ed40630174 sl: Fix exit(0) when incorrect usage
Any command that uses lib/sl for sub-commands fails to exit with a
non-zero exit code on usage error.

The fix is a one-character change in lib/sl/slc-gram.y.

Affected are all subcommands of:

 - ktutil
 - kadmin
 - heimtools
 - hxtool
 - gsstool
 - kdigest
 - iprop-log
2022-10-11 21:05:45 -05:00
Nicolas Williams
ea4b822af7 gss: Fix gss-token success exit code 2022-10-06 16:42:33 -05:00
Nicolas Williams
5ce580f5ad roken: Fix typo in lib/roken/Makefile.am 2022-10-06 16:42:33 -05:00
Nicolas Williams
c015db46da windows: Do not make test in kadmin/
Somehow the dreaded C1041 error pops up.
2022-10-03 09:44:22 -05:00
Nicolas Williams
ceec364ed4 ktutil: Add import command and other improvements
- Add an import command that imports JSON as output by
   `ktutil list --json --keys`.

   This is enables one to filter/edit keytabs with jq!

 - Add a `merge` alias for the `copy` command, since that's effectively
   what it does.

 - Add a `--copy-duplicates` option to the `copy`/`merge` command.

 - Add a `--no-create` option to the `get` command.

 - Add a `--no-change-keys` option to the `get` command.

 - Make `add` complain if it can't finish writing to the keytab.
2022-10-03 09:44:22 -05:00
Nicolas Williams
69dc89b39a ktutil: Add list --json option 2022-10-03 09:44:22 -05:00
Nicolas Williams
6297b76362 klist: Real JSON output 2022-10-03 09:44:22 -05:00
Nicolas Williams
f90f055659 iprop: Enable secondary KDC bootstrapping w/ PKINIT
With this change it's possible to bootstrap a KDC using a client
certificate with a PKINIT SAN for iprop/fqdn.  Given such a certificate
one could run ipropd-slave via kinit to pull down the initial copy of
the HDB, then start the KDC services using the HDBGET: keytab.

That should make bootstrapping new secondary KDCs very easy.

One could bootstrap the KDC with such a certificate using, e.g.,
Safeboot (https://github.com/osresearch/safeboot), enrolling the host as
a KDC.
2022-10-02 22:46:37 -05:00
Nicolas Williams
56c6120522 httpkadmind: Make more like bx509d internally
- Correct handling of POST (before POSTs with non-zero-length bodies
   would cause the server to close the connection).

 - Add CSRF features from bx509d.
2022-10-02 22:46:37 -05:00
Nicolas Williams
ae527bf97c bx509d: Add /get-tgts batch end-point
In order to support batch jobs systems that run many users' jobs and
which jobs need credentials, we add a /get-tgts end-point that is a
batched version of the /get-tgt end-point.  This end-point returns JSON.

Also, we make GETs optional, default to not-allowed in preference of
POSTs.

We also correct handling of POST (before POSTs with non-zero-length bodies
would cause the server to close the connection), and add additional CSRF
protection features, including the ability to disable all GET requests
for /get-keys and /get-config.
2022-10-02 22:46:37 -05:00
Nicolas Williams
323f4631a4 krb5: Do not clobber keytab entry timestamps
We set the timestamp field of krb5_keytab_entry in every case in-tree,
so we should not clobber it in krb5_kt_add_entry().  This is very
important in the context of virtual service principals, as the timestamp
of the keys in the keytab is a clue to when they must be refetched!
2022-10-02 22:46:37 -05:00
Nicolas Williams
1429814eda base: HEIM_JSON_F_TRY_DECODE_DATA cannot work
The idea with HEIM_JSON_F_TRY_DECODE_DATA is that on parsing of JSON
texts, if we find a base64-encoded string, decode it.  But a lot of
strings that aren't base64-encoded can be decoded anyways, leaving a
mess.

Insted we should -in a future commit- implement this only for the string
values of "heimdal-type-data-76d7fca2-d0da-4b20-a126-1a10f8a0eae6" names
in singleton objects.
2022-10-02 22:46:37 -05:00
Nicolas Williams
ed4b50720d base: Export type ID enum
Otherwise we really can't use the heimbase CF types outside lib/base!
2022-10-02 22:46:37 -05:00
Nicolas Williams
8364bdd8f3 base: Add JSON string non-ASCII escaping options
- Add HEIM_JSON_F_ESCAPE_NON_ASCII to indicate that non-ASCII must be
   escaped as \uXXXX.

 - Add HEIM_JSON_F_NO_ESCAPE_NON_ASCII to force non-escaping of BMP
   codepoints.

 - If the locale's codeset is not UTF-8 and
   HEIM_JSON_F_NO_ESCAPE_NON_ASCII is not set, then set
   HEIM_JSON_F_ESCAPE_NON_ASCII.
2022-10-02 22:46:37 -05:00
Nicolas Williams
03f06b9472 base: Prettier JSON output / options
- Add flags for indenting with 2, 4, or 8 spaces, still defaulting to
   tabs if none of those are set.

 - Don't emit a newline before emitting scalar values in dicts.
2022-10-01 00:15:37 -05:00
Nicolas Williams
c6a46f0c96 base: Implement JSON string escaping
We encode JSON in the KDC's audit logs, and soon in bx509d's /get-tgts.
Therefore, we should be reasonable in terms of what we encode.
2022-09-29 17:05:24 -05:00
Joseph Sutton
7ae4292986 lib/krb5: Fix leak in error path
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-09-27 17:35:38 +10:00
Stefan Metzmacher
c4216b17a8 kdc: add enable_fast option (enabled by default)
This makes it possible to disable fast if needed,
which is very good for regression tests.
Samba disables this in a few test environments with this
option.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-09-25 21:13:01 +10:00
Rod Widdowson
348a03e48e Documentation changes for the Windows Build
- Fix markup
- Specific quoted command line for Visual Studio
  build
- Caveat about line ending for gawk
- Add comments about python versions
- makeinfo.exe is no longer available from cygwin
- Add some words about APPVER setting
2022-09-24 20:21:09 +10:00
Sergei Trofimovich
cd3b6e5a41 hdb: fix ldap module build (missing 'is_file_based' and 'can_taste' initializers)
Without the change the build fails as:

      CC       hdb-ldap.lo
    hdb-ldap.c:2109:5: warning: initialization of 'unsigned char:1' from 'krb5_error_code (*)(struct krb5_context_data *, void **)' {aka 'int (*)(struct krb5_context_data *, void **)'} makes integer from pointer without a cast [-Wint-conversion]
     2109 |     init,
          |     ^~~~
    hdb-ldap.c:2109:5: note: (near initialization for 'hdb_ldapi_interface.is_file_based')
    hdb-ldap.c:2109:5: error: initializer element is not computable at load time
    hdb-ldap.c:2109:5: note: (near initialization for 'hdb_ldapi_interface.is_file_based')
    hdb-ldap.c:2110:5: warning: initialization of 'unsigned char:1' from 'void (*)(void *)' makes integer from pointer without a cast [-Wint-conversion]
     2110 |     fini,
          |     ^~~~
    hdb-ldap.c:2110:5: note: (near initialization for 'hdb_ldapi_interface.can_taste')
    hdb-ldap.c:2110:5: error: initializer element is not computable at load time
    hdb-ldap.c:2110:5: note: (near initialization for 'hdb_ldapi_interface.can_taste')
    hdb-ldap.c:2111:5: warning: initialization of 'krb5_error_code (*)(struct krb5_context_data *, void **)' {aka 'int (*)(struct krb5_context_data *, void **)'} from incompatible pointer type 'char *' [-Wincompatible-pointer-types]
     2111 |     "ldapi",
          |     ^~~~~~~
    hdb-ldap.c:2111:5: note: (near initialization for 'hdb_ldapi_interface.init')
    hdb-ldap.c:2112:5: warning: initialization of 'void (*)(void *)' from incompatible pointer type 'krb5_error_code (*)(struct krb5_context_data *, HDB **, const char *)' {aka 'int (*)(struct krb5_context_data *, HDB **, const char *)'} [-Wincompatible-pointer-types]
     2112 |     hdb_ldapi_create
          |     ^~~~~~~~~~~~~~~~
    hdb-ldap.c:2112:5: note: (near initialization for 'hdb_ldapi_interface.fini')
    hdb-ldap.c:2113:1: warning: missing initializer for field 'prefix' of 'struct hdb_method' [-Wmissing-field-initializers]
     2113 | };
          | ^
Started failing when commit 93ada1fbf ("hdb: Remove default HDB backend
footgun") added extra fields to 'struct hdb_method'.
2022-09-24 19:38:16 +10:00
Jeffrey Altman
8b0c7ec09a krb5: remove krb5-v4compat.h
Kerberos v4 compatibility definitions are no longer required
in the source tree.
2022-09-22 22:13:05 -04:00