From bed3bcd2ed4a5081a0cfd26d511a04e7504f2c23 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Sun, 16 Jul 2023 16:52:24 +0200 Subject: [PATCH] 5.4-stable patches added patches: fs-no-need-to-check-source.patch --- queue-5.4/fs-no-need-to-check-source.patch | 45 ++++++++++++++++++++++ queue-5.4/series | 1 + 2 files changed, 46 insertions(+) create mode 100644 queue-5.4/fs-no-need-to-check-source.patch diff --git a/queue-5.4/fs-no-need-to-check-source.patch b/queue-5.4/fs-no-need-to-check-source.patch new file mode 100644 index 00000000000..118ada4ab58 --- /dev/null +++ b/queue-5.4/fs-no-need-to-check-source.patch @@ -0,0 +1,45 @@ +From 66d8fc0539b0d49941f313c9509a8384e4245ac1 Mon Sep 17 00:00:00 2001 +From: Jan Kara +Date: Mon, 3 Jul 2023 16:49:11 +0200 +Subject: fs: no need to check source + +From: Jan Kara + +commit 66d8fc0539b0d49941f313c9509a8384e4245ac1 upstream. + +The @source inode must be valid. It is even checked via IS_SWAPFILE() +above making it pretty clear. So no need to check it when we unlock. + +What doesn't need to exist is the @target inode. The lock_two_inodes() +helper currently swaps the @inode1 and @inode2 arguments if @inode1 is +NULL to have consistent lock class usage. However, we know that at least +for vfs_rename() that @inode1 is @source and thus is never NULL as per +above. We also know that @source is a different inode than @target as +that is checked right at the beginning of vfs_rename(). So we know that +@source is valid and locked and that @target is locked. So drop the +check whether @source is non-NULL. + +Fixes: 28eceeda130f ("fs: Lock moved directories") +Reported-by: kernel test robot +Reported-by: Dan Carpenter +Closes: https://lore.kernel.org/r/202307030026.9sE2pk2x-lkp@intel.com +Message-Id: <20230703-vfs-rename-source-v1-1-37eebb29b65b@kernel.org> +[brauner: use commit message from patch I sent concurrently] +Signed-off-by: Christian Brauner +Signed-off-by: Greg Kroah-Hartman +--- + fs/namei.c | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +--- a/fs/namei.c ++++ b/fs/namei.c +@@ -4497,8 +4497,7 @@ int vfs_rename(struct inode *old_dir, st + d_exchange(old_dentry, new_dentry); + } + out: +- if (source) +- inode_unlock(source); ++ inode_unlock(source); + if (target) + inode_unlock(target); + dput(new_dentry); diff --git a/queue-5.4/series b/queue-5.4/series index 6f1ab6fda33..38ab0be551d 100644 --- a/queue-5.4/series +++ b/queue-5.4/series @@ -177,3 +177,4 @@ fs-lock-moved-directories.patch btrfs-fix-race-when-deleting-quota-root-from-the-dirty-cow-roots-list.patch asoc-mediatek-mt8173-fix-irq-error-path.patch arm-orion5x-fix-d2net-gpio-initialization.patch +fs-no-need-to-check-source.patch -- 2.47.3