1 /*
2 * Check decoding of seccomp SECCOMP_GET_ACTION_AVAIL.
3 *
4 * Copyright (c) 2017-2021 Dmitry V. Levin <ldv@strace.io>
5 * All rights reserved.
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10 #include "tests.h"
11 #include "scno.h"
12
13 #include <stdio.h>
14 #include <stdint.h>
15 #include <unistd.h>
16
17 #include <linux/seccomp.h>
18
19 static const char *errstr;
20
21 static long
22 k_seccomp(const kernel_ulong_t op, const kernel_ulong_t flags,
23 const kernel_ulong_t args)
24 {
25 const long rc = syscall(__NR_seccomp, op, flags, args);
26 errstr = sprintrc(rc);
27 return rc;
28 }
29
30 int
31 main(void)
32 {
33 TAIL_ALLOC_OBJECT_CONST_PTR(uint32_t, act);
34 kernel_ulong_t op = (kernel_ulong_t) 0xfacefeed00000000ULL
35 | SECCOMP_GET_ACTION_AVAIL;
36 kernel_ulong_t flags = (kernel_ulong_t) 0xdeadbeef00000000ULL;
37
38 struct {
39 uint32_t val;
40 const char *str;
41 } actions [] = {
42 { 0, "SECCOMP_RET_KILL_THREAD" },
43 { ARG_STR(SECCOMP_RET_KILL_PROCESS) },
44 { ARG_STR(SECCOMP_RET_TRAP) },
45 { ARG_STR(SECCOMP_RET_ERRNO) },
46 { ARG_STR(SECCOMP_RET_USER_NOTIF) },
47 { ARG_STR(SECCOMP_RET_TRACE) },
48 { ARG_STR(SECCOMP_RET_LOG) },
49 { ARG_STR(SECCOMP_RET_ALLOW) },
50 { 0xffffffff, "0xffffffff /* SECCOMP_RET_??? */" }
51 };
52
53 for (unsigned int i = 0; i < ARRAY_SIZE(actions); ++i) {
54 *act = actions[i].val;
55 k_seccomp(op, flags, (uintptr_t) act);
56 printf("seccomp(SECCOMP_GET_ACTION_AVAIL, 0, [%s]) = %s\n",
57 actions[i].str, errstr);
58 }
59
60 *act = actions[0].val;
61
62 k_seccomp(op, flags, (uintptr_t) (act + 1));
63 printf("seccomp(SECCOMP_GET_ACTION_AVAIL, 0, %p) = %s\n",
64 act + 1, errstr);
65
66 if (F8ILL_KULONG_SUPPORTED) {
67 k_seccomp(op, flags, f8ill_ptr_to_kulong(act));
68 printf("seccomp(SECCOMP_GET_ACTION_AVAIL, 0, %#jx) = %s\n",
69 (uintmax_t) f8ill_ptr_to_kulong(act), errstr);
70 }
71
72 flags |= 0xcafef00d;
73 k_seccomp(op, flags, 0);
74 printf("seccomp(SECCOMP_GET_ACTION_AVAIL, %#x, NULL) = %s\n",
75 (unsigned int) flags, errstr);
76
77 puts("+++ exited with 0 +++");
78 return 0;
79 }