From 7cabaa5d7023d5529cf5816939fbb4bce8b5083d Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Wed, 11 Dec 2024 10:43:22 +0100 Subject: [PATCH] pbkdf: Do not allow memory cost that cannot be used in size_t For 32bit platforms size_t is 32bit integer and unfortunately our maximum hard limit overflows by 1. Stop validation if this happens (it cannot be passed to malloc() and similar functions anyway). There should be no compatibility change, as such memory is not allocatable on 32bit anyway. Other platforms have 64bit size_t. --- lib/utils_pbkdf.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/utils_pbkdf.c b/lib/utils_pbkdf.c index 56971f27..670a5761 100644 --- a/lib/utils_pbkdf.c +++ b/lib/utils_pbkdf.c @@ -159,6 +159,10 @@ int verify_pbkdf_params(struct crypt_device *cd, pbkdf_limits.max_memory); r = -EINVAL; } + if (1024ULL * pbkdf->max_memory_kb > SIZE_MAX) { + log_err(cd, _("Requested maximum PBKDF memory cost is too high (limited by the integer maximal size).")); + r = -EINVAL; + } if (!pbkdf->max_memory_kb) { log_err(cd, _("Requested maximum PBKDF memory cannot be zero.")); r = -EINVAL;