[PATCH v2 3/6] KEYS: Prevent overflow of user->{qnkeys,qnbytes} in key_alloc()
From: Jarkko Sakkinen
Date: Mon Oct 19 2026 - 14:20:04 EST
Add the missing overflow checks for user->qnkeys and user->qnbytes
in order keep calculations within INT_MAX range, which is the
absolute maximum quota.
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: LLM
Fixes: 7e047ef5fe2d ("[PATCH] keys: sort out key quota system")
Reviewed-by: David Howells <dhowells@xxxxxxxxxx>
Signed-off-by: Jarkko Sakkinen <jarkko@xxxxxxxxxx>
---
security/keys/key.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/security/keys/key.c b/security/keys/key.c
index e9f8cacf00c8..d4e4a2e89a20 100644
--- a/security/keys/key.c
+++ b/security/keys/key.c
@@ -263,6 +263,10 @@ struct key *key_alloc(struct key_type *type, const char *desc,
key_quota_root_maxbytes : key_quota_maxbytes;
spin_lock_irqsave(&user->lock, irqflags);
+ if (user->qnkeys == INT_MAX ||
+ quotalen > INT_MAX - user->qnbytes)
+ goto no_quota;
+
if (!(flags & KEY_ALLOC_QUOTA_OVERRUN)) {
if (user->qnkeys + 1 > maxkeys ||
user->qnbytes + quotalen > maxbytes ||
--
2.47.3