Commit Graph

5791 Commits

Author SHA1 Message Date
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
Robert Manner
914976aca6 krb5/store_stdio.c: workaround for solaris10/hpux/aix fread/fwrite duplication bug 2023-01-09 10:09:26 -06:00
Nicolas Williams
d3b08638f9 krb5: Fix wrong cast in _krb5_store_data_at_offset() 2023-01-07 11:08:00 -06:00
Luke Howard
ed93098365 krb5: include config.h before string.h
Solaris requires __EXTENSIONS__ to be defined before including string.h so that
the strnlen() prototype is visible
2023-01-07 12:08:35 +11:00
Nicolas Williams
ece456b028 krb5: Do not fail to rd_req if no AD-KDC-ISSUED
We reject tickets that have no AD-KDC-ISSUED(!).

This was reported by Samba.  The workaround they found was to set
check_pac = true in krb5.conf, as that clobbers the ret from
krb5_ticket_get_authorization_data_type() not having found an
AD-KDC-ISSUED element.

This was introduced in 1cede09a0b.
2023-01-05 17:57:36 -06:00
Nicolas Williams
fefc380568 krb5: Quiet warning in socket_free() 2023-01-04 16:17:30 -06:00
Nicolas Williams
45cd575d83 krb5: Reduce storage max_alloc 2023-01-04 16:17:09 -06:00
Nicolas Williams
6b2e65592d krb5: Limit AP-REQs to 1MB in krb5_recvauth*() 2023-01-04 02:03:12 -06:00
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