]> git.baikalelectronics.ru Git - kernel.git/commit
seccomp: don't leak memory when filter install races
authorTycho Andersen <tycho@tycho.pizza>
Wed, 2 Sep 2020 01:40:16 +0000 (19:40 -0600)
committerKees Cook <keescook@chromium.org>
Tue, 8 Sep 2020 18:19:50 +0000 (11:19 -0700)
commit9df46be978eb668cde306838b5a2f1a9524b56c1
treeeaf1faa6cece4d4ba2d24192d6bf9cf633f47a44
parent066a8aace0c5f86a6f60488ff677bb53935358db
seccomp: don't leak memory when filter install races

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
anyway.

Fixes: 7f9dda3b2c2f ("seccomp: allow TSYNC and USER_NOTIF together")
Reported-by: syzbot+3ad9614a12f80994c32e@syzkaller.appspotmail.com
Signed-off-by: Tycho Andersen <tycho@tycho.pizza>
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
Link: https://lore.kernel.org/r/20200902014017.934315-1-tycho@tycho.pizza
Signed-off-by: Kees Cook <keescook@chromium.org>
kernel/seccomp.c