[PATCH 1/2] KEYS: Fix userspace buffer overflow in keyctl_pkey_e_d_s()

sashiko-bot at kernel.org sashiko-bot at kernel.org
Mon Nov 23 21:32:42 UTC 2026


Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] KEYS: sensitive plaintext leaked to slab in keyctl_pkey_e_d_s()
  [1]
--

commit e1794f1dd0090bbea27485536c98f990c8a30f19
Author: Guicai Ma <maguicai at kylinos.cn>

KEYS: Fix userspace buffer overflow in keyctl_pkey_e_d_s()

This commit passes the caller's output buffer length back from
keyctl_pkey_params_get_2() to keyctl_pkey_e_d_s() and returns -EOVERFLOW if
the operation output exceeds it before copying to userspace.

> diff --git a/security/keys/keyctl_pkey.c b/security/keys/keyctl_pkey.c
> index e7121523b9c9a..b5f82804b5ad1 100644
> --- a/security/keys/keyctl_pkey.c
> +++ b/security/keys/keyctl_pkey.c
[ ... ]
> @@ -310,6 +315,10 @@ long keyctl_pkey_e_d_s(int op,
>  	if (ret < 0)
>  		goto error_out;
>  
> +	if (ret > user_out_len) {
> +		ret = -EOVERFLOW;
> +		goto error_out;
> +	}
>  	if (copy_to_user(_out, out, ret) != 0)
>  		ret = -EFAULT;

[Severity: High]
This problem wasn't introduced by this patch, but should the error_out and
error_in paths in keyctl_pkey_e_d_s() use kfree_sensitive() instead of
kfree() [1]?

security/keys/keyctl_pkey.c:keyctl_pkey_e_d_s() {
	...
error_out:
	kfree(out);
error_in:
	kfree(in);
	...
}

Because in and out hold plaintext or other cryptographic payloads for
KEYCTL_PKEY_ENCRYPT, KEYCTL_PKEY_DECRYPT, and KEYCTL_PKEY_SIGN, freeing
them with kfree() leaves sensitive material in the slab cache.

[1] https://sashiko.dev/#/bug/linux-4199b169-0b8d-4055-9a71-6b5b79e38eb3

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123211959.4102708-1-jarkko@kernel.org?part=1



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