| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "testlib/s2n_testlib.h" |
| 17 |
#include "utils/s2n_safety.h" |
| 18 |
|
| 19 |
#ifdef SECCOMP |
| 20 |
|
| 21 |
#include <seccomp.h> |
| 22 |
|
| 23 |
DEFINE_POINTER_CLEANUP_FUNC(scmp_filter_ctx, seccomp_release); |
| 24 |
|
| 25 |
extern bool s2n_use_color_in_output; |
| 26 |
|
| 27 |
bool s2n_is_seccomp_supported() |
| 28 |
{ |
| 29 |
return true; |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
S2N_RESULT s2n_seccomp_init() |
| 38 |
{ |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
DEFER_CLEANUP(scmp_filter_ctx ctx = seccomp_init(SCMP_ACT_TRAP), |
| 44 |
seccomp_release_pointer); |
| 45 |
RESULT_ENSURE_REF(ctx); |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(access), 0)); |
| 56 |
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(brk), 0)); |
| 57 |
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(clock_gettime), 0)); |
| 58 |
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(close), 0)); |
| 59 |
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(exit_group), 0)); |
| 60 |
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(fstat), 0)); |
| 61 |
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(futex), 0)); |
| 62 |
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(getrandom), 0)); |
| 63 |
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(read), 0)); |
| 64 |
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 0)); |
| 65 |
|
| 66 |
|
| 67 |
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(newfstatat), 0)); |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
RESULT_GUARD_POSIX(seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EINVAL), SCMP_SYS(madvise), 0)); |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
s2n_use_color_in_output = false; |
| 77 |
|
| 78 |
RESULT_GUARD_POSIX(seccomp_load(ctx)); |
| 79 |
return S2N_RESULT_OK; |
| 80 |
} |
| 81 |
|
| 82 |
#else |
| 83 |
|
| 84 |
bool s2n_is_seccomp_supported() |
| 85 |
{ |
| 86 |
return false; |
| 87 |
} |
| 88 |
|
| 89 |
S2N_RESULT s2n_seccomp_init() |
| 90 |
{ |
| 91 |
return S2N_RESULT_OK; |
| 92 |
} |
| 93 |
|
| 94 |
#endif |