1 /* SPDX-License-Identifier: GPL-2.0 */
2 #include <linux/compiler.h>
3 #include <linux/types.h>
7 /* This workload was initially added to test enum augmentation with BTF in perf
8 * trace because its the only syscall that has an enum argument. Since it is
9 * a recent addition to the Linux kernel (at the time of the introduction of this
10 * 'perf test' workload) we just add the required types and defines here instead
11 * of including linux/landlock, that isn't available in older systems.
13 * We are not interested in the the result of the syscall, just in intercepting
17 #ifndef __NR_landlock_add_rule
18 #define __NR_landlock_add_rule 445
21 #ifndef LANDLOCK_ACCESS_FS_READ_FILE
22 #define LANDLOCK_ACCESS_FS_READ_FILE (1ULL << 2)
24 #define LANDLOCK_RULE_PATH_BENEATH 1
26 struct landlock_path_beneath_attr
{
32 #ifndef LANDLOCK_ACCESS_NET_CONNECT_TCP
33 #define LANDLOCK_ACCESS_NET_CONNECT_TCP (1ULL << 1)
35 #define LANDLOCK_RULE_NET_PORT 2
37 struct landlock_net_port_attr
{
43 static int landlock(int argc __maybe_unused
, const char **argv __maybe_unused
)
45 int fd
= 11, flags
= 45;
47 struct landlock_path_beneath_attr path_beneath_attr
= {
48 .allowed_access
= LANDLOCK_ACCESS_FS_READ_FILE
,
52 struct landlock_net_port_attr net_port_attr
= {
54 .allowed_access
= LANDLOCK_ACCESS_NET_CONNECT_TCP
,
57 syscall(__NR_landlock_add_rule
, fd
, LANDLOCK_RULE_PATH_BENEATH
,
58 &path_beneath_attr
, flags
);
60 syscall(__NR_landlock_add_rule
, fd
, LANDLOCK_RULE_NET_PORT
,
61 &net_port_attr
, flags
);
66 DEFINE_WORKLOAD(landlock
);