Commit Graph

5779 Commits

Author SHA1 Message Date
Nicolas Williams
1a75e174ac krb5: Always try mkdir in DIR: ccache (quiet [harmless] TOCTOU warning) 2023-01-04 00:43:36 -06:00
Nicolas Williams
b0b4510f9f krb5: Fix return of pointer to local in krb5_sendauth() (never exercised)
We don't have a caller in-tree that exercises this path.
2023-01-04 00:43:36 -06:00
Nicolas Williams
46df04dafb krb5: Fix leaks 2023-01-04 00:43:36 -06:00
Nicolas Williams
21ada15e08 krb5: Expand breadcrumb commentary in _krb5_get_host_realm_int() 2023-01-04 00:43:36 -06:00
Nicolas Williams
2e7d996ea9 krb5: Fix string read overrun (fix #1057) 2023-01-04 00:43:36 -06:00
Nicolas Williams
cc641edf6b krb5: Fix moduli open file leak 2023-01-04 00:43:36 -06:00
Nicolas Williams
7705ff6588 krb5: Fix FAST anon PKINIT leak 2023-01-04 00:43:36 -06:00
Nicolas Williams
59e13ad299 krb5: Quiet static analyzer warning in store.c 2023-01-04 00:43:36 -06:00
Nicolas Williams
5535ace6ea krb5: Fix ignored error in SCC: ccache 2023-01-04 00:43:36 -06:00
Nicolas Williams
0fba239baa krb5: Quiet static analyzer warning in name canon rules 2023-01-04 00:43:36 -06:00
Nicolas Williams
e5a8a6f972 krb5: Quiet static analyzer warning in krbhst 2023-01-04 00:43:36 -06:00
Nicolas Williams
a1c0639ddd krb5: Fix NULL deref in KCM: ccache 2023-01-04 00:43:36 -06:00
Nicolas Williams
2e11ecefba krb5: Fix krb5_copy_context() use-after-free copy-pasto 2023-01-04 00:43:35 -06:00
Nicolas Williams
58e07f8882 krb5: Fix(?) st_nlink check in fcache.c
We have a check for symlinks and hardlinks so that we refuse to open
ccaches through symlinks or which have hardlinks.  This check is too
strict, checking for `st_nlink != 1`, which runs into trouble when a
ccache is mounted as a file into a container, in which case `stat(2)`
reports it as having zero links.

The fix is to check for `st_nlink > 1`:

    -    if (sb2.st_nlink != 1) {
    +    if (sb2.st_nlink > 1) {
            krb5_set_error_message(context, EPERM, N_("Refuses to open hardlinks for caches FILE:%s", ""), filename);

Though I question the utility of the hardlink check.  MIT Kerberos
doesn't have it.
2022-12-29 22:27:42 -06:00
Nicolas Williams
42b0702601 krb5: Better checking for storage EOF 2022-12-22 17:55:13 -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
6336cf69d4 krb5: OpenSSL 3.0 support 2022-11-22 11:34:54 -05: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
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
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
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
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
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
8e9ad6eda2 krb5: Fix UB 2022-11-01 16:10:57 -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
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
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
Jeffrey Altman
97eaa6cd01 krb5: pkinit select_dh_group clarify 'bits' param is the minimum
The 'bits' parameter to select_dh_group() is the minimum acceptable
bit size.   Rename 'bits' to 'min_bits' and fix the comparision
with krb5_dh_moduli.bits to ensure that DH groups whose bit size
is the minimum acceptable are not excluded.

Fixes #1002

Reported-By: Julien Rische (GitHub: jrisc)
2022-09-16 17:00:20 -04:00
Jeffrey Altman
1e67fd6c01 krb5: rfc3526-MODP-group14 incorrect bit size
Heimdal supports the 2 mandatory MODP groups (group 2 and group 14)
according to RFC4556, however group 14 is defined with a size of
1760 bits instead of 2048.

Fixes #1001

Reported-by: Julien Rische (GitHub: jrisc)
2022-09-16 16:36:42 -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
f165d1e942 lib/krb5: Avoid undefined pointer arithmetic
If the AP len is large enough, we might end up computing an address
beyond the end of the 'reply' array, which is undefined behaviour.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-09-16 15:43:44 -04:00
Nicolas Williams
d1e7650988 krb5: Fix skew bug, or krb5_copy_context() moar
Now that we use krb5_copy_context() via kadm5_c_dup_context(), we see
occasional skew errors in the tests because context->max_skew was not
being initialized, so it was set to 0s of skew, and krb5_rd_priv() or
others could fail.
2022-03-24 16:41:22 -05:00
Nicolas Williams
4b9faa02b0 krb5: Fix KCM for root user 2022-03-22 23:36:18 -05:00
Nicolas Williams
5a0aaf9e19 krb5: Fix leak in default an2ln DB plugin 2022-03-18 18:33:53 -05:00
Nicolas Williams
a26c30b230 krb5: Initialize krb5_ret_string() output param 2022-03-18 18:33:53 -05:00
Stefan Metzmacher
0861754a84 lib/krb5: before we create a new FAST armor we should clear the old strengthen_key
In a cross-realm situation the client KDC exchange may use on orphaned
strengthen_key (from the previous exchange) if the current KDC
doesn't not support FAST and the previous KDC supported it.

Otherwise init_creds_step() or fast_tgs_strengthen_key()
generate the reply key.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-03-12 12:51:03 +11:00