2 4d9d3093 2023-08-23 op * Copyright (c) 2023 Omar Polo <op@omarpolo.com>
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.
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.
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>
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,
27 4d9d3093 2023-08-23 op return syscall(__NR_landlock_create_ruleset, attr, size, flags);
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
40 4d9d3093 2023-08-23 op rfd = landlock_create_ruleset(&rsattr, sizeof(rsattr), 0);
41 4d9d3093 2023-08-23 op return rfd == -1;