[PATCH] all: only request the userspace notification fd once
authorPaul Moore <paul@paul-moore.com>
Sun, 26 Jul 2020 15:01:49 +0000 (11:01 -0400)
committerFelix Geyer <fgeyer@debian.org>
Sun, 8 Nov 2020 18:59:21 +0000 (18:59 +0000)
commitca05f27cbccefc460e1059dae0b34edda0ca2833
treedb7e9727eb4067ee65884b076f08309835650b65
parent67321010d3290eaa61d95fcbec36c35a4148d9ec
[PATCH] all: only request the userspace notification fd once

It turns out that requesting the seccomp userspace notifcation fd
more than once is a bad thing which causes the kernel to complain
(rightfully so for a variety of reasons).  Unfortunately as we were
always requesting the notification fd whenever possible this results
in problems at filter load time.

Our solution is to move the notification fd out of the filter context
and into the global task context, using a newly created task_state
structure.  This allows us to store, and retrieve the notification
outside the scope of an individual filter context.  It also provides
some implementation improvements by giving us a convenient place to
stash all of the API level related support variables.  We also extend
the seccomp_reset() API call to reset this internal global state when
passed a NULL filter context.

There is one potential case which we don't currently handle well:
threads.  At the moment libseccomp is thread ignorant, and that works
well as the only global state up to this point was the currently
supported API level information which was common to all threads in a
process.  Unfortunately, it appears that the notification fd need not
be common to all threads in a process, yet this patch treats it as if
it is common.  I suspect this is a very unusual use case so I decided
to keep this patch simple and ignore this case, but in the future if
we need to support this properly we should be able to do so without
API changes by keeping an internal list of notification fds indexed
by gettid(2).

This fixes the GitHub issue below:
* https://github.com/seccomp/libseccomp/issues/273

Reported-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Acked-by: Tom Hromatka <tom.hromatka@oracle.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
(imported from commit ce314fe4111887c593e3c6b17c60d93bc6ab66b9)

Gbp-Pq: Name all_only_request_the_userspace_notification_fd_once.patch
doc/man/man3/seccomp_init.3
doc/man/man3/seccomp_notify_alloc.3
src/api.c
src/db.c
src/db.h
src/system.c
src/system.h
tests/11-basic-basic_errors.c
tests/51-live-user_notification.c
tests/51-live-user_notification.py