| | #include <errno.h> |
| | #include <seccomp.h> |
| | #include <stdio.h> |
| | #include <stdlib.h> |
| | #include <unistd.h> |
| |
|
| | int main(int argc, char* argv[]) { |
| | if (argc < 2) { |
| | fprintf(stderr, "Usage: %s <command> [args...]\n", argv[0]); |
| | return EXIT_FAILURE; |
| | } |
| |
|
| | scmp_filter_ctx ctx; |
| |
|
| | |
| | ctx = seccomp_init(SCMP_ACT_ALLOW); |
| | if (ctx == NULL) { |
| | perror("seccomp_init"); |
| | return EXIT_FAILURE; |
| | } |
| |
|
| | |
| |
|
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| |
|
| | seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EPERM), SCMP_SYS(connect), 0); |
| | seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EPERM), SCMP_SYS(accept), 0); |
| | seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EPERM), SCMP_SYS(send), 0); |
| | seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EPERM), SCMP_SYS(sendto), 0); |
| | seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EPERM), SCMP_SYS(sendmsg), 0); |
| | seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EPERM), SCMP_SYS(recv), 0); |
| | seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EPERM), SCMP_SYS(recvfrom), 0); |
| | seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EPERM), SCMP_SYS(recvmsg), 0); |
| | seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EPERM), SCMP_SYS(setsockopt), 0); |
| | seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EPERM), SCMP_SYS(getsockopt), 0); |
| |
|
| | |
| | if (seccomp_load(ctx) < 0) { |
| | perror("seccomp_load"); |
| | seccomp_release(ctx); |
| | return EXIT_FAILURE; |
| | } |
| |
|
| | #ifdef DEBUG |
| | printf("seccomp filter installed. Network access is blocked.\n"); |
| | #endif |
| |
|
| | |
| | execvp(argv[1], argv + 1); |
| |
|
| | seccomp_release(ctx); |
| | return EXIT_SUCCESS; |
| | } |
| |
|