-
Notifications
You must be signed in to change notification settings - Fork 6
/
test-landlock.c
37 lines (33 loc) · 928 Bytes
/
test-landlock.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <linux/landlock.h>
#include <linux/prctl.h>
#include <stdlib.h>
#include <sys/prctl.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <stdint.h>
#ifndef landlock_create_ruleset
static inline int landlock_create_ruleset(const struct landlock_ruleset_attr *const attr,
const size_t size, const __u32 flags)
{
return syscall(__NR_landlock_create_ruleset, attr, size, flags);
}
#endif
#ifndef landlock_restrict_self
static inline int landlock_restrict_self(const int ruleset_fd,
const __u32 flags)
{
return syscall(__NR_landlock_restrict_self, ruleset_fd, flags);
}
#endif
int
main(void)
{
uint64_t mask = LANDLOCK_ACCESS_FS_READ_FILE | LANDLOCK_ACCESS_FS_WRITE_FILE;
struct landlock_ruleset_attr rules = {
.handled_access_fs = mask
};
int fd = landlock_create_ruleset(&rules, sizeof(rules), 0);
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))
return 1;
return landlock_restrict_self(fd, 0) ? 1 : 0;
}