public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KEYS: DH: validate __spare field
@ 2017-07-03 20:50 Eric Biggers
  2017-07-07  8:19 ` David Howells
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Biggers @ 2017-07-03 20:50 UTC (permalink / raw)
  To: keyrings
  Cc: David Howells, Mat Martineau, Stephan Mueller, stable,
	Eric Biggers

From: Eric Biggers <ebiggers@google.com>

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: stable@vger.kernel.org # v4.12+
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 security/keys/compat_dh.c | 2 ++
 security/keys/dh.c        | 5 +++++
 2 files changed, 7 insertions(+)

diff --git a/security/keys/compat_dh.c b/security/keys/compat_dh.c
index a6a659b6bcb6..aa6b34cafe5f 100644
--- a/security/keys/compat_dh.c
+++ b/security/keys/compat_dh.c
@@ -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);
 }
diff --git a/security/keys/dh.c b/security/keys/dh.c
index 4755d4b4f945..d1ea9f325f94 100644
--- a/security/keys/dh.c
+++ b/security/keys/dh.c
@@ -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;
-- 
2.13.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] KEYS: DH: validate __spare field
  2017-07-03 20:50 [PATCH] KEYS: DH: validate __spare field Eric Biggers
@ 2017-07-07  8:19 ` David Howells
  2017-07-07 16:04   ` Mat Martineau
  0 siblings, 1 reply; 3+ messages in thread
From: David Howells @ 2017-07-07  8:19 UTC (permalink / raw)
  To: Eric Biggers, Mat Martineau
  Cc: dhowells, keyrings, Stephan Mueller, stable, Eric Biggers

Eric Biggers <ebiggers3@gmail.com> wrote:

> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] KEYS: DH: validate __spare field
  2017-07-07  8:19 ` David Howells
@ 2017-07-07 16:04   ` Mat Martineau
  0 siblings, 0 replies; 3+ messages in thread
From: Mat Martineau @ 2017-07-07 16:04 UTC (permalink / raw)
  To: David Howells
  Cc: Eric Biggers, keyrings, Stephan Mueller, stable, Eric Biggers

On Fri, 7 Jul 2017, David Howells wrote:

> Eric Biggers <ebiggers3@gmail.com> wrote:
>
>> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-07-07 16:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-03 20:50 [PATCH] KEYS: DH: validate __spare field Eric Biggers
2017-07-07  8:19 ` David Howells
2017-07-07 16:04   ` Mat Martineau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox