| 1 |
/* COVERAGE: seccomp */ |
| 2 |
|
| 3 |
#define _GNU_SOURCE |
| 4 |
#include <unistd.h> |
| 5 |
#include <sys/syscall.h> |
| 6 |
|
| 7 |
#ifdef __NR_seccomp |
| 8 |
|
| 9 |
#include <linux/seccomp.h> |
| 10 |
#include <linux/filter.h> |
| 11 |
#include <linux/audit.h> |
| 12 |
#include <linux/signal.h> |
| 13 |
#include <sys/ptrace.h> |
| 14 |
|
| 15 |
// Some versions of <linux/seccomp.h> don't define SECCOMP_SET_MODE_FILTER. |
| 16 |
#ifndef SECCOMP_SET_MODE_FILTER |
| 17 |
#define SECCOMP_SET_MODE_FILTER 1 |
| 18 |
#endif |
| 19 |
|
| 20 |
struct sock_filter filter[] = { |
| 21 |
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW), |
| 22 |
}; |
| 23 |
|
| 24 |
struct sock_fprog prog = { |
| 25 |
.len = (unsigned short) (sizeof(filter) / sizeof(filter[0])), |
| 26 |
.filter = filter, |
| 27 |
}; |
| 28 |
|
| 29 |
static inline int __seccomp(unsigned int operation, unsigned int flags, void *args) |
| 30 |
{ |
| 31 |
return syscall(__NR_seccomp, operation, flags, args); |
| 32 |
} |
| 33 |
|
| 34 |
int main() |
| 35 |
{ |
| 36 |
__seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog); |
| 37 |
//staptest// [[[[seccomp (SECCOMP_SET_MODE_FILTER, 0x0, XXXX)!!!!ni_syscall ()]]]] = NNNN |
| 38 |
|
| 39 |
// Limit testing |
| 40 |
|
| 41 |
__seccomp(-1, 0, NULL); |
| 42 |
//staptest// [[[[seccomp (0x[f]+, 0x0, 0x0)!!!!ni_syscall ()]]]] = -NNNN |
| 43 |
|
| 44 |
__seccomp(SECCOMP_SET_MODE_FILTER, -1, NULL); |
| 45 |
//staptest// [[[[seccomp (SECCOMP_SET_MODE_FILTER, 0x[f]+, 0x0)!!!!ni_syscall ()]]]] = -NNNN |
| 46 |
|
| 47 |
__seccomp(SECCOMP_SET_MODE_FILTER, 0, (void *)-1); |
| 48 |
#ifdef __s390__ |
| 49 |
//staptest// [[[[seccomp (SECCOMP_SET_MODE_FILTER, 0x0, 0x[7]?[f]+)!!!!ni_syscall ()]]]] = -NNNN |
| 50 |
#else |
| 51 |
//staptest// [[[[seccomp (SECCOMP_SET_MODE_FILTER, 0x0, 0x[f]+)!!!!ni_syscall ()]]]] = -NNNN |
| 52 |
#endif |
| 53 |
|
| 54 |
return 0; |
| 55 |
} |
| 56 |
#else |
| 57 |
int main() |
| 58 |
{ |
| 59 |
return 0; |
| 60 |
} |
| 61 |
#endif |