xref: /linux-6.15/include/uapi/linux/landlock.h (revision 6cc2df8e)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  * Landlock - User space API
4  *
5  * Copyright © 2017-2020 Mickaël Salaün <[email protected]>
6  * Copyright © 2018-2020 ANSSI
7  */
8 
9 #ifndef _UAPI_LINUX_LANDLOCK_H
10 #define _UAPI_LINUX_LANDLOCK_H
11 
12 #include <linux/types.h>
13 
14 /**
15  * struct landlock_ruleset_attr - Ruleset definition
16  *
17  * Argument of sys_landlock_create_ruleset().  This structure can grow in
18  * future versions.
19  */
20 struct landlock_ruleset_attr {
21 	/**
22 	 * @handled_access_fs: Bitmask of actions (cf. `Filesystem flags`_)
23 	 * that is handled by this ruleset and should then be forbidden if no
24 	 * rule explicitly allow them.  This is needed for backward
25 	 * compatibility reasons.
26 	 */
27 	__u64 handled_access_fs;
28 };
29 
30 /*
31  * sys_landlock_create_ruleset() flags:
32  *
33  * - %LANDLOCK_CREATE_RULESET_VERSION: Get the highest supported Landlock ABI
34  *   version.
35  */
36 /* clang-format off */
37 #define LANDLOCK_CREATE_RULESET_VERSION			(1U << 0)
38 /* clang-format on */
39 
40 /**
41  * enum landlock_rule_type - Landlock rule type
42  *
43  * Argument of sys_landlock_add_rule().
44  */
45 enum landlock_rule_type {
46 	/**
47 	 * @LANDLOCK_RULE_PATH_BENEATH: Type of a &struct
48 	 * landlock_path_beneath_attr .
49 	 */
50 	LANDLOCK_RULE_PATH_BENEATH = 1,
51 };
52 
53 /**
54  * struct landlock_path_beneath_attr - Path hierarchy definition
55  *
56  * Argument of sys_landlock_add_rule().
57  */
58 struct landlock_path_beneath_attr {
59 	/**
60 	 * @allowed_access: Bitmask of allowed actions for this file hierarchy
61 	 * (cf. `Filesystem flags`_).
62 	 */
63 	__u64 allowed_access;
64 	/**
65 	 * @parent_fd: File descriptor, open with ``O_PATH``, which identifies
66 	 * the parent directory of a file hierarchy, or just a file.
67 	 */
68 	__s32 parent_fd;
69 	/*
70 	 * This struct is packed to avoid trailing reserved members.
71 	 * Cf. security/landlock/syscalls.c:build_check_abi()
72 	 */
73 } __attribute__((packed));
74 
75 /**
76  * DOC: fs_access
77  *
78  * A set of actions on kernel objects may be defined by an attribute (e.g.
79  * &struct landlock_path_beneath_attr) including a bitmask of access.
80  *
81  * Filesystem flags
82  * ~~~~~~~~~~~~~~~~
83  *
84  * These flags enable to restrict a sandboxed process to a set of actions on
85  * files and directories.  Files or directories opened before the sandboxing
86  * are not subject to these restrictions.
87  *
88  * A file can only receive these access rights:
89  *
90  * - %LANDLOCK_ACCESS_FS_EXECUTE: Execute a file.
91  * - %LANDLOCK_ACCESS_FS_WRITE_FILE: Open a file with write access.
92  * - %LANDLOCK_ACCESS_FS_READ_FILE: Open a file with read access.
93  *
94  * A directory can receive access rights related to files or directories.  The
95  * following access right is applied to the directory itself, and the
96  * directories beneath it:
97  *
98  * - %LANDLOCK_ACCESS_FS_READ_DIR: Open a directory or list its content.
99  *
100  * However, the following access rights only apply to the content of a
101  * directory, not the directory itself:
102  *
103  * - %LANDLOCK_ACCESS_FS_REMOVE_DIR: Remove an empty directory or rename one.
104  * - %LANDLOCK_ACCESS_FS_REMOVE_FILE: Unlink (or rename) a file.
105  * - %LANDLOCK_ACCESS_FS_MAKE_CHAR: Create (or rename or link) a character
106  *   device.
107  * - %LANDLOCK_ACCESS_FS_MAKE_DIR: Create (or rename) a directory.
108  * - %LANDLOCK_ACCESS_FS_MAKE_REG: Create (or rename or link) a regular file.
109  * - %LANDLOCK_ACCESS_FS_MAKE_SOCK: Create (or rename or link) a UNIX domain
110  *   socket.
111  * - %LANDLOCK_ACCESS_FS_MAKE_FIFO: Create (or rename or link) a named pipe.
112  * - %LANDLOCK_ACCESS_FS_MAKE_BLOCK: Create (or rename or link) a block device.
113  * - %LANDLOCK_ACCESS_FS_MAKE_SYM: Create (or rename or link) a symbolic link.
114  *
115  * .. warning::
116  *
117  *   It is currently not possible to restrict some file-related actions
118  *   accessible through these syscall families: :manpage:`chdir(2)`,
119  *   :manpage:`truncate(2)`, :manpage:`stat(2)`, :manpage:`flock(2)`,
120  *   :manpage:`chmod(2)`, :manpage:`chown(2)`, :manpage:`setxattr(2)`,
121  *   :manpage:`utime(2)`, :manpage:`ioctl(2)`, :manpage:`fcntl(2)`,
122  *   :manpage:`access(2)`.
123  *   Future Landlock evolutions will enable to restrict them.
124  */
125 /* clang-format off */
126 #define LANDLOCK_ACCESS_FS_EXECUTE			(1ULL << 0)
127 #define LANDLOCK_ACCESS_FS_WRITE_FILE			(1ULL << 1)
128 #define LANDLOCK_ACCESS_FS_READ_FILE			(1ULL << 2)
129 #define LANDLOCK_ACCESS_FS_READ_DIR			(1ULL << 3)
130 #define LANDLOCK_ACCESS_FS_REMOVE_DIR			(1ULL << 4)
131 #define LANDLOCK_ACCESS_FS_REMOVE_FILE			(1ULL << 5)
132 #define LANDLOCK_ACCESS_FS_MAKE_CHAR			(1ULL << 6)
133 #define LANDLOCK_ACCESS_FS_MAKE_DIR			(1ULL << 7)
134 #define LANDLOCK_ACCESS_FS_MAKE_REG			(1ULL << 8)
135 #define LANDLOCK_ACCESS_FS_MAKE_SOCK			(1ULL << 9)
136 #define LANDLOCK_ACCESS_FS_MAKE_FIFO			(1ULL << 10)
137 #define LANDLOCK_ACCESS_FS_MAKE_BLOCK			(1ULL << 11)
138 #define LANDLOCK_ACCESS_FS_MAKE_SYM			(1ULL << 12)
139 /* clang-format on */
140 
141 #endif /* _UAPI_LINUX_LANDLOCK_H */
142