arm64: mte: change ASYNC and SYNC TCF settings into bitfields
[linux-2.6-microblaze.git] / include / uapi / linux / landlock.h
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 <mic@digikod.net>
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 #define LANDLOCK_CREATE_RULESET_VERSION                 (1U << 0)
37
38 /**
39  * enum landlock_rule_type - Landlock rule type
40  *
41  * Argument of sys_landlock_add_rule().
42  */
43 enum landlock_rule_type {
44         /**
45          * @LANDLOCK_RULE_PATH_BENEATH: Type of a &struct
46          * landlock_path_beneath_attr .
47          */
48         LANDLOCK_RULE_PATH_BENEATH = 1,
49 };
50
51 /**
52  * struct landlock_path_beneath_attr - Path hierarchy definition
53  *
54  * Argument of sys_landlock_add_rule().
55  */
56 struct landlock_path_beneath_attr {
57         /**
58          * @allowed_access: Bitmask of allowed actions for this file hierarchy
59          * (cf. `Filesystem flags`_).
60          */
61         __u64 allowed_access;
62         /**
63          * @parent_fd: File descriptor, open with ``O_PATH``, which identifies
64          * the parent directory of a file hierarchy, or just a file.
65          */
66         __s32 parent_fd;
67         /*
68          * This struct is packed to avoid trailing reserved members.
69          * Cf. security/landlock/syscalls.c:build_check_abi()
70          */
71 } __attribute__((packed));
72
73 /**
74  * DOC: fs_access
75  *
76  * A set of actions on kernel objects may be defined by an attribute (e.g.
77  * &struct landlock_path_beneath_attr) including a bitmask of access.
78  *
79  * Filesystem flags
80  * ~~~~~~~~~~~~~~~~
81  *
82  * These flags enable to restrict a sandboxed process to a set of actions on
83  * files and directories.  Files or directories opened before the sandboxing
84  * are not subject to these restrictions.
85  *
86  * A file can only receive these access rights:
87  *
88  * - %LANDLOCK_ACCESS_FS_EXECUTE: Execute a file.
89  * - %LANDLOCK_ACCESS_FS_WRITE_FILE: Open a file with write access.
90  * - %LANDLOCK_ACCESS_FS_READ_FILE: Open a file with read access.
91  *
92  * A directory can receive access rights related to files or directories.  The
93  * following access right is applied to the directory itself, and the
94  * directories beneath it:
95  *
96  * - %LANDLOCK_ACCESS_FS_READ_DIR: Open a directory or list its content.
97  *
98  * However, the following access rights only apply to the content of a
99  * directory, not the directory itself:
100  *
101  * - %LANDLOCK_ACCESS_FS_REMOVE_DIR: Remove an empty directory or rename one.
102  * - %LANDLOCK_ACCESS_FS_REMOVE_FILE: Unlink (or rename) a file.
103  * - %LANDLOCK_ACCESS_FS_MAKE_CHAR: Create (or rename or link) a character
104  *   device.
105  * - %LANDLOCK_ACCESS_FS_MAKE_DIR: Create (or rename) a directory.
106  * - %LANDLOCK_ACCESS_FS_MAKE_REG: Create (or rename or link) a regular file.
107  * - %LANDLOCK_ACCESS_FS_MAKE_SOCK: Create (or rename or link) a UNIX domain
108  *   socket.
109  * - %LANDLOCK_ACCESS_FS_MAKE_FIFO: Create (or rename or link) a named pipe.
110  * - %LANDLOCK_ACCESS_FS_MAKE_BLOCK: Create (or rename or link) a block device.
111  * - %LANDLOCK_ACCESS_FS_MAKE_SYM: Create (or rename or link) a symbolic link.
112  *
113  * .. warning::
114  *
115  *   It is currently not possible to restrict some file-related actions
116  *   accessible through these syscall families: :manpage:`chdir(2)`,
117  *   :manpage:`truncate(2)`, :manpage:`stat(2)`, :manpage:`flock(2)`,
118  *   :manpage:`chmod(2)`, :manpage:`chown(2)`, :manpage:`setxattr(2)`,
119  *   :manpage:`utime(2)`, :manpage:`ioctl(2)`, :manpage:`fcntl(2)`,
120  *   :manpage:`access(2)`.
121  *   Future Landlock evolutions will enable to restrict them.
122  */
123 #define LANDLOCK_ACCESS_FS_EXECUTE                      (1ULL << 0)
124 #define LANDLOCK_ACCESS_FS_WRITE_FILE                   (1ULL << 1)
125 #define LANDLOCK_ACCESS_FS_READ_FILE                    (1ULL << 2)
126 #define LANDLOCK_ACCESS_FS_READ_DIR                     (1ULL << 3)
127 #define LANDLOCK_ACCESS_FS_REMOVE_DIR                   (1ULL << 4)
128 #define LANDLOCK_ACCESS_FS_REMOVE_FILE                  (1ULL << 5)
129 #define LANDLOCK_ACCESS_FS_MAKE_CHAR                    (1ULL << 6)
130 #define LANDLOCK_ACCESS_FS_MAKE_DIR                     (1ULL << 7)
131 #define LANDLOCK_ACCESS_FS_MAKE_REG                     (1ULL << 8)
132 #define LANDLOCK_ACCESS_FS_MAKE_SOCK                    (1ULL << 9)
133 #define LANDLOCK_ACCESS_FS_MAKE_FIFO                    (1ULL << 10)
134 #define LANDLOCK_ACCESS_FS_MAKE_BLOCK                   (1ULL << 11)
135 #define LANDLOCK_ACCESS_FS_MAKE_SYM                     (1ULL << 12)
136
137 #endif /* _UAPI_LINUX_LANDLOCK_H */