mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tycho Andersen <tycho@tycho.ws>
To: Kees Cook <keescook@chromium.org>
Cc: linux-kernel@vger.kernel.org, Jann Horn <jannh@google.com>,
	Tycho Andersen <tycho@tycho.ws>,
	Andy Lutomirski <luto@amacapital.net>
Subject: [PATCH 3/3] seccomp: introduce read protection for struct seccomp
Date: Fri, 28 Sep 2018 09:46:48 -0600	[thread overview]
Message-ID: <20180928154648.6320-3-tycho@tycho.ws> (raw)
In-Reply-To: <20180928154648.6320-1-tycho@tycho.ws>

As Jann pointed out, there is a race between SECCOMP_FILTER_FLAG_TSYNC and
the ptrace code that can inspect a filter of another process. Let's
introduce read locking into the two ptrace accesses so that we don't race.

Signed-off-by: Tycho Andersen <tycho@tycho.ws>
Reported-by: Jann Horn <jannh@google.com>
CC: Kees Cook <keescook@chromium.org>
CC: Andy Lutomirski <luto@amacapital.net>
---
 include/linux/seccomp.h |  4 ++--
 kernel/seccomp.c        | 10 ++++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/include/linux/seccomp.h b/include/linux/seccomp.h
index 8429bdda947a..30b27e898162 100644
--- a/include/linux/seccomp.h
+++ b/include/linux/seccomp.h
@@ -22,8 +22,8 @@ struct seccomp_filter;
  * @filter: must always point to a valid seccomp-filter or NULL as it is
  *          accessed without locking during system call entry.
  *
- *          @filter must only be accessed from the context of current as there
- *          is no read locking.
+ *          @filter is read-protected by task->signal->cred_guard_mutex when
+ *          outside of current context.
  */
 struct seccomp {
 	int mode;
diff --git a/kernel/seccomp.c b/kernel/seccomp.c
index ef80dd19f268..f65d47650ac1 100644
--- a/kernel/seccomp.c
+++ b/kernel/seccomp.c
@@ -1042,7 +1042,12 @@ int seccomp_get_filter(struct task_struct *task, unsigned long filter_off,
 		return -EACCES;
 	}
 
+	ret = mutex_lock_killable(&task->signal->cred_guard_mutex);
+	if (ret < 0)
+		return ret;
+
 	filter = get_nth_filter(task, filter_off);
+	mutex_unlock(&task->signal->cred_guard_mutex);
 	if (IS_ERR(filter))
 		return PTR_ERR(filter);
 
@@ -1088,7 +1093,12 @@ int seccomp_get_metadata(struct task_struct *task,
 	if (copy_from_user(&kmd.filter_off, data, sizeof(kmd.filter_off)))
 		return -EFAULT;
 
+	ret = mutex_lock_killable(&task->signal->cred_guard_mutex);
+	if (ret < 0)
+		return ret;
+
 	filter = get_nth_filter(task, kmd.filter_off);
+	mutex_unlock(&task->signal->cred_guard_mutex);
 	if (IS_ERR(filter))
 		return PTR_ERR(filter);
 
-- 
2.17.1


  parent reply	other threads:[~2018-09-28 15:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-28 15:46 [PATCH 1/3] seccomp: change return type of seccomp_get_metadata to int Tycho Andersen
2018-09-28 15:46 ` [PATCH 2/3] seccomp: change return type of seccomp_get_filter " Tycho Andersen
2018-09-28 15:46 ` Tycho Andersen [this message]
2018-09-28 20:33   ` [PATCH 3/3] seccomp: introduce read protection for struct seccomp Jann Horn
2018-09-28 20:56     ` Tycho Andersen
2018-09-28 21:10       ` Jann Horn
2018-09-28 21:35         ` Tycho Andersen
2018-09-28 21:54           ` Jann Horn
2018-09-28 22:02             ` Tycho Andersen

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=20180928154648.6320-3-tycho@tycho.ws \
    --to=tycho@tycho.ws \
    --cc=jannh@google.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    /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

Powered by JetHome