Skip to content

Commit 924f440

Browse files
committed
landlock: Factor out check_access_path()
Merge check_access_path() into current_check_access_path() and make hook_path_mknod() use it. Cc: Günther Noack <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mickaël Salaün <[email protected]>
1 parent 0e4db4f commit 924f440

File tree

1 file changed

+11
-21
lines changed
  • security/landlock

1 file changed

+11
-21
lines changed

security/landlock/fs.c

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -908,28 +908,22 @@ static bool is_access_to_paths_allowed(
908908
return allowed_parent1 && allowed_parent2;
909909
}
910910

911-
static int check_access_path(const struct landlock_ruleset *const domain,
912-
const struct path *const path,
913-
access_mask_t access_request)
914-
{
915-
layer_mask_t layer_masks[LANDLOCK_NUM_ACCESS_FS] = {};
916-
917-
access_request = landlock_init_layer_masks(
918-
domain, access_request, &layer_masks, LANDLOCK_KEY_INODE);
919-
if (is_access_to_paths_allowed(domain, path, access_request,
920-
&layer_masks, NULL, 0, NULL, NULL))
921-
return 0;
922-
return -EACCES;
923-
}
924-
925911
static int current_check_access_path(const struct path *const path,
926-
const access_mask_t access_request)
912+
access_mask_t access_request)
927913
{
928914
const struct landlock_ruleset *const dom = get_current_fs_domain();
915+
layer_mask_t layer_masks[LANDLOCK_NUM_ACCESS_FS] = {};
929916

930917
if (!dom)
931918
return 0;
932-
return check_access_path(dom, path, access_request);
919+
920+
access_request = landlock_init_layer_masks(
921+
dom, access_request, &layer_masks, LANDLOCK_KEY_INODE);
922+
if (is_access_to_paths_allowed(dom, path, access_request, &layer_masks,
923+
NULL, 0, NULL, NULL))
924+
return 0;
925+
926+
return -EACCES;
933927
}
934928

935929
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,
14131407
struct dentry *const dentry, const umode_t mode,
14141408
const unsigned int dev)
14151409
{
1416-
const struct landlock_ruleset *const dom = get_current_fs_domain();
1417-
1418-
if (!dom)
1419-
return 0;
1420-
return check_access_path(dom, dir, get_mode_access(mode));
1410+
return current_check_access_path(dir, get_mode_access(mode));
14211411
}
14221412

14231413
static int hook_path_symlink(const struct path *const dir,

0 commit comments

Comments
 (0)