Skip to content

Commit c51abd9

Browse files
ebiggersjarkkojs
authored andcommitted
KEYS: fix length validation in keyctl_pkey_params_get_2()
In many cases, keyctl_pkey_params_get_2() is validating the user buffer lengths against the wrong algorithm properties. Fix it to check against the correct properties. Probably this wasn't noticed before because for all asymmetric keys of the "public_key" subtype, max_data_size == max_sig_size == max_enc_size == max_dec_size. However, this isn't necessarily true for the "asym_tpm" subtype (it should be, but it's not strictly validated). Of course, future key types could have different values as well. Fixes: 00d60fd ("KEYS: Provide keyctls to drive the new key type ops for asymmetric keys [ver #2]") Cc: <stable@vger.kernel.org> # v4.20+ Signed-off-by: Eric Biggers <ebiggers@google.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
1 parent 8335adb commit c51abd9

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

security/keys/keyctl_pkey.c

+11-3
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,31 @@ static int keyctl_pkey_params_get_2(const struct keyctl_pkey_params __user *_par
135135

136136
switch (op) {
137137
case KEYCTL_PKEY_ENCRYPT:
138+
if (uparams.in_len > info.max_dec_size ||
139+
uparams.out_len > info.max_enc_size)
140+
return -EINVAL;
141+
break;
138142
case KEYCTL_PKEY_DECRYPT:
139143
if (uparams.in_len > info.max_enc_size ||
140144
uparams.out_len > info.max_dec_size)
141145
return -EINVAL;
142146
break;
143147
case KEYCTL_PKEY_SIGN:
148+
if (uparams.in_len > info.max_data_size ||
149+
uparams.out_len > info.max_sig_size)
150+
return -EINVAL;
151+
break;
144152
case KEYCTL_PKEY_VERIFY:
145-
if (uparams.in_len > info.max_sig_size ||
146-
uparams.out_len > info.max_data_size)
153+
if (uparams.in_len > info.max_data_size ||
154+
uparams.in2_len > info.max_sig_size)
147155
return -EINVAL;
148156
break;
149157
default:
150158
BUG();
151159
}
152160

153161
params->in_len = uparams.in_len;
154-
params->out_len = uparams.out_len;
162+
params->out_len = uparams.out_len; /* Note: same as in2_len */
155163
return 0;
156164
}
157165

0 commit comments

Comments
 (0)