Skip to contentSkip to conversation

KEYS: DH: validate __spare field

PATCH In review Eric Biggers 3 participants 3 messages Jul 3, 2017 – Jul 7, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KEYS: DH: validate __spare field

From: Eric Biggers <[email protected]>

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.

---
 security/keys/compat_dh.c | 2 ++
 security/keys/dh.c        | 5 +++++
 2 files changed, 7 insertions(+)
security/keys/compat_dh.c +2 -0
index a6a659b6bcb6..aa6b34cafe5f 100644
@@ -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);
 }
security/keys/dh.c +5 -0
index 4755d4b4f945..d1ea9f325f94 100644
@@ -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;
Signature · 1 line
2.13.2
maintainer
#1 lore raw
Quoted 4 lines · Eric Biggers

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.

Fine by me. Mat?

David

#2 lore raw
Quoted 8 lines · David Howells
Quoted 4 lines · Eric Biggers

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.

Fine by me. Mat?

Looks good, please apply the patch. Thanks for catching this, Eric.

--
Mat Martineau
Intel OTC