Merge branches 'acpi-battery', 'acpi-video' and 'acpi-misc'
[sfrench/cifs-2.6.git] / security / landlock / syscalls.c
index 2fde978bf8caceea43a7da13238ec862f03faf3a..735a0865ea113512488cc1ec988c0690c3bc0bd6 100644 (file)
@@ -129,7 +129,7 @@ static const struct file_operations ruleset_fops = {
        .write = fop_dummy_write,
 };
 
-#define LANDLOCK_ABI_VERSION 1
+#define LANDLOCK_ABI_VERSION 2
 
 /**
  * sys_landlock_create_ruleset - Create a new ruleset
@@ -292,14 +292,13 @@ out_fdput:
  *
  * - EOPNOTSUPP: Landlock is supported by the kernel but disabled at boot time;
  * - EINVAL: @flags is not 0, or inconsistent access in the rule (i.e.
- *   &landlock_path_beneath_attr.allowed_access is not a subset of the rule's
- *   accesses);
+ *   &landlock_path_beneath_attr.allowed_access is not a subset of the
+ *   ruleset handled accesses);
  * - ENOMSG: Empty accesses (e.g. &landlock_path_beneath_attr.allowed_access);
  * - EBADF: @ruleset_fd is not a file descriptor for the current thread, or a
  *   member of @rule_attr is not a file descriptor as expected;
  * - EBADFD: @ruleset_fd is not a ruleset file descriptor, or a member of
- *   @rule_attr is not the expected file descriptor type (e.g. file open
- *   without O_PATH);
+ *   @rule_attr is not the expected file descriptor type;
  * - EPERM: @ruleset_fd has no write access to the underlying ruleset;
  * - EFAULT: @rule_attr inconsistency.
  */
@@ -319,20 +318,24 @@ SYSCALL_DEFINE4(landlock_add_rule, const int, ruleset_fd,
        if (flags)
                return -EINVAL;
 
-       if (rule_type != LANDLOCK_RULE_PATH_BENEATH)
-               return -EINVAL;
-
-       /* Copies raw user space buffer, only one type for now. */
-       res = copy_from_user(&path_beneath_attr, rule_attr,
-                            sizeof(path_beneath_attr));
-       if (res)
-               return -EFAULT;
-
        /* Gets and checks the ruleset. */
        ruleset = get_ruleset_from_fd(ruleset_fd, FMODE_CAN_WRITE);
        if (IS_ERR(ruleset))
                return PTR_ERR(ruleset);
 
+       if (rule_type != LANDLOCK_RULE_PATH_BENEATH) {
+               err = -EINVAL;
+               goto out_put_ruleset;
+       }
+
+       /* Copies raw user space buffer, only one type for now. */
+       res = copy_from_user(&path_beneath_attr, rule_attr,
+                            sizeof(path_beneath_attr));
+       if (res) {
+               err = -EFAULT;
+               goto out_put_ruleset;
+       }
+
        /*
         * Informs about useless rule: empty allowed_access (i.e. deny rules)
         * are ignored in path walks.
@@ -402,10 +405,6 @@ SYSCALL_DEFINE2(landlock_restrict_self, const int, ruleset_fd, const __u32,
        if (!landlock_initialized)
                return -EOPNOTSUPP;
 
-       /* No flag for now. */
-       if (flags)
-               return -EINVAL;
-
        /*
         * Similar checks as for seccomp(2), except that an -EPERM may be
         * returned.
@@ -414,6 +413,10 @@ SYSCALL_DEFINE2(landlock_restrict_self, const int, ruleset_fd, const __u32,
            !ns_capable_noaudit(current_user_ns(), CAP_SYS_ADMIN))
                return -EPERM;
 
+       /* No flag for now. */
+       if (flags)
+               return -EINVAL;
+
        /* Gets and checks the ruleset. */
        ruleset = get_ruleset_from_fd(ruleset_fd, FMODE_CAN_READ);
        if (IS_ERR(ruleset))