Skip to content

Commit 644a607

Browse files
ebiggerssmb49
authored andcommitted
KEYS: fix length validation in keyctl_pkey_params_get_2()
BugLink: https://bugs.launchpad.net/bugs/1969110 commit c51abd9 upstream. 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: <[email protected]> # v4.20+ Signed-off-by: Eric Biggers <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit fe8df44892407e301ed03027639b4d904f12694c) Signed-off-by: Paolo Pisati <[email protected]>
1 parent 1ed8176 commit 644a607

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

security/keys/keyctl_pkey.c

Lines changed: 11 additions & 3 deletions
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)