mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tycho Andersen <tycho@tycho.ws>
To: linux-kernel@vger.kernel.org, Kees Cook <keescook@chromium.org>
Cc: Tycho Andersen <tycho@tycho.ws>, Oleg Nesterov <oleg@redhat.com>
Subject: [PATCH 2/3] ptrace, seccomp: tweak get_metadata behavior slightly
Date: Tue, 20 Feb 2018 19:47:46 -0700	[thread overview]
Message-ID: <20180221024747.9659-3-tycho@tycho.ws> (raw)
In-Reply-To: <20180221024747.9659-1-tycho@tycho.ws>

Previously if users passed a small size for the input structure size, they
would get get odd behavior. It doesn't make sense to pass a structure
smaller than at least filter_off size, so let's just give -EINVAL in this
case.

This changes userspace visible behavior, but was only introduced in commit
26500475ac1b ("ptrace, seccomp: add support for retrieving seccomp
metadata") in 4.16-rc2, so should be safe to change if merged before then.

Reported-by: Eugene Syromiatnikov <esyr@redhat.com>
Signed-off-by: Tycho Andersen <tycho@tycho.ws>
CC: Kees Cook <keescook@chromium.org>
CC: Oleg Nesterov <oleg@redhat.com>
---
 kernel/seccomp.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/seccomp.c b/kernel/seccomp.c
index 940fa408a288..dc77548167ef 100644
--- a/kernel/seccomp.c
+++ b/kernel/seccomp.c
@@ -1076,14 +1076,16 @@ long seccomp_get_metadata(struct task_struct *task,
 
 	size = min_t(unsigned long, size, sizeof(kmd));
 
-	if (copy_from_user(&kmd, data, size))
+	if (size < sizeof(kmd.filter_off))
+		return -EINVAL;
+
+	if (copy_from_user(&kmd.filter_off, data, sizeof(kmd.filter_off)))
 		return -EFAULT;
 
 	filter = get_nth_filter(task, kmd.filter_off);
 	if (IS_ERR(filter))
 		return PTR_ERR(filter);
 
-	memset(&kmd, 0, sizeof(kmd));
 	if (filter->log)
 		kmd.flags |= SECCOMP_FILTER_FLAG_LOG;
 
-- 
2.14.1

  parent reply	other threads:[~2018-02-21  2:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-21  2:47 [PATCH 0/3] some fixups for PTRACE_SECCOMP_GET_METADATA Tycho Andersen
2018-02-21  2:47 ` [PATCH 1/3] seccomp, ptrace: switch get_metadata types to arch independent Tycho Andersen
2018-02-21  3:17   ` Dmitry V. Levin
2018-02-21  2:47 ` Tycho Andersen [this message]
2018-02-21  2:47 ` [PATCH 3/3] seccomp: add a selftest for get_metadata Tycho Andersen
2018-02-22  1:05 ` [PATCH 0/3] some fixups for PTRACE_SECCOMP_GET_METADATA Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180221024747.9659-3-tycho@tycho.ws \
    --to=tycho@tycho.ws \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®