Skip to content

Commit

Permalink
KEYS: DH: validate __spare field
Browse files Browse the repository at this point in the history
Syscalls must validate that their reserved arguments are zero and return
EINVAL otherwise.  Otherwise, it will be impossible to actually use them
for anything in the future because existing programs may be passing
garbage in.  This is standard practice when adding new APIs.

Cc: [email protected]
Signed-off-by: Eric Biggers <[email protected]>
Signed-off-by: David Howells <[email protected]>
Signed-off-by: James Morris <[email protected]>
  • Loading branch information
ebiggers authored and James Morris committed Jul 14, 2017
1 parent 5ccbdbf commit 4f9dabf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions security/keys/compat_dh.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ long compat_keyctl_dh_compute(struct keyctl_dh_params __user *params,
kdfcopy.hashname = compat_ptr(compat_kdfcopy.hashname);
kdfcopy.otherinfo = compat_ptr(compat_kdfcopy.otherinfo);
kdfcopy.otherinfolen = compat_kdfcopy.otherinfolen;
memcpy(kdfcopy.__spare, compat_kdfcopy.__spare,
sizeof(kdfcopy.__spare));

return __keyctl_dh_compute(params, buffer, buflen, &kdfcopy);
}
5 changes: 5 additions & 0 deletions security/keys/dh.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ long __keyctl_dh_compute(struct keyctl_dh_params __user *params,
if (kdfcopy) {
char *hashname;

if (memchr_inv(kdfcopy->__spare, 0, sizeof(kdfcopy->__spare))) {
ret = -EINVAL;
goto out1;
}

if (buflen > KEYCTL_KDF_MAX_OUTPUT_LEN ||
kdfcopy->otherinfolen > KEYCTL_KDF_MAX_OI_LEN) {
ret = -EMSGSIZE;
Expand Down

0 comments on commit 4f9dabf

Please sign in to comment.