Blame


1 4c31de29 2021-09-19 op /*
2 4c31de29 2021-09-19 op * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
3 4c31de29 2021-09-19 op *
4 4c31de29 2021-09-19 op * Permission to use, copy, modify, and distribute this software for any
5 4c31de29 2021-09-19 op * purpose with or without fee is hereby granted, provided that the above
6 4c31de29 2021-09-19 op * copyright notice and this permission notice appear in all copies.
7 4c31de29 2021-09-19 op *
8 4c31de29 2021-09-19 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 4c31de29 2021-09-19 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 4c31de29 2021-09-19 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 4c31de29 2021-09-19 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 4c31de29 2021-09-19 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 4c31de29 2021-09-19 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 4c31de29 2021-09-19 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 4c31de29 2021-09-19 op */
16 4c31de29 2021-09-19 op
17 4c31de29 2021-09-19 op /*
18 4c31de29 2021-09-19 op * What's the deal with landlock? While distro with linux >= 5.13
19 4c31de29 2021-09-19 op * have the struct declarations, it seems that the glibc (or whatever)
20 4c31de29 2021-09-19 op * wrappers are missing. The sample landlock code provided by the
21 4c31de29 2021-09-19 op * authors includes these "shims" for the landlock API until libc
22 4c31de29 2021-09-19 op * provides them.
23 4c31de29 2021-09-19 op *
24 4c31de29 2021-09-19 op * Linux is such a mess sometimes. /rant
25 4c31de29 2021-09-19 op */
26 4c31de29 2021-09-19 op
27 4c31de29 2021-09-19 op #ifndef LANDLOCK_SHIM_H
28 4c31de29 2021-09-19 op #define LANDLOCK_SHIM_H
29 4c31de29 2021-09-19 op
30 4c31de29 2021-09-19 op #include <linux/landlock.h>
31 4c31de29 2021-09-19 op #include <linux/prctl.h>
32 4c31de29 2021-09-19 op
33 4c31de29 2021-09-19 op #include <sys/prctl.h>
34 4c31de29 2021-09-19 op #include <sys/stat.h>
35 4c31de29 2021-09-19 op #include <sys/syscall.h>
36 4c31de29 2021-09-19 op
37 4c31de29 2021-09-19 op #include <unistd.h>
38 4c31de29 2021-09-19 op
39 4c31de29 2021-09-19 op #ifndef landlock_create_ruleset
40 4c31de29 2021-09-19 op static inline int
41 4c31de29 2021-09-19 op landlock_create_ruleset(const struct landlock_ruleset_attr *attr, size_t size,
42 4c31de29 2021-09-19 op __u32 flags)
43 4c31de29 2021-09-19 op {
44 4c31de29 2021-09-19 op return syscall(__NR_landlock_create_ruleset, attr, size, flags);
45 4c31de29 2021-09-19 op }
46 4c31de29 2021-09-19 op #endif
47 4c31de29 2021-09-19 op
48 4c31de29 2021-09-19 op #ifndef landlock_add_rule
49 4c31de29 2021-09-19 op static inline int
50 4c31de29 2021-09-19 op landlock_add_rule(int ruleset_fd, enum landlock_rule_type type,
51 4c31de29 2021-09-19 op const void *attr, __u32 flags)
52 4c31de29 2021-09-19 op {
53 4c31de29 2021-09-19 op return syscall(__NR_landlock_add_rule, ruleset_fd, type, attr, flags);
54 4c31de29 2021-09-19 op }
55 4c31de29 2021-09-19 op #endif
56 4c31de29 2021-09-19 op
57 4c31de29 2021-09-19 op #ifndef landlock_restrict_self
58 4c31de29 2021-09-19 op static inline int
59 4c31de29 2021-09-19 op landlock_restrict_self(int ruleset_fd, __u32 flags)
60 4c31de29 2021-09-19 op {
61 4c31de29 2021-09-19 op return syscall(__NR_landlock_restrict_self, ruleset_fd, flags);
62 4c31de29 2021-09-19 op }
63 4c31de29 2021-09-19 op #endif
64 4c31de29 2021-09-19 op
65 4c31de29 2021-09-19 op #endif /* LANDLOCK_SHIM_H */