Skip to content

Commit a08bf91

Browse files
ebiggersJames Morris
authored andcommitted
KEYS: allow reaching the keys quotas exactly
If the sysctl 'kernel.keys.maxkeys' is set to some number n, then actually users can only add up to 'n - 1' keys. Likewise for 'kernel.keys.maxbytes' and the root_* versions of these sysctls. But these sysctls are apparently supposed to be *maximums*, as per their names and all documentation I could find -- the keyrings(7) man page, Documentation/security/keys/core.rst, and all the mentions of EDQUOT meaning that the key quota was *exceeded* (as opposed to reached). Thus, fix the code to allow reaching the quotas exactly. Fixes: 0b77f5b ("keys: make the keyring quotas controllable through /proc/sys") Cc: stable@vger.kernel.org Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: James Morris <james.morris@microsoft.com>
1 parent 5ded587 commit a08bf91

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

security/keys/key.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ struct key *key_alloc(struct key_type *type, const char *desc,
265265

266266
spin_lock(&user->lock);
267267
if (!(flags & KEY_ALLOC_QUOTA_OVERRUN)) {
268-
if (user->qnkeys + 1 >= maxkeys ||
269-
user->qnbytes + quotalen >= maxbytes ||
268+
if (user->qnkeys + 1 > maxkeys ||
269+
user->qnbytes + quotalen > maxbytes ||
270270
user->qnbytes + quotalen < user->qnbytes)
271271
goto no_quota;
272272
}

0 commit comments

Comments
 (0)