summaryrefslogtreecommitdiffstats
path: root/tests/helpers/test_enosys.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/helpers/test_enosys.c126
1 files changed, 27 insertions, 99 deletions
diff --git a/tests/helpers/test_enosys.c b/tests/helpers/test_enosys.c
index 9e93cc2..98f8d15 100644
--- a/tests/helpers/test_enosys.c
+++ b/tests/helpers/test_enosys.c
@@ -16,111 +16,39 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include <stddef.h>
-#include <stdbool.h>
-#include <getopt.h>
-
-#include <linux/unistd.h>
-#include <linux/filter.h>
-#include <linux/seccomp.h>
-#include <linux/audit.h>
-#include <sys/prctl.h>
-
-#include "c.h"
-#include "audit-arch.h"
-#include "exitcodes.h"
-
-#define syscall_nr (offsetof(struct seccomp_data, nr))
-
-struct syscall {
- const char *const name;
- int number;
-};
-
-const struct syscall syscalls[] = {
-#ifdef __NR_move_mount
- { "move_mount", __NR_move_mount },
-#endif
-#ifdef __NR_open_tree
- { "open_tree", __NR_open_tree },
-#endif
-#ifdef __NR_fsopen
- { "fsopen", __NR_fsopen },
-#endif
-#ifdef __NR_mount_setattr
- { "mount_setattr", __NR_mount_setattr },
-#endif
-
-};
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
int main(int argc, char **argv)
{
- int c;
- size_t i;
- bool found;
- static const struct option longopts[] = {
- { "syscall", required_argument, NULL, 's' },
- { 0 }
- };
+ int r;
- bool blocked_syscalls[ARRAY_SIZE(syscalls)] = {};
-
- while ((c = getopt_long (argc, argv, "s:", longopts, NULL)) != -1) {
- switch (c) {
- case 's':
- found = 0;
- for (i = 0; i < ARRAY_SIZE(syscalls); i++) {
- if (strcmp(optarg, syscalls[i].name) == 0) {
- blocked_syscalls[i] = true;
- found = 1;
- break;
- }
- }
- if (!found)
- errx(EXIT_FAILURE, "Unknown syscall '%s'", optarg);
- break;
- default:
- errx(EXIT_FAILURE, "Unknown option");
- }
+ if (argc != 2) {
+ fprintf(stderr, "invalid options\n");
+ return EXIT_FAILURE;
}
- if (optind >= argc)
- errx(EXIT_FAILURE, "No executable specified");
-
-#define N_FILTERS (ARRAY_SIZE(syscalls) + 3)
-
- struct sock_filter filter[N_FILTERS] = {
- [0] = BPF_STMT(BPF_LD | BPF_W | BPF_ABS, syscall_nr),
-
- [N_FILTERS - 2] = BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),
- [N_FILTERS - 1] = BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ERRNO | ENOSYS),
- };
-
- const struct sock_filter nop = BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0);
-
- for (i = 0; i < ARRAY_SIZE(syscalls); i++) {
- if (blocked_syscalls[i]) {
- const struct sock_filter block = BPF_JUMP(
- BPF_JMP | BPF_JEQ | BPF_K,
- syscalls[i].number,
- N_FILTERS - 3 - i, 0);
- filter[i + 1] = block;
- } else {
- filter[i + 1] = nop;
- }
+ if (strcmp(argv[1], "fallocate") == 0) {
+ errno = 0;
+ r = fallocate(-1, 0, 0, 0);
+ errx(EXIT_SUCCESS, "fallocate r=%d errno=%s", r, strerror(errno));
+ } else if (strcmp(argv[1], "exec") == 0) {
+ char *const cmd[] = {
+ "/bin/false",
+ NULL
+ };
+ execve(cmd[0], cmd, NULL);
+ err(EXIT_FAILURE, "exec failed");
+ } else if (strcmp(argv[1], "ioctl") == 0) {
+ r = ioctl(0, FIOCLEX);
+ errx(EXIT_SUCCESS, "ioctl r=%d errno=%s", r, strerror(errno));
}
- struct sock_fprog prog = {
- .len = ARRAY_SIZE(filter),
- .filter = filter,
- };
-
- if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))
- err(EXIT_NOTSUPP, "prctl(PR_SET_NO_NEW_PRIVS)");
-
- if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog))
- err(EXIT_NOTSUPP, "prctl(PR_SET_SECCOMP)");
-
- if (execvp(argv[optind], argv + optind))
- err(EXIT_NOTSUPP, "Could not exec");
+ errx(EXIT_FAILURE, "invalid mode %s", argv[1]);
}