[RFC PATCH 4/8] KEYS: Prevent overflow of user->qnkeys in key_alloc()
From: Jarkko Sakkinen
Date: Mon Oct 19 2026 - 11:52:20 EST
Add the missing check rejecting allocations when user->qnkeys has reached
INT_MAX.
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: LLM
Fixes: 7e047ef5fe2d ("[PATCH] keys: sort out key quota system")
Signed-off-by: Jarkko Sakkinen <jarkko@xxxxxxxxxx>
---
security/keys/key.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/security/keys/key.c b/security/keys/key.c
index 7888c0c6a772..30f8a8dea206 100644
--- a/security/keys/key.c
+++ b/security/keys/key.c
@@ -263,6 +263,9 @@ 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)
+ goto no_quota;
+
if (!(flags & KEY_ALLOC_QUOTA_OVERRUN)) {
if (user->qnkeys + 1 > maxkeys ||
user->qnbytes + quotalen > maxbytes ||
--
2.47.3