KEYS: rhashtable bug fixes
Subsystems (3)
Jarkko Sakkinen
maintainercover KEYS: rhashtable bug fixes
My patch set that migrates assoc_array to rhashtable had some LLM scavegend bug fixes. Unfortunately most them where either plain wrong or not in the right scope. The bug fixes in this patch set are by human labour constructed fully but they are derived from what I got out of the original LLM source. Thus, they are tagged as LLM assisted.
Jarkko Sakkinen (8):
KEYS: Change the type of key->quotalen to unsigned int
KEYS: Change the type of key->datalen to unsigned int
KEYS: Reject @desclen values over U16_MAX in key_alloc()
KEYS: Prevent overflow of user->qnkeys in key_alloc()
KEYS: Prevent overflow of quota in key_alloc()
KEYS: Prevent overflow of user->qnbytes in key_alloc()
KEYS: Reject @datalen values over INT_MAX
KEYS: Verify the key identity in __keyctl_unlink
include/linux/key.h | 4 ++-- security/keys/key.c | 13 ++++++++++++- security/keys/keyring.c | 6 ++++++ 3 files changed, 20 insertions(+), 3 deletions(-)
--
2.47.3
Jarkko Sakkinen
maintainerRFC PATCH 1/8 KEYS: Change the type of key->quotalen to unsigned int
key_alloc() and key_payload_reserve() set key->quotalen with values, which can be larger than USHRT_MAX.
Change the type from unsigned short to unsigned int.
--- include/linux/key.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/key.h +1 -1
@@ -216,7 +216,7 @@ struct key {kuid_t uid;kgid_t gid;key_perm_t perm;/* access permissions */ -unsigned short quotalen;/* length added to quota */ +unsigned int quotalen;/* length added to quota */ unsigned short datalen;/* payload data length * - may not match RCU dereferenced payload * - payload should contain own length
Signature · 1 line
2.47.3
Jarkko Sakkinen
maintainerRFC PATCH 2/8 KEYS: Change the type of key->datalen to unsigned int
In reply to Jarkko Sakkinenkey_alloc() and key_payload_reserve() set key->datalen with values, which can be larger than USHRT_MAX.
Change the type from unsigned short to unsigned int.
--- include/linux/key.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/key.h +1 -1
@@ -217,7 +217,7 @@ struct key {kgid_t gid;key_perm_t perm;/* access permissions */ unsigned int quotalen;/* length added to quota */ -unsigned short datalen;/* payload data length +unsigned int datalen;/* payload data length * - may not match RCU dereferenced payload * - payload should contain own length */
Signature · 1 line
2.47.3
Jarkko Sakkinen
maintainerRFC PATCH 3/8 KEYS: Reject @desclen values over U16_MAX in key_alloc()
In reply to Jarkko Sakkinen@desclen in key_alloc() is saved to the 16-bit wide desc_len field in struct keyring_index_key.
Reject @desclen values over U16_MAX with -EINVAL in order to prevent integer overflow.
--- security/keys/key.c | 2 ++ 1 file changed, 2 insertions(+)
security/keys/key.c +2 -0
@@ -245,6 +245,8 @@ struct key *key_alloc(struct key_type *type, const char *desc, } desclen =strlen (desc); +if (desclen >U16_MAX ) + goto error; quotalen = desclen +1 + type->def_datalen;/* get hold of the key tracking for this user */
Signature · 1 line
2.47.3
Jarkko Sakkinen
maintainerRFC PATCH 4/8 KEYS: Prevent overflow of user->qnkeys in key_alloc()
In reply to Jarkko SakkinenAdd the missing check rejecting allocations when user->qnkeys has reached INT_MAX.
--- security/keys/key.c | 3 +++ 1 file changed, 3 insertions(+)
security/keys/key.c +3 -0
@@ -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 ||
Signature · 1 line
2.47.3
Jarkko Sakkinen
maintainerRFC PATCH 5/8 KEYS: Prevent overflow of quota in key_alloc()
In reply to Jarkko SakkinenCheck that the calculated quota length does not go over INT_MAX.
--- security/keys/key.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
security/keys/key.c +1 -1
@@ -245,7 +245,7 @@ struct key *key_alloc(struct key_type *type, const char *desc, } desclen =strlen (desc); -if (desclen >U16_MAX ) +if (desclen >U16_MAX || type->def_datalen >INT_MAX - desclen -1 ) goto error; quotalen = desclen +1 + type->def_datalen;
Signature · 1 line
2.47.3
Jarkko Sakkinen
maintainerRFC PATCH 6/8 KEYS: Prevent overflow of user->qnbytes in key_alloc()
In reply to Jarkko SakkinenAdd the missing check rejecting resulting byte counts above INT_MAX.
--- security/keys/key.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
security/keys/key.c +2 -1
@@ -263,7 +263,8 @@ 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 ) +if (user->qnkeys ==INT_MAX || + quotalen >INT_MAX - user->qnbytes) goto no_quota;if (!(flags &KEY_ALLOC_QUOTA_OVERRUN )) {
Signature · 1 line
2.47.3
Jarkko Sakkinen
maintainerRFC PATCH 7/8 KEYS: Reject @datalen values over INT_MAX
In reply to Jarkko SakkinenProtect quota from overflowing by rejecting @datalen values that surpass over INT_MAX.
--- security/keys/key.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
security/keys/key.c +6 -1
@@ -379,11 +379,16 @@ EXPORT_SYMBOL(key_alloc);*/ int key_payload_reserve (struct key *key,size_t datalen) { -int delta = (int )datalen - key->datalen; +int delta;int ret =0 ;key_check (key); +if (datalen >INT_MAX ) +return -EINVAL ; + + delta = (int )datalen - key->datalen; +/* contemplate the quota adjustment */ if (delta !=0 &&test_bit (KEY_FLAG_IN_QUOTA , &key->flags)) { unsigned maxbytes = uid_eq(key->user->uid, GLOBAL_ROOT_UID) ?
Signature · 1 line
2.47.3
Jarkko Sakkinen
maintainerRFC PATCH 8/8 KEYS: Verify the key identity in __keyctl_unlink
In reply to Jarkko SakkinenLet's define the following preconditions:
- Two keys: A and B.
- R is a keyring.
- Both have the same type/description/domain.
Then:
1. KEYCTL_LINK(A, R) => {A}
1. KEYCTL_LINK(B, R) => {B}
2. KEYCTL_UNLINK(A, R) => {}
Instead, verify key tidentity before unlinking, and return -ENOENT on mismatch.
--- security/keys/keyring.c | 6 ++++++ 1 file changed, 6 insertions(+)
security/keys/keyring.c +6 -0
@@ -1501,9 +1501,15 @@ static int __key_unlink_begin(struct key *keyring, struct key *key, struct assoc_array_edit **_edit) {struct assoc_array_edit *edit; +const void *object;BUG_ON (*_edit !=NULL ); + object =assoc_array_find (&keyring->keys, &keyring_assoc_array_ops, + &key->index_key); +if (!object ||keyring_ptr_to_key (object) != key) +return -ENOENT ; + edit =assoc_array_delete (&keyring->keys, &keyring_assoc_array_ops, &key->index_key);if (IS_ERR (edit))
Signature · 1 line
2.47.3
Jarkko Sakkinen
maintainerQuoted 5 lines · Jarkko Sakkinen
My patch set that migrates
assoc_arrayto rhashtable had some LLM scavegend bug fixes. Unfortunately most them where either plain wrong or not in the right scope. The bug fixes in this patch set are by human labour constructed fully but they are derived from what I got out of the original LLM source. Thus, they are tagged as LLM assisted.
I like to document any possible LLM association mostly for self-reflection. I'm still adapting and not fully comfortable with every detail so this gives a chance to look back and learn how to do things better in the future.
So I'm neither supporter or desupporter of LLMs but more like representing the "I don't know what to think about this" camp :-)
Somewhat fuzzy opinion I have that more guards and checks should be set to the patch submission process to address "proxy contributors". At high rate such fixes are right bug but wrong fix type of situations where author is really not an author but instead a reporter. This is both time consuming and unfair for legit contributors.
Quoted 11 lines
Jarkko Sakkinen (8):
KEYS: Change the type ofkey->quotalento unsigned int
KEYS: Change the type ofkey->datalento unsigned int
KEYS: Reject @desclen values overU16_MAXinkey_alloc()
KEYS: Prevent overflow ofuser->qnkeysinkey_alloc()
KEYS: Prevent overflow of quota inkey_alloc()
KEYS: Prevent overflow ofuser->qnbytesinkey_alloc()
KEYS: Reject @datalen values overINT_MAX
KEYS: Verify the key identity in__keyctl_unlink
Quoted 8 lines
include/linux/key.h | 4 ++-- security/keys/key.c | 13 ++++++++++++- security/keys/keyring.c | 6 ++++++ 3 files changed, 20 insertions(+), 3 deletions(-)--
2.47.3
Br, Jarkko
Re: [RFC PATCH 2/8] KEYS: Change the type of key->datalen to unsigned int
In reply to Jarkko SakkinenI would merge this with patch 1.
Apart from that:
on both 1 & 2.
David
David Howells
maintainerRe: [RFC PATCH 3/8] KEYS: Reject @desclen values over U16_MAX in key_alloc()
In reply to Jarkko SakkinenQuoted 2 lines · Jarkko Sakkinen
Reject @desclen values over
U16_MAXwith-EINVALin order to prevent integer overflow.
KEY_MAX_DESC_SIZE.
David
[email protected]
AI reviewRe: [RFC PATCH 1/8] KEYS: Change the type of key->quotalen to unsigned int
In reply to Jarkko SakkinenSashiko has reviewed this patch and found no issues.
Quoted 9 lines
key_alloc()andkey_payload_reserve()setkey->quotalenwith values, which can be larger thanUSHRT_MAX.Change the type from unsigned short to unsigned int.
Assisted-by LLMFixes 1da177e4c3f4 ("Linux-2.6.12-rc2")Signed-off-by Jarkko Sakkinen <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [RFC PATCH 5/8] KEYS: Prevent overflow of quota in key_alloc()
In reply to Jarkko Sakkinensecurity/keys/key.c struct key *key_alloc(struct key_type *type, const char *desc, · line 248
Quoted 1 line · Jarkko Sakkinen
security/keys/key.c +0
-1-if (desclen >U16_MAX )
This should also be KEY_MAX_DESC_SIZE.
security/keys/key.c struct key *key_alloc(struct key_type *type, const char *desc, · line 248
Quoted 1 line
security/keys/key.c +1
-0+if (desclen >U16_MAX || type->def_datalen >INT_MAX - desclen -1 )
That looks awkward, but I can see why you did it.
[email protected]
AI reviewRe: [RFC PATCH 2/8] KEYS: Change the type of key->datalen to unsigned int
In reply to Jarkko SakkinenSashiko has reviewed this patch and found no issues.
Quoted 9 lines
key_alloc()andkey_payload_reserve()setkey->datalenwith values, which can be larger thanUSHRT_MAX.Change the type from unsigned short to unsigned int.
Assisted-by LLMFixes 1da177e4c3f4 ("Linux-2.6.12-rc2")Signed-off-by Jarkko Sakkinen <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [RFC PATCH 6/8] KEYS: Prevent overflow of user->qnbytes in key_alloc()
In reply to Jarkko SakkinenI suggest merging patches 4 and 6, then add:
David Howells
maintainerRe: [RFC PATCH 7/8] KEYS: Reject @datalen values over INT_MAX
In reply to Jarkko Sakkinensecurity/keys/key.c EXPORT_SYMBOL(key_alloc); · line 391
Quoted 11 lines · Jarkko Sakkinen
security/keys/key.c +6
-1-int delta = (int )datalen - key->datalen; +int delta;int ret =0 ;key_check (key); +if (datalen >INT_MAX ) +return -EINVAL ; + + delta = (int )datalen - key->datalen; +
You don't actually need to move the subtraction.
But apart from that:
[email protected]
AI reviewRe: [RFC PATCH 3/8] KEYS: Reject @desclen values over U16_MAX in key_alloc()
In reply to Jarkko SakkinenThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] KEYS: desc_len truncation in __key_create_or_update() before key_alloc() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] KEYS: desc_len truncation in __key_create_or_update() before key_alloc() --
commit e49d7d031ada6f60dccb5c6e74d1e66145a0c3d4
Author: Jarkko Sakkinen <[email protected]>
KEYS: Reject @desclen values over U16_MAX in key_alloc()
This commit adds a bounds check in key_alloc() to reject key descriptions longer than U16_MAX with -EINVAL, preventing truncation when storing the length in the 16-bit desc_len field of struct keyring_index_key.
security/keys/key.c struct key *key_alloc(struct key_type *type, const char *desc, · line 252
Quoted 13 lines
security/keys/key.c +2
-0@@ -245,6 +245,8 @@ struct key *key_alloc(struct key_type *type, const char *desc, } desclen =strlen (desc); +if (desclen >U16_MAX ) + goto error; quotalen = desclen +1 + type->def_datalen;/* get hold of the key tracking for this user */
[Severity: High]
Does __key_create_or_update() also need to validate the description length before assigning index_key.desc_len?
In security/keys/key.c, __key_create_or_update() assigns strlen() to the 16-bit index_key.desc_len field and passes it into __key_link_begin() and find_key_to_update() before key_alloc() is called:
security/keys/key.c:__key_create_or_update() {
...
index_key.desc_len = strlen(index_key.description);
key_set_index_key(&index_key);
ret = __key_link_lock(keyring, &index_key);
if (ret < 0) {
key_ref = ERR_PTR(ret);
goto error_free_prep;
}
ret = __key_link_begin(keyring, &index_key, &edit);
if (ret < 0) {
key_ref = ERR_PTR(ret);
goto error_link_end;
}
...
if (allow_update) {
if (index_key.type->update) {
key_ref = find_key_to_update(keyring, &index_key);
if (key_ref)
goto found_matching_key;
}
}
key = key_alloc(index_key.type, index_key.description,
cred->fsuid, cred->fsgid, cred, perm, flags, NULL);
}Although add_key() limits user-supplied _description strings to KEY_MAX_DESC_SIZE, _description can be NULL when index_key.type->preparse generates prep.description from the payload. For example, in crypto/asymmetric_keys/x509_public_key.c, x509_key_preparse() constructs prep->description from the X.509 certificate subject and hex-encoded serial or skid:
desc = kmalloc(sulen + 2 + srlen * 2 + 1, GFP_KERNEL); if (!desc) return -ENOMEM; p = memcpy(desc, cert->subject, sulen); p += sulen; *p++ = ':'; *p++ = ' '; p = bin2hex(p, q, srlen); *p = 0;
Since the payload can be up to almost 1MB, strlen(index_key.description) can exceed U16_MAX.
If strlen(index_key.description) is a multiple of 65536 (or 0), index_key.desc_len truncates to 0 and triggers BUG_ON(index_key->desc_len == 0) in __key_link_begin() in security/keys/keyring.c before key_alloc() is reached.
If strlen(index_key.description) > U16_MAX is not a multiple of 65536, index_key.desc_len truncates to strlen % 65536. Because keyring_compare_object() in security/keys/keyring.c only compares index_key->desc_len bytes:
return key->index_key.type == index_key->type && key->index_key.domain_tag == index_key->domain_tag && key->index_key.desc_len == index_key->desc_len && memcmp(key->index_key.description, index_key->description, index_key->desc_len) == 0;
find_key_to_update() can match an existing key with a shorter description sharing that prefix and update the wrong key via goto found_matching_key, bypassing key_alloc() altogether (or fail with -EEXIST instead of -EINVAL).
In addition, keyring_search() in security/keys/keyring.c, as well as request_key_and_link() and request_key_rcu() in security/keys/request_key.c, also assign strlen(description) directly to .index_key.desc_len without bounds checking.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [RFC PATCH 8/8] KEYS: Verify the key identity in __keyctl_unlink
In reply to Jarkko SakkinenThis will show it:
keyctl newring ring_a @s
keyctl newring ring_b @s
A=keyctl add user A ss %:ring_a
B=keyctl add user A qq %:ring_b
keyctl newring R @s
keyctl show
keyctl link $A %:R
keyctl show
keyctl link $B %:R
keyctl show
keyctl unlink $A %:R
keyctl show # R is now incorrectly empty
[email protected]
AI reviewRe: [RFC PATCH 4/8] KEYS: Prevent overflow of user->qnkeys in key_alloc()
In reply to Jarkko SakkinenSashiko has reviewed this patch and found no issues.
Quoted 7 lines
Add the missing check rejecting allocations when
user->qnkeyshas reachedINT_MAX.Assisted-by LLMFixes 7e047ef5fe2d ("[PATCH] keys: sort out key quota system")Signed-off-by Jarkko Sakkinen <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [RFC PATCH 5/8] KEYS: Prevent overflow of quota in key_alloc()
In reply to Jarkko SakkinenThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] keys: u16 truncation of desc_len in __key_create_or_update() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] keys: u16 truncation of desc_len in __key_create_or_update()
--
commit ceebacfa6e4fbe645d2fe96b70fce1be4e928c92
Author: Jarkko Sakkinen <[email protected]>
KEYS: Prevent overflow of quota in key_alloc()
This commit adds a check in key_alloc() to ensure that the calculated quotalen does not exceed INT_MAX when combining desclen and type->def_datalen.
security/keys/key.c struct key *key_alloc(struct key_type *type, const char *desc, · line 251
Quoted 13 lines
security/keys/key.c +1
-1@@ -245,7 +245,7 @@ struct key *key_alloc(struct key_type *type, const char *desc, } desclen =strlen (desc); -if (desclen >U16_MAX ) +if (desclen >U16_MAX || type->def_datalen >INT_MAX - desclen -1 ) goto error; quotalen = desclen +1 + type->def_datalen;
[Severity: High]
Is checking desclen > U16_MAX in key_alloc() sufficient to prevent u16 truncation of index_key.desc_len in the __key_create_or_update() path?
In security/keys/key.c:__key_create_or_update(), when index_key.type->preparse generates prep.description (or a caller passes a long description to key_create_or_update() or key_create()), strlen(index_key.description) is assigned directly to the u16 field index_key.desc_len and passed to __key_link_begin() and find_key_to_update() before key_alloc() is ever called:
security/keys/key.c:__key_create_or_update() {
...
index_key.desc_len = strlen(index_key.description);
key_set_index_key(&index_key);
ret = __key_link_lock(keyring, &index_key);
if (ret < 0) {
key_ref = ERR_PTR(ret);
goto error_free_prep;
}
ret = __key_link_begin(keyring, &index_key, &edit);
...
}For example, when add_key("asymmetric", NULL, payload, plen, keyring) is called with a crafted X.509 certificate, asn1_ber_decoder() caps the input blob at datalen <= 65535, but x509_key_preparse() constructs prep->description by hex-encoding cert->raw_serial (or cert->raw_skid) via bin2hex(), which doubles its length:
crypto/asymmetric_keys/x509_public_key.c:x509_key_preparse() {
...
desc = kmalloc(sulen + 2 + srlen * 2 + 1, GFP_KERNEL);
if (!desc)
return -ENOMEM;
p = memcpy(desc, cert->subject, sulen);
p += sulen;
*p++ = ':';
*p++ = ' ';
p = bin2hex(p, q, srlen);
*p = 0;
...
}If a certificate has sulen == 0 and srlen == 32767 (with distinct issuer and subject so x509_check_for_self_signed() skips signature verification), strlen(prep.description) is 0 + 2 + 32767 * 2 = 65536 (U16_MAX + 1).
When __key_create_or_update() assigns 65536 to u16 index_key.desc_len, it truncates to 0, and __key_link_begin() immediately hits a BUG_ON before reaching key_alloc():
security/keys/keyring.c:__key_link_begin() {
...
BUG_ON(index_key->desc_len == 0);
...
}If strlen(index_key.description) exceeds U16_MAX and is not a multiple of 65536, index_key.desc_len truncates modulo 65536, causing __key_link_begin() and find_key_to_update() to operate on a truncated description length before key_alloc() can reject it.
Should __key_create_or_update() also validate strlen(index_key.description) <= U16_MAX before assigning index_key.desc_len?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
[email protected]
AI reviewRe: [RFC PATCH 6/8] KEYS: Prevent overflow of user->qnbytes in key_alloc()
In reply to Jarkko SakkinenSashiko has reviewed this patch and found no issues.
Quoted 6 lines
Add the missing check rejecting resulting byte counts above
INT_MAX.Assisted-by LLMFixes 7e047ef5fe2d ("[PATCH] keys: sort out key quota system")Signed-off-by Jarkko Sakkinen <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
[email protected]
AI reviewRe: [RFC PATCH 7/8] KEYS: Reject @datalen values over INT_MAX
In reply to Jarkko SakkinenSashiko has reviewed this patch and found no issues.
Quoted 7 lines
Protect quota from overflowing by rejecting @datalen values that surpass over
INT_MAX.Assisted-by LLMFixes 1da177e4c3f4 ("Linux-2.6.12-rc2")Signed-off-by Jarkko Sakkinen <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
[email protected]
AI reviewRe: [RFC PATCH 8/8] KEYS: Verify the key identity in __keyctl_unlink
In reply to Jarkko SakkinenSashiko has reviewed this patch and found no issues.
Quoted 12 lines
Let's define the following preconditions:
- Two keys: A and B.
- R is a keyring.
- Both have the same type/description/domain.Then:
1.
KEYCTL_LINK(A, R)=> {A}
1.KEYCTL_LINK(B, R)=> {B}
2.KEYCTL_UNLINK(A, R)=> {}
Quoted 7 lines
Instead, verify key tidentity before unlinking, and return
-ENOENTon mismatch.Fixes b2a4df200d57 ("KEYS: Expand the capacity of a keyring")Assisted-by LLMSigned-off-by Jarkko Sakkinen <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Jarkko Sakkinen
maintainerRe: [RFC PATCH 2/8] KEYS: Change the type of key->datalen to unsigned int
In reply to David HowellsQuoted 10 lines · David Howells
I would merge this with patch 1.
Apart from that:
Reviewed-by David Howells <[email protected]>on both 1 & 2.
David
I can do that. I went a little over the top with sanity checking the slop :-)
Br, Jarkko
Jarkko Sakkinen
maintainerRe: [RFC PATCH 3/8] KEYS: Reject @desclen values over U16_MAX in key_alloc()
In reply to David HowellsQuoted 8 lines · David Howells
Quoted 2 lines · Jarkko Sakkinen
Reject @desclen values over
U16_MAXwith-EINVALin order to prevent integer overflow.
KEY_MAX_DESC_SIZE.David
Good catch, thanks.
Br, Jarkko
Jarkko Sakkinen
maintainerRe: [RFC PATCH 5/8] KEYS: Prevent overflow of quota in key_alloc()
In reply to David HowellsQuoted 6 lines · David Howells
security/keys/key.c struct key *key_alloc(struct key_type *type, const char *desc, · line 248
Quoted 1 line · Jarkko Sakkinen
security/keys/key.c +0
-1-if (desclen >U16_MAX )This should also be
KEY_MAX_DESC_SIZE.
Quoted 6 lines
security/keys/key.c struct key *key_alloc(struct key_type *type, const char *desc, · line 248
Quoted 1 line
security/keys/key.c +1
-0+if (desclen >U16_MAX || type->def_datalen >INT_MAX - desclen -1 )That looks awkward, but I can see why you did it.
Reviewed-by David Howells <[email protected]>
Do you mind if I do search-replace and apply these with KEY_MAX_DESC_SIZE fixup?
Br, Jarkko
Jarkko Sakkinen
maintainerRe: [RFC PATCH 6/8] KEYS: Prevent overflow of user->qnbytes in key_alloc()
In reply to David HowellsQuoted 3 lines · David Howells
I suggest merging patches 4 and 6, then add:
Reviewed-by David Howells <[email protected]>
Ok, I'll merge 1-2 and 4-6 both and apply, thanks.
Br, Jarkko
Jarkko Sakkinen
maintainerRe: [RFC PATCH 7/8] KEYS: Reject @datalen values over INT_MAX
In reply to David HowellsQuoted 8 lines · David Howells
Quoted 6 lines · Jarkko Sakkinen
security/keys/key.c +1
-1-int delta = (int )datalen - key->datalen; +int delta;int ret =0 ;key_check (key);
Quoted 7 lines
security/keys/key.c EXPORT_SYMBOL(key_alloc); · line 391
Quoted 5 lines
security/keys/key.c +5
-0+if (datalen >INT_MAX ) +return -EINVAL ; + + delta = (int )datalen - key->datalen; +You don't actually need to move the subtraction.
Ouch, you're right, I'll fixup that.
Quoted 4 lines
But apart from that:
Signed-off-by David Howells <[email protected]>
Br, Jarkko
Jarkko Sakkinen
maintainerRe: [RFC PATCH 8/8] KEYS: Verify the key identity in __keyctl_unlink
In reply to David HowellsQuoted 15 lines · David Howells
This will show it:
keyctl newring
ring_a@s
keyctl newringring_b@s
A=keyctl add user A ss %:ring_a
B=keyctl add user A qq %:ring_b
keyctl newring R @s
keyctl show
keyctl link $A %:R
keyctl show
keyctl link $B %:R
keyctl show
keyctl unlink $A %:R
keyctl show # R is now incorrectly empty
Quoted 1 line
Reviewed-by David Howells <[email protected]>
I'll actually add this to my own test harness, thanks.
I'm a slightly worried of this patch given that you can technically interpret it as a uapi change. I guess here it is acceptable, and if a tree falls down, we'll respond to that.
Br, Jarkko