Blame


1 4d9d3093 2023-08-23 op /*
2 4d9d3093 2023-08-23 op * Copyright (c) 2023 Omar Polo <op@omarpolo.com>
3 4d9d3093 2023-08-23 op *
4 4d9d3093 2023-08-23 op * Permission to use, copy, modify, and distribute this software for any
5 4d9d3093 2023-08-23 op * purpose with or without fee is hereby granted, provided that the above
6 4d9d3093 2023-08-23 op * copyright notice and this permission notice appear in all copies.
7 4d9d3093 2023-08-23 op *
8 4d9d3093 2023-08-23 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 4d9d3093 2023-08-23 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 4d9d3093 2023-08-23 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 4d9d3093 2023-08-23 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 4d9d3093 2023-08-23 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 4d9d3093 2023-08-23 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 4d9d3093 2023-08-23 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 4d9d3093 2023-08-23 op */
16 4d9d3093 2023-08-23 op
17 4d9d3093 2023-08-23 op #include <linux/landlock.h>
18 4d9d3093 2023-08-23 op #include <sys/prctl.h>
19 4d9d3093 2023-08-23 op #include <sys/stat.h>
20 4d9d3093 2023-08-23 op #include <sys/syscall.h>
21 4d9d3093 2023-08-23 op
22 4d9d3093 2023-08-23 op #ifndef landlock_create_ruleset
23 4d9d3093 2023-08-23 op static inline int
24 4d9d3093 2023-08-23 op landlock_create_ruleset(const struct landlock_ruleset_attr *attr, size_t size,
25 4d9d3093 2023-08-23 op __u32 flags)
26 4d9d3093 2023-08-23 op {
27 4d9d3093 2023-08-23 op return syscall(__NR_landlock_create_ruleset, attr, size, flags);
28 4d9d3093 2023-08-23 op }
29 4d9d3093 2023-08-23 op #endif
30 4d9d3093 2023-08-23 op
31 4d9d3093 2023-08-23 op int
32 4d9d3093 2023-08-23 op main(void)
33 4d9d3093 2023-08-23 op {
34 4d9d3093 2023-08-23 op int rfd;
35 4d9d3093 2023-08-23 op const struct landlock_ruleset_attr rsattr = {
36 4d9d3093 2023-08-23 op .handled_access_fs = LANDLOCK_ACCESS_FS_READ_FILE |
37 4d9d3093 2023-08-23 op LANDLOCK_ACCESS_FS_READ_DIR
38 4d9d3093 2023-08-23 op };
39 4d9d3093 2023-08-23 op
40 4d9d3093 2023-08-23 op rfd = landlock_create_ruleset(&rsattr, sizeof(rsattr), 0);
41 4d9d3093 2023-08-23 op return rfd == -1;
42 4d9d3093 2023-08-23 op }