LKML Archive on
 help / color / Atom feed
From: Tycho Andersen <>
To: Kees Cook <>
Cc:, "Tobin C . Harding" <>,
	Christian Brauner <>,
	Tycho Andersen <>,
Subject: [PATCH 1/2] seccomp: don't leak memory when filter install races
Date: Tue,  1 Sep 2020 19:40:16 -0600
Message-ID: <> (raw)

In seccomp_set_mode_filter() with TSYNC | NEW_LISTENER, we first initialize
the listener fd, then check to see if we can actually use it later in
seccomp_may_assign_mode(), which can fail if anyone else in our thread
group has installed a filter and caused some divergence. If we can't, we
partially clean up the newly allocated file: we put the fd, put the file,
but don't actually clean up the *memory* that was allocated at
filter->notif. Let's clean that up too.

To accomplish this, let's hoist the actual "detach a notifier from a
filter" code to its own helper out of seccomp_notify_release(), so that in
case anyone adds stuff to init_listener(), they only have to add the
cleanup code in one spot. This does a bit of extra locking and such on the
failure path when the filter is not attached, but it's a slow failure path

Fixes: 51891498f2da ("seccomp: allow TSYNC and USER_NOTIF together")
Signed-off-by: Tycho Andersen <>
 kernel/seccomp.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/kernel/seccomp.c b/kernel/seccomp.c
index 3ee59ce0a323..bb0dd9ae699a 100644
--- a/kernel/seccomp.c
+++ b/kernel/seccomp.c
@@ -1109,13 +1109,12 @@ static long seccomp_set_mode_strict(void)
-static int seccomp_notify_release(struct inode *inode, struct file *file)
+static void seccomp_notify_detach(struct seccomp_filter *filter)
-	struct seccomp_filter *filter = file->private_data;
 	struct seccomp_knotif *knotif;
 	if (!filter)
-		return 0;
+		return;
@@ -1142,6 +1141,13 @@ static int seccomp_notify_release(struct inode *inode, struct file *file)
 	filter->notif = NULL;
+static int seccomp_notify_release(struct inode *inode, struct file *file)
+	struct seccomp_filter *filter = file->private_data;
+	seccomp_notify_detach(filter);
 	return 0;
@@ -1581,6 +1587,7 @@ static long seccomp_set_mode_filter(unsigned int flags,
 			listener_f->private_data = NULL;
+			seccomp_notify_detach(prepared);
 		} else {
 			fd_install(listener, listener_f);
 			ret = listener;

base-commit: f75aef392f869018f78cfedf3c320a6b3fcfda6b

             reply index

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-02  1:40 Tycho Andersen [this message]
2020-09-02  1:40 ` [PATCH 2/2] mailmap, MAINTAINERS: move to Tycho Andersen
2020-09-02  1:40   ` Tycho Andersen
2020-09-02  8:36   ` Christian Brauner
2020-09-02  9:08 ` [PATCH 1/2] seccomp: don't leak memory when filter install races Christian Brauner
2020-09-02 13:39   ` Tycho Andersen
2020-09-08 18:40 ` 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:

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

  git send-email \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

LKML Archive on

Archives are clonable:
	git clone --mirror lkml/git/0.git
	git clone --mirror lkml/git/1.git
	git clone --mirror lkml/git/2.git
	git clone --mirror lkml/git/3.git
	git clone --mirror lkml/git/4.git
	git clone --mirror lkml/git/5.git
	git clone --mirror lkml/git/6.git
	git clone --mirror lkml/git/7.git
	git clone --mirror lkml/git/8.git
	git clone --mirror lkml/git/9.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ \
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone