[PATCH] Fix vfs_unlink issue introduced by link/unlink race correction

Linux Kernel Mailing List <[email protected]> Fri, 26 May 2006 19:59:02 GMT
Newsgroups gmane.linux.kernel.commits.2-4
Message-ID <[email protected]>
commit efc95599c0261dd7ab3a1d9071024ca140b4c644
tree c5d74c708c914f0980060aa412ae88704ee63275
parent 6601095e2de35f00325a33c8be6b548f81fe76d5
author Marcelo Tosatti <[email protected]> Fri, 26 May 2006 22:41:06 -0300
committer Marcelo Tosatti <[email protected]> Fri, 26 May 2006 22:41:06 -0300

[PATCH] Fix vfs_unlink issue introduced by link/unlink race correction

may_delete() should be called before attempting to grab victim's
i_zombie.

Signed-off-by: Marcelo Tosatti <[email protected]>

 fs/namei.c |   25 +++++++++++++------------
 1 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index 48bd26c..42cce98 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1479,19 +1479,20 @@ int vfs_unlink(struct inode *dir, struct
 {
 	int error;
 
-	double_down(&dir->i_zombie, &dentry->d_inode->i_zombie);
 	error = may_delete(dir, dentry, 0);
-	if (!error) {
-		error = -EPERM;
-		if (dir->i_op && dir->i_op->unlink) {
-			DQUOT_INIT(dir);
-			if (d_mountpoint(dentry))
-				error = -EBUSY;
-			else {
-				lock_kernel();
-				error = dir->i_op->unlink(dir, dentry);
-				unlock_kernel();
-			}
+	if (error)
+		return error;
+
+	double_down(&dir->i_zombie, &dentry->d_inode->i_zombie);
+	error = -EPERM;
+	if (dir->i_op && dir->i_op->unlink) {
+		DQUOT_INIT(dir);
+		if (d_mountpoint(dentry))
+			error = -EBUSY;
+		else {
+			lock_kernel();
+			error = dir->i_op->unlink(dir, dentry);
+			unlock_kernel();
 		}
 	}
 	double_up(&dir->i_zombie, &dentry->d_inode->i_zombie);