diff options
author | Paul Moore <paul@paul-moore.com> | 2020-07-26 11:01:49 -0400 |
---|---|---|
committer | Paul Moore <paul@paul-moore.com> | 2020-08-18 11:44:44 -0400 |
commit | ce314fe4111887c593e3c6b17c60d93bc6ab66b9 (patch) | |
tree | 41c2c6b5bf4e9c1ead1e3f8122e5ff5ff6b5f465 /src/system.h | |
parent | bee43d3e884788569860a384e6a38357785a3995 (diff) | |
download | libseccomp-ce314fe4111887c593e3c6b17c60d93bc6ab66b9.tar.gz |
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>
Diffstat (limited to 'src/system.h')
-rw-r--r-- | src/system.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/system.h b/src/system.h index 133f9b1..096f3ca 100644 --- a/src/system.h +++ b/src/system.h @@ -182,6 +182,8 @@ struct seccomp_notif_resp { #define SECCOMP_IOCTL_NOTIF_ID_VALID SECCOMP_IOR(2, __u64) #endif /* SECCOMP_RET_USER_NOTIF */ +void sys_reset_state(void); + int sys_chk_seccomp_syscall(void); void sys_set_seccomp_syscall(bool enable); @@ -193,6 +195,7 @@ void sys_set_seccomp_flag(int flag, bool enable); int sys_filter_load(struct db_filter_col *col, bool rawrc); +int sys_notify_fd(void); int sys_notify_alloc(struct seccomp_notif **req, struct seccomp_notif_resp **resp); int sys_notify_receive(int fd, struct seccomp_notif *req); |