path: root/security/tomoyo/tomoyo.c
diff options
authorMickaël Salaün <>2022-05-06 18:10:56 +0200
committerMickaël Salaün <>2022-05-23 13:27:58 +0200
commit100f59d964050020285f0c8264ce520f0c406c13 (patch)
tree037d009604dce35f82e15cdc324258d39dbaed9b /security/tomoyo/tomoyo.c
parent9da82b20fde95814af721a2a7b1796a5b4a3d78e (diff)
LSM: Remove double path_rename hook calls for RENAME_EXCHANGE
In order to be able to identify a file exchange with renameat2(2) and RENAME_EXCHANGE, which will be useful for Landlock [1], propagate the rename flags to LSMs. This may also improve performance because of the switch from two set of LSM hook calls to only one, and because LSMs using this hook may optimize the double check (e.g. only one lock, reduce the number of path walks). AppArmor, Landlock and Tomoyo are updated to leverage this change. This should not change the current behavior (same check order), except (different level of) speed boosts. [1] Cc: James Morris <> Cc: Kentaro Takeda <> Cc: Serge E. Hallyn <> Acked-by: John Johansen <> Acked-by: Tetsuo Handa <> Reviewed-by: Paul Moore <> Signed-off-by: Mickaël Salaün <> Link:
Diffstat (limited to 'security/tomoyo/tomoyo.c')
1 files changed, 10 insertions, 1 deletions
diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
index b6a31901f289..71e82d855ebf 100644
--- a/security/tomoyo/tomoyo.c
+++ b/security/tomoyo/tomoyo.c
@@ -264,17 +264,26 @@ static int tomoyo_path_link(struct dentry *old_dentry, const struct path *new_di
* @old_dentry: Pointer to "struct dentry".
* @new_parent: Pointer to "struct path".
* @new_dentry: Pointer to "struct dentry".
+ * @flags: Rename options.
* Returns 0 on success, negative value otherwise.
static int tomoyo_path_rename(const struct path *old_parent,
struct dentry *old_dentry,
const struct path *new_parent,
- struct dentry *new_dentry)
+ struct dentry *new_dentry,
+ const unsigned int flags)
struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
+ if (flags & RENAME_EXCHANGE) {
+ const int err = tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path2,
+ &path1);
+ if (err)
+ return err;
+ }
return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);