[PATCH] KEYS: fix userspace buffer overflow in keyctl_pkey_e_d_s()
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Fri Nov 20 02:36:36 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: in2_len overwritten with max_sig_size in
keyctl_pkey_params_get_2() [1]
--
commit a87f672b96b4f7c3b4eabf969b369139c77f96be
Author: Guicai Ma <maguicai at kylinos.cn>
KEYS: fix userspace buffer overflow in keyctl_pkey_e_d_s()
This commit passes the caller-supplied uparams.out_len back from
keyctl_pkey_params_get_2() to keyctl_pkey_e_d_s() and returns -EOVERFLOW if
the operation output exceeds the userspace buffer size.
> 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
> @@ -113,7 +113,8 @@ static int keyctl_pkey_params_get(key_serial_t id,
> static int keyctl_pkey_params_get_2(const struct keyctl_pkey_params __user *_params,
> const char __user *_info,
> int op,
> - struct kernel_pkey_params *params)
> + struct kernel_pkey_params *params,
> + u32 *user_out_len)
> {
> struct keyctl_pkey_params uparams;
> struct kernel_pkey_query info;
> @@ -183,6 +184,8 @@ static int keyctl_pkey_params_get_2(const struct keyctl_pkey_params __user *_par
> }
>
> params->in_len = uparams.in_len;
> + if (user_out_len)
> + *user_out_len = uparams.out_len;
>
> switch (op) {
> case KEYCTL_PKEY_VERIFY:
[Severity: High]
This problem wasn't introduced by this patch, but in the
KEYCTL_PKEY_VERIFY case just above this hunk, commit cb481e59ea6c ("KEYS:
fix overflow in keyctl_pkey_params_get_2()") also overwrote params->out_len
(which aliases params->in2_len in struct kernel_pkey_params) with
info.max_sig_size instead of preserving uparams.in2_len [1]:
security/keys/keyctl_pkey.c:keyctl_pkey_params_get_2() {
...
case KEYCTL_PKEY_VERIFY:
if (uparams.in_len > info.max_data_size ||
uparams.in2_len > info.max_sig_size) {
ret = -EINVAL;
goto out_up_key_sem;
}
params->out_len = info.max_sig_size;
break;
...
}
When keyctl_pkey_verify() verifies a variable-length signature shorter than
info.max_sig_size (such as an ASN.1 DER-encoded ECDSA signature), does
memdup_user(_in2, params.in2_len) read past the end of the userspace _in2
buffer and either fail with -EFAULT or pass trailing garbage bytes to
asym_verify_signature()?
Should KEYCTL_PKEY_VERIFY set params->in2_len = uparams.in2_len instead?
[1] https://sashiko.dev/#/bug/linux-dd9ad2ca-a846-4d0d-89d6-aa262ffd40f1
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120022447.789625-1-maguicai@kylinos.cn?part=1
More information about the Linux-security-module-archive
mailing list