Skip to content

Commit 2e35610

Browse files
xuyang0410Jarkko Sakkinen
authored andcommitted
KEYS: reaching the keys quotas correctly
Currently, when we add a new user key, the calltrace as below: add_key() key_create_or_update() key_alloc() __key_instantiate_and_link generic_key_instantiate key_payload_reserve ...... Since commit a08bf91 ("KEYS: allow reaching the keys quotas exactly"), we can reach max bytes/keys in key_alloc, but we forget to remove this limit when we reserver space for payload in key_payload_reserve. So we can only reach max keys but not max bytes when having delta between plen and type->def_datalen. Remove this limit when instantiating the key, so we can keep consistent with key_alloc. Also, fix the similar problem in keyctl_chown_key(). Fixes: 0b77f5b ("keys: make the keyring quotas controllable through /proc/sys") Fixes: a08bf91 ("KEYS: allow reaching the keys quotas exactly") Cc: stable@vger.kernel.org # 5.0.x Cc: Eric Biggers <ebiggers@google.com> Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Reviewed-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
1 parent 18b3670 commit 2e35610

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

‎security/keys/key.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ int key_payload_reserve(struct key *key, size_t datalen)
382382
spin_lock(&key->user->lock);
383383

384384
if (delta > 0 &&
385-
(key->user->qnbytes + delta >= maxbytes ||
385+
(key->user->qnbytes + delta > maxbytes ||
386386
key->user->qnbytes + delta < key->user->qnbytes)) {
387387
ret = -EDQUOT;
388388
}

‎security/keys/keyctl.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,8 +937,8 @@ long keyctl_chown_key(key_serial_t id, uid_t user, gid_t group)
937937
key_quota_root_maxbytes : key_quota_maxbytes;
938938

939939
spin_lock(&newowner->lock);
940-
if (newowner->qnkeys + 1 >= maxkeys ||
941-
newowner->qnbytes + key->quotalen >= maxbytes ||
940+
if (newowner->qnkeys + 1 > maxkeys ||
941+
newowner->qnbytes + key->quotalen > maxbytes ||
942942
newowner->qnbytes + key->quotalen <
943943
newowner->qnbytes)
944944
goto quota_overrun;

0 commit comments

Comments
 (0)