From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
To: hch@infradead.org, viro@zeniv.linux.org.uk
Cc: linux-fsdevel@vger.kernel.org,
"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>,
Sage Weil <sage@newdream.net>, Miklos Szeredi <mszeredi@suse.cz>
Subject: [PATCH] vfs: Don't rehash the dentry on successfull deletion
Date: Wed, 16 Feb 2011 16:44:46 +0530 [thread overview]
Message-ID: <1297854886-2672-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> (raw)
vfs_rename_dir() doesn't properly account for filesystems with
FS_RENAME_DOES_D_MOVE. If new_dentry has a target inode attached, it
unhashes the new_dentry prior to the rename() iop and rehashes it after,
but doesn't account for the possibility that rename() may have swapped
{old,new}_dentry. For FS_RENAME_DOES_D_MOVE filesystems, it rehashes
new_dentry (now the old renamed-from name, which d_move() expected to go
away), such that a subsequent lookup will find it... and the overwritte
target inode.
To correct this call d_rehash only in case of error or in if the
file systems doesn't do d_move itself.
Based on the original patch by Sage Weil <sage@newdream.net>
http://kerneltrap.org/mailarchive/linux-fsdevel/2008/4/18/1498534
Cc: Zach Brown <zach.brown@oracle.com
Cc: Sage Weil <sage@newdream.net>
Cc: Miklos Szeredi <mszeredi@suse.cz>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
fs/namei.c | 11 +++++++++--
1 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/fs/namei.c b/fs/namei.c
index 7d77f24..5631ccf 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -3259,8 +3259,15 @@ static int vfs_rename_dir(struct inode *old_dir, struct dentry *old_dentry,
dont_mount(new_dentry);
}
mutex_unlock(&target->i_mutex);
- if (d_unhashed(new_dentry))
- d_rehash(new_dentry);
+ /*
+ * if rename callback returned success and we have
+ * FS_RENAME_DOES_D_MOVE set, then don't do the
+ * rehash.
+ */
+ if (error ||
+ !(old_dir->i_sb->s_type->fs_flags & FS_RENAME_DOES_D_MOVE))
+ if (d_unhashed(new_dentry))
+ d_rehash(new_dentry);
dput(new_dentry);
}
if (!error)
--
1.7.1
reply other threads:[~2011-02-16 11:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1297854886-2672-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com \
--to=aneesh.kumar@linux.vnet.ibm.com \
--cc=hch@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=mszeredi@suse.cz \
--cc=sage@newdream.net \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).