Blame SOURCES/0001-ecryptfs_rename-verify-that-lower-dentries-are-still.patch

Kmods SIG c540c3
From 74dd7c97ea2ab08b41925ab2f472db573accda89 Mon Sep 17 00:00:00 2001
Kmods SIG c540c3
From: Al Viro <viro@zeniv.linux.org.uk>
Kmods SIG c540c3
Date: Tue, 9 Oct 2018 23:32:41 -0400
Kmods SIG c540c3
Subject: [Backport 74dd7c97ea2a] ecryptfs_rename(): verify that lower dentries
Kmods SIG c540c3
 are still OK after lock_rename()
Kmods SIG c540c3
Kmods SIG c540c3
We get lower layer dentries, find their parents, do lock_rename() and
Kmods SIG c540c3
proceed to vfs_rename().  However, we do not check that dentries still
Kmods SIG c540c3
have the same parents and are not unlinked.  Need to check that...
Kmods SIG c540c3
Kmods SIG c540c3
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Kmods SIG c540c3
---
Kmods SIG c540c3
 src/inode.c | 11 ++++++++---
Kmods SIG c540c3
 1 file changed, 8 insertions(+), 3 deletions(-)
Kmods SIG c540c3
Kmods SIG c540c3
diff --git a/src/inode.c b/src/inode.c
Kmods SIG c540c3
index 49121e5a8de228acfb1ea126250e5ad94e4ec812..5c36ceecb5c12828ceb84a39d19c86b69713b937 100644
Kmods SIG c540c3
--- a/src/inode.c
Kmods SIG c540c3
+++ b/src/inode.c
Kmods SIG c540c3
@@ -593,11 +593,16 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry,
Kmods SIG c540c3
 	lower_new_dir_dentry = dget_parent(lower_new_dentry);
Kmods SIG c540c3
 	target_inode = d_inode(new_dentry);
Kmods SIG c540c3
 	trap = lock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
Kmods SIG c540c3
+	rc = -EINVAL;
Kmods SIG c540c3
+	if (lower_old_dentry->d_parent != lower_old_dir_dentry)
Kmods SIG c540c3
+		goto out_lock;
Kmods SIG c540c3
+	if (lower_new_dentry->d_parent != lower_new_dir_dentry)
Kmods SIG c540c3
+		goto out_lock;
Kmods SIG c540c3
+	if (d_unhashed(lower_old_dentry) || d_unhashed(lower_new_dentry))
Kmods SIG c540c3
+		goto out_lock;
Kmods SIG c540c3
 	/* source should not be ancestor of target */
Kmods SIG c540c3
-	if (trap == lower_old_dentry) {
Kmods SIG c540c3
-		rc = -EINVAL;
Kmods SIG c540c3
+	if (trap == lower_old_dentry)
Kmods SIG c540c3
 		goto out_lock;
Kmods SIG c540c3
-	}
Kmods SIG c540c3
 	/* target should not be ancestor of source */
Kmods SIG c540c3
 	if (trap == lower_new_dentry) {
Kmods SIG c540c3
 		rc = -ENOTEMPTY;
Kmods SIG c540c3
-- 
Kmods SIG c540c3
2.31.1
Kmods SIG c540c3