From: sashiko-bot@kernel.org
Cc: "open list:SECURITY SUBSYSTEM" <linux-security-module@vger.kernel.org>
Subject: Re: [PATCH v3 2/3] KEYS: Reject @desclen values >= KEY_MAX_DESC_SIZE in key_alloc()
Date: Tue, 20 Oct 2026 01:51:12 +0000 [thread overview]
Message-ID: <sashiko-outbox-178417@kernel.org> (raw)
In-Reply-To: <20261020013903.1244157-3-jarkko@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] keys: u16 desc_len truncation in __key_create_or_update() before key_alloc()
--
commit e17213de3a1a23830538a740d7a666ca408d3916
Author: Jarkko Sakkinen <jarkko@kernel.org>
KEYS: Reject @desclen values >= KEY_MAX_DESC_SIZE in key_alloc()
This commit moves KEY_MAX_DESC_SIZE to include/linux/key.h and rejects
descriptions with length at or above KEY_MAX_DESC_SIZE in key_alloc() to
prevent overflowing the 16-bit desc_len field in struct keyring_index_key.
> diff --git a/security/keys/key.c b/security/keys/key.c
> index a438c4508595d..aa0112a693e68 100644
> --- a/security/keys/key.c
> +++ b/security/keys/key.c
> @@ -245,6 +245,8 @@ struct key *key_alloc(struct key_type *type, const char *desc,
> }
>
> desclen = strlen(desc);
> + if (desclen >= KEY_MAX_DESC_SIZE)
> + goto error;
> quotalen = desclen + 1 + type->def_datalen;
>
> /* get hold of the key tracking for this user */
[Severity: Critical]
Is checking desclen in key_alloc() too late when a key is created or
updated through __key_create_or_update()?
In security/keys/key.c, __key_create_or_update() can obtain
index_key.description from index_key.type->preparse(&prep) (for example,
via add_key() with a NULL description and the "asymmetric" key type, where
x509_key_preparse() in crypto/asymmetric_keys/x509_public_key.c constructs
prep.description from the X.509 subject and hex-encoded serial or skid
without bounding it to KEY_MAX_DESC_SIZE) or from an in-kernel caller of
key_create_or_update().
Before calling key_alloc(), __key_create_or_update() assigns the length
directly into the 16-bit index_key.desc_len field and passes index_key to
the keyring lookup and linking helpers:
security/keys/key.c:__key_create_or_update() {
if (index_key.type->preparse) {
ret = index_key.type->preparse(&prep);
if (ret < 0) {
key_ref = ERR_PTR(ret);
goto error_free_prep;
}
if (!index_key.description)
index_key.description = prep.description;
key_ref = ERR_PTR(-EINVAL);
if (!index_key.description)
goto error_free_prep;
}
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);
...
key_ref = find_key_to_update(keyring_ref, &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);
}
If strlen(index_key.description) is 65536 (which x509_key_preparse() can
produce from a ~33 KB certificate payload because bin2hex() doubles the
serial or skid length), truncating it to the u16 index_key.desc_len yields
0 and hits BUG_ON(index_key->desc_len == 0) in __key_link_begin() in
security/keys/keyring.c before key_alloc() is ever reached:
security/keys/keyring.c:__key_link_begin() {
...
BUG_ON(index_key->desc_len == 0);
}
Similarly, if strlen(index_key.description) is >= KEY_MAX_DESC_SIZE and not
a multiple of 65536, the unvalidated or truncated desc_len is used by
key_set_index_key(), __key_link_begin(), and find_key_to_update(), which
can match and update an existing key with that shorter prefix via
goto found_matching_key without calling key_alloc(). Other paths that
populate struct keyring_index_key directly, such as keyring_search() in
security/keys/keyring.c and request_key_and_link() / request_key_rcu() in
security/keys/request_key.c, also assign index_key.desc_len =
strlen(description) without checking against KEY_MAX_DESC_SIZE.
Should the KEY_MAX_DESC_SIZE check also be enforced in
__key_create_or_update() (and other struct keyring_index_key initialization
paths) before assigning index_key.desc_len?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261020013903.1244157-1-jarkko@kernel.org?part=2
next prev parent reply other threads:[~2026-10-20 1:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-20 1:38 [PATCH v3 0/3] KEYS: rhashtable bug fixes Jarkko Sakkinen
2026-10-20 1:38 ` [PATCH v3 1/3] KEYS: Expand key->{datalen,quotalen} to unsigned int Jarkko Sakkinen
2026-10-20 1:46 ` sashiko-bot
2026-10-20 15:47 ` Eric Biggers
2026-10-20 15:56 ` Jarkko Sakkinen
2026-10-20 1:38 ` [PATCH v3 2/3] KEYS: Reject @desclen values >= KEY_MAX_DESC_SIZE in key_alloc() Jarkko Sakkinen
2026-10-20 1:47 ` Jarkko Sakkinen
2026-10-20 2:28 ` Eric Biggers
2026-10-20 10:57 ` Jarkko Sakkinen
2026-10-20 13:00 ` Jarkko Sakkinen
2026-10-20 15:50 ` Eric Biggers
2026-10-20 16:09 ` Jarkko Sakkinen
2026-10-20 1:51 ` sashiko-bot [this message]
2026-10-20 1:38 ` [PATCH v3 3/3] KEYS: Verify the key identity in __key_unlink_begin Jarkko Sakkinen
2026-10-20 1:44 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-178417@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.