-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add seccomp support for sandbox #274
base: sandbox
Are you sure you want to change the base?
Conversation
Great work! Attached is a diff which reworks the macros and some cleanup: diff --git compat-sandbox.c compat-sandbox.c
index 3f63556..2645f23 100644
--- compat-sandbox.c
+++ compat-sandbox.c
@@ -36,49 +36,45 @@ sandbox(int stage)
#include <err.h>
#include <seccomp.h>
-#define ALLOW(syscall) \
- if (seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(syscall), 0) < 0) { \
- err(1, "seccomp_rule_add"); \
- }
+#define ALLOW(syscall) \
+ (seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(syscall), 0) < 0)
-#define ALLOW_IOCTL(syscall, x) \
- if (seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(ioctl), x, \
- SCMP_A1(SCMP_CMP_EQ, syscall)) < 0) { \
- err(1, "seccomp_rule_add (ioctl)"); \
- }
+#define ALLOW_IOCTL(syscall, x) \
+ (seccomp_rule_add(ctx, SCMP_ACT_ALLOW,SCMP_SYS(ioctl), x, \
+ SCMP_A1(SCMP_CMP_EQ, syscall)) < 0)
void
sandbox(int stage)
{
- scmp_filter_ctx ctx;
+ scmp_filter_ctx ctx;
switch (stage) {
case SANDBOX_ENTER:
-
if ((ctx = seccomp_init(SCMP_ACT_TRAP)) == NULL)
err(1, "seccomp_init");
- ALLOW(access);
- ALLOW(close);
- ALLOW(exit_group);
- ALLOW(fstat);
- ALLOW(fstat64);
- ALLOW(mmap);
- ALLOW(mmap2);
- ALLOW(munmap);
- ALLOW(open);
- ALLOW(poll);
- ALLOW(read);
- ALLOW(rt_sigaction);
- ALLOW(sigaction);
- ALLOW(sigreturn);
- ALLOW(stat);
- ALLOW(stat64);
- ALLOW(time);
- ALLOW(write);
- ALLOW_IOCTL(TCGETS, 1);
- ALLOW_IOCTL(TCSETS, 1);
- ALLOW_IOCTL(TIOCGWINSZ, 1);
+ if (ALLOW(access) ||
+ ALLOW(close) ||
+ ALLOW(exit_group) ||
+ ALLOW(fstat) ||
+ ALLOW(fstat64) ||
+ ALLOW(mmap) ||
+ ALLOW(mmap2) ||
+ ALLOW(munmap) ||
+ ALLOW(open) ||
+ ALLOW(poll) ||
+ ALLOW(read) ||
+ ALLOW(rt_sigaction) ||
+ ALLOW(sigaction) ||
+ ALLOW(sigreturn) ||
+ ALLOW(stat) ||
+ ALLOW(stat64) ||
+ ALLOW(time) ||
+ ALLOW(write) ||
+ ALLOW_IOCTL(TCGETS, 1) ||
+ ALLOW_IOCTL(TCSETS, 1) ||
+ ALLOW_IOCTL(TIOCGWINSZ, 1))
+ err(1, "seccomp_rule_add");
if (seccomp_load(ctx) < 0)
err(1, "seccomp_load"); |
I guess
|
Thanks: applied! |
cebf2cd
to
321e6e7
Compare
The experimental |
Codecov Report
@@ Coverage Diff @@
## sandbox #274 +/- ##
========================================
Coverage 90.58% 90.58%
========================================
Files 1 1
Lines 510 510
========================================
Hits 462 462
Misses 48 48 Continue to review full report at Codecov.
|
No description provided.