Blob


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