-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement user notification in libseccomp
Kernel 5.0 includes the new user notification return code. Here's all the infrastructure to handle that. Signed-off-by: Tycho Andersen <tycho@tycho.ws>
- Loading branch information
Showing
9 changed files
with
302 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,3 +55,4 @@ util.pyc | |
47-live-kill_process | ||
48-sim-32b_args | ||
49-sim-64b_comparisons | ||
50-user-notification |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#include <sys/types.h> | ||
#include <sys/wait.h> | ||
#include <unistd.h> | ||
#include <seccomp.h> | ||
#include <signal.h> | ||
#include <syscall.h> | ||
#include <errno.h> | ||
#include <stdlib.h> | ||
|
||
#include "util.h" | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
int rc, fd = -1, status; | ||
struct seccomp_notif *req = NULL; | ||
struct seccomp_notif_resp *resp = NULL; | ||
scmp_filter_ctx ctx = NULL; | ||
pid_t pid = 0; | ||
struct util_options opts; | ||
|
||
rc = util_getopt(argc, argv, &opts); | ||
if (rc < 0) | ||
goto out; | ||
|
||
ctx = seccomp_init(SCMP_ACT_ALLOW); | ||
if (ctx == NULL) | ||
return ENOMEM; | ||
|
||
rc = util_filter_output(&opts, ctx); | ||
if (rc) | ||
goto out; | ||
|
||
rc = seccomp_attr_set(ctx, SCMP_FLTATR_NEW_LISTENER, 1); | ||
if (rc) | ||
goto out; | ||
|
||
rc = seccomp_rule_add_exact(ctx, SCMP_ACT_USER_NOTIF, SCMP_SYS(getpid), 0, NULL); | ||
if (rc) | ||
goto out; | ||
|
||
rc = fd = seccomp_load(ctx); | ||
if (rc < 0) | ||
goto out; | ||
|
||
#define MAGIC 0x1122334455667788UL | ||
pid = fork(); | ||
if (pid == 0) | ||
exit(syscall(SCMP_SYS(getpid)) != MAGIC); | ||
|
||
rc = seccomp_alloc_notifications(&req, &resp); | ||
if (rc) | ||
goto out; | ||
|
||
rc = seccomp_receive_notif(fd, req); | ||
if (rc) | ||
goto out; | ||
|
||
if (req->data.nr != SCMP_SYS(getpid)) { | ||
rc = -EINVAL; | ||
goto out; | ||
} | ||
|
||
resp->id = req->id; | ||
resp->val = MAGIC; | ||
resp->error = 0; | ||
|
||
rc = seccomp_send_notif_resp(fd, resp); | ||
if (rc) | ||
goto out; | ||
|
||
rc = -EINVAL; | ||
if (waitpid(pid, &status, 0) != pid) | ||
goto out; | ||
|
||
if (!WIFEXITED(status)) | ||
goto out; | ||
|
||
if (WEXITSTATUS(status)) | ||
goto out; | ||
|
||
rc = 0; | ||
out: | ||
if (req) | ||
seccomp_free_notifications(req, resp); | ||
if (pid) | ||
kill(pid, SIGKILL); | ||
seccomp_release(ctx); | ||
if (fd >= 0) | ||
close(fd); | ||
return (rc < 0 ? -rc : rc); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# | ||
# libseccomp regression test automation data | ||
# | ||
# Copyright Cisco Systems 2019 | ||
# Author: Tycho Andersen <tycho@tycho.ws> | ||
# | ||
|
||
test type: bpf-sim | ||
|
||
# Testname Arch Syscall Arg0 Arg1 Arg2 Arg3 Arg4 Arg5 Result | ||
50-user-notification all,-x32 0-350 N N N N N N USER_NOTIF | ||
|
||
test type: bpf-sim-fuzz | ||
|
||
# Testname StressCount | ||
50-user-notification 50 | ||
|
||
test type: bpf-valgrind | ||
|
||
# Testname | ||
50-user-notification |
Oops, something went wrong.