[PATCH v2 2/6] KEYS: Reject @desclen values >= KEY_MAX_DESC_SIZE in key_alloc()

Jarkko Sakkinen jarkko at kernel.org
Mon Oct 19 20:46:58 UTC 2026


On Mon, Oct 19, 2026 at 12:17:59PM -0700, Eric Biggers wrote:
> On Mon, Oct 19, 2026 at 09:17:22PM +0300, Jarkko Sakkinen wrote:
> > @desclen in key_alloc() is saved to the 16-bit wide desc_len field in
> > struct keyring_index_key.
> > 
> > Reject @desclen values at or above KEY_MAX_DESC_SIZE with -EINVAL in
> > order to account for the NUL terminator and prevent integer overflow.
> 
> This should say something like: "in order to match the userspace limit
> and avoid u16 truncation".
> 
> There are also similar truncations of desc_len to u16 in
> key_create_or_update() and keyring_search().

Ack.

> 
> > +#define KEY_MAX_DESC_SIZE 4096
> 
> Could use a comment mentioning that it includes the trailing NUL.

OK, that improved the commit mesage somewhat:

    KEYS: Reject @desclen values >= KEY_MAX_DESC_SIZE in key_alloc()

    @desclen in key_alloc() is saved to the 16-bit wide desc_len field in
    struct keyring_index_key.

    Reject @desclen values at or above KEY_MAX_DESC_SIZE with -EINVAL in order
    to match the userspace limit. The constraints inherits from the one byte
    required for the NULL character.

> 
> - Eric

Br, Jarkko



More information about the Linux-security-module-archive mailing list