krb5 commit [krb5-1.22]: Prevent read underrun on empty db_args tl-data
ghudson at mit.edu
ghudson at mit.edu
Tue Nov 17 14:41:36 EST 2026
https://github.com/krb5/krb5/commit/f691f657c5ab560703c7adf4dcab6e3ecc205886
commit f691f657c5ab560703c7adf4dcab6e3ecc205886
Author: ubeddulla khan <ubed at bugqore.com>
Date: Fri Nov 13 21:36:42 2026 +0530
Prevent read underrun on empty db_args tl-data
In extract_db_args_from_tl_data(), reject a zero-length
KRB5_TL_DB_ARGS value before reading its last byte to check for a null
terminator. kadmind can receive such a value from a client with add
or modify privileges, causing a one-byte read before a zero-size heap
allocation and possibly a further over-read in the KDB module.
(cherry picked from commit 7aaada396eb3a43169916d551956fd7f03bf1d60)
ticket: 9287
version_fixed: 1.22.4
src/lib/kdb/kdb5.c | 3 ++-
src/tests/kdbtest.c | 8 ++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/lib/kdb/kdb5.c b/src/lib/kdb/kdb5.c
index b6db28d8d..91638b544 100644
--- a/src/lib/kdb/kdb5.c
+++ b/src/lib/kdb/kdb5.c
@@ -910,7 +910,8 @@ extract_db_args_from_tl_data(krb5_context kcontext, krb5_tl_data **start,
/* Since this is expected to be NULL terminated string and
this could come from any client, do a check before
passing it to db. */
- if (((char *) curr->tl_data_contents)[curr->tl_data_length - 1] !=
+ if (curr->tl_data_length == 0 ||
+ ((char *) curr->tl_data_contents)[curr->tl_data_length - 1] !=
'\0') {
/* Not null terminated. Dangerous input. */
status = EINVAL;
diff --git a/src/tests/kdbtest.c b/src/tests/kdbtest.c
index 6459c3390..61fff5951 100644
--- a/src/tests/kdbtest.c
+++ b/src/tests/kdbtest.c
@@ -37,6 +37,7 @@
#include <krb5.h>
#include <kadm5/admin.h>
+#include <errno.h>
#include <string.h>
static krb5_context ctx;
@@ -101,6 +102,9 @@ static krb5_tl_data tl3 = { &tl4, KRB5_TL_KADM_DATA, 32,
static krb5_tl_data tl2 = { &tl3, KRB5_TL_MOD_PRINC, 8, U("\5\6\7\0x at Y\0") };
static krb5_tl_data tl1 = { &tl2, KRB5_TL_LAST_PWD_CHANGE, 4, U("\1\2\3\4") };
+/* A zero-length db_args value, as kadmind can receive from a client. */
+static krb5_tl_data tl_empty_db_args = { NULL, KRB5_TL_DB_ARGS, 0, NULL };
+
/* An encoded osa_print_enc with no policy reference. */
static krb5_tl_data tl_no_policy = { NULL, KRB5_TL_KADM_DATA, 24,
U("\x12\x34\x5C\x01\x00\x00\x00\x00"
@@ -385,6 +389,10 @@ main(void)
* KDB_TL_USER_INFO tl-data. */
CHECK(krb5_db_delete_principal(ctx, &sample_princ));
CHECK(krb5_db_put_principal(ctx, ent));
+
+ /* Check that a zero-length db_args tl-data value is rejected. */
+ CHECK(krb5_dbe_update_tl_data(ctx, ent, &tl_empty_db_args));
+ CHECK_COND(krb5_db_put_principal(ctx, ent) == EINVAL);
krb5_db_free_principal(ctx, ent);
/* Exercise principal iteration code. */
More information about the cvs-krb5
mailing list