]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
landlock: Factor out check_access_path()
authorMickaël Salaün <mic@digikod.net>
Wed, 8 Jan 2025 15:43:11 +0000 (16:43 +0100)
committerMickaël Salaün <mic@digikod.net>
Fri, 17 Jan 2025 18:05:33 +0000 (19:05 +0100)
Merge check_access_path() into current_check_access_path() and make
hook_path_mknod() use it.

Cc: Günther Noack <gnoack@google.com>
Link: https://lore.kernel.org/r/20250108154338.1129069-4-mic@digikod.net
Signed-off-by: Mickaël Salaün <mic@digikod.net>
security/landlock/fs.c

index f81d0335b8257579be24191b29be64a2a2cd76be..4023354dd8e368b343e54c6a2b417c421c8d040d 100644 (file)
@@ -908,28 +908,22 @@ jump_up:
        return allowed_parent1 && allowed_parent2;
 }
 
-static int check_access_path(const struct landlock_ruleset *const domain,
-                            const struct path *const path,
-                            access_mask_t access_request)
-{
-       layer_mask_t layer_masks[LANDLOCK_NUM_ACCESS_FS] = {};
-
-       access_request = landlock_init_layer_masks(
-               domain, access_request, &layer_masks, LANDLOCK_KEY_INODE);
-       if (is_access_to_paths_allowed(domain, path, access_request,
-                                      &layer_masks, NULL, 0, NULL, NULL))
-               return 0;
-       return -EACCES;
-}
-
 static int current_check_access_path(const struct path *const path,
-                                    const access_mask_t access_request)
+                                    access_mask_t access_request)
 {
        const struct landlock_ruleset *const dom = get_current_fs_domain();
+       layer_mask_t layer_masks[LANDLOCK_NUM_ACCESS_FS] = {};
 
        if (!dom)
                return 0;
-       return check_access_path(dom, path, access_request);
+
+       access_request = landlock_init_layer_masks(
+               dom, access_request, &layer_masks, LANDLOCK_KEY_INODE);
+       if (is_access_to_paths_allowed(dom, path, access_request, &layer_masks,
+                                      NULL, 0, NULL, NULL))
+               return 0;
+
+       return -EACCES;
 }
 
 static __attribute_const__ access_mask_t get_mode_access(const umode_t mode)
@@ -1413,11 +1407,7 @@ static int hook_path_mknod(const struct path *const dir,
                           struct dentry *const dentry, const umode_t mode,
                           const unsigned int dev)
 {
-       const struct landlock_ruleset *const dom = get_current_fs_domain();
-
-       if (!dom)
-               return 0;
-       return check_access_path(dom, dir, get_mode_access(mode));
+       return current_check_access_path(dir, get_mode_access(mode));
 }
 
 static int hook_path_symlink(const struct path *const dir,