Thread (44 messages) 44 messages, 4 authors, 2021-03-25

Re: [PATCH v30 08/12] landlock: Add syscall implementations

From: Mickaël Salaün <mic@digikod.net>
Date: 2021-03-24 15:04:08
Also in: linux-api, linux-arch, linux-fsdevel, linux-kselftest, linux-security-module, lkml

On 19/03/2021 22:53, Mickaël Salaün wrote:
On 19/03/2021 20:06, Kees Cook wrote:
quoted
On Tue, Mar 16, 2021 at 09:42:48PM +0100, Mickaël Salaün wrote:
quoted
From: Mickaël Salaün <redacted>
[...]
quoted
quoted
+/**
+ * sys_landlock_create_ruleset - Create a new ruleset
+ *
+ * @attr: Pointer to a &struct landlock_ruleset_attr identifying the scope of
+ *        the new ruleset.
+ * @size: Size of the pointed &struct landlock_ruleset_attr (needed for
+ *        backward and forward compatibility).
+ * @flags: Must be 0.
+ *
+ * This system call enables to create a new Landlock ruleset, and returns the
+ * related file descriptor on success.
+ *
+ * Possible returned errors are:
+ *
+ * - EOPNOTSUPP: Landlock is supported by the kernel but disabled at boot time;
+ * - EINVAL: @flags is not 0, or unknown access, or too small @size;
+ * - E2BIG or EFAULT: @attr or @size inconsistencies;
+ * - ENOMSG: empty &landlock_ruleset_attr.handled_access_fs.
+ */
+SYSCALL_DEFINE3(landlock_create_ruleset,
+		const struct landlock_ruleset_attr __user *const, attr,
+		const size_t, size, const __u32, flags)
+{
+	struct landlock_ruleset_attr ruleset_attr;
+	struct landlock_ruleset *ruleset;
+	int err, ruleset_fd;
+
+	/* Build-time checks. */
+	build_check_abi();
+
+	if (!landlock_initialized)
+		return -EOPNOTSUPP;
+
+	/* No flag for now. */
+	if (flags)
+		return -EINVAL;
+
+	/* Copies raw user space buffer. */
+	err = copy_min_struct_from_user(&ruleset_attr, sizeof(ruleset_attr),
+			offsetofend(typeof(ruleset_attr), handled_access_fs),
The use of offsetofend() here appears to be kind of the "V1", "V2", ...
sizes used in other extensible syscall implementations?
ruleset_attr is an extensible argument.
offsetofen() is used to set the minimum size of a valid argument. This
code will then not change with future extended ruleset_attr.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help