From 15416d801a0ade89f2754b59f46f4fb3dc188290 Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Fri, 31 Jan 2025 09:24:53 +1300 Subject: [PATCH] dsdb:password_hash.c: restrict crypt hash to proper forms Signed-off-by: Douglas Bagnall Reviewed-by: Jennifer Sutton --- .../dsdb/samdb/ldb_modules/password_hash.c | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/source4/dsdb/samdb/ldb_modules/password_hash.c b/source4/dsdb/samdb/ldb_modules/password_hash.c index ee4aae6d10a..b7a0c5066a7 100644 --- a/source4/dsdb/samdb/ldb_modules/password_hash.c +++ b/source4/dsdb/samdb/ldb_modules/password_hash.c @@ -1562,6 +1562,9 @@ static bool parse_scheme(const char *scheme, int *algorithm, int *rounds) { == 0) { *algorithm = SHA_512_ALGORITHM_ID; } else { + DBG_ERR("user password scheme '%s' is not SHA_256 or SHA_512 " + "('$5$' or '$6$')\n", + scheme); return false; } @@ -1577,6 +1580,27 @@ static bool parse_scheme(const char *scheme, int *algorithm, int *rounds) { } digits[i] = '\0'; *rounds = atoi(digits); + /* + * According to https://www.akkadia.org/drepper/SHA-crypt.txt + * SHA_256 and SHA_512 crypt rounds are restricted to the range + * [1000, 999_999_999]. (thus it is OK to use int and atoi). + * + * As specified crypt() itself will clamp to these values and + * continue, but that leads to confusing situations, like the + * salt not matching. + * + * Rather than let that happen, we complain and bail out. This + * is from smb.conf ("password hash userPassword schemes"), + * and we want to let the admin know it's wrong. + */ + if (*rounds < 1000 || *rounds > 999999999) { + DBG_ERR("user password scheme '%s' specifies a non-standard " + "number of rounds (%d)\n", + scheme, + *rounds); + return false; + } + return true; } -- 2.47.3