diff options
author | Xue jiufei <xuejiufei@huawei.com> | 2014-02-10 17:25:54 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-02-10 19:01:43 -0500 |
commit | 0e048316ff577e12c748e2d0a2e4f0f7b006654d (patch) | |
tree | f37ad130de45bf55b3cb43fcb8e5e06a924a41d8 /fs/ocfs2/namei.c | |
parent | c7d2cbc364b2a237b0ed1bdd7cbf8a24c8a89dfd (diff) |
ocfs2: check existence of old dentry in ocfs2_link()
System call linkat first calls user_path_at(), check the existence of
old dentry, and then calls vfs_link()->ocfs2_link() to do the actual
work. There may exist a race when Node A create a hard link for file
while node B rm it.
Node A Node B
user_path_at()
->ocfs2_lookup(),
find old dentry exist
rm file, add inode say inodeA
to orphan_dir
call ocfs2_link(),create a
hard link for inodeA.
rm the link, add inodeA to orphan_dir
again
When orphan_scan work start, it calls ocfs2_queue_orphans() to do the
main work. It first tranverses entrys in orphan_dir, linking all inodes
in this orphan_dir to a list look like this:
inodeA->inodeB->...->inodeA
When tranvering this list, it will fall into loop, calling iput() again
and again. And finally trigger BUG_ON(inode->i_state & I_CLEAR).
Signed-off-by: joyce <xuejiufei@huawei.com>
Reviewed-by: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <jlbec@evilplan.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/ocfs2/namei.c')
-rw-r--r-- | fs/ocfs2/namei.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c index f4d609be9400..3683643f3f0e 100644 --- a/fs/ocfs2/namei.c +++ b/fs/ocfs2/namei.c | |||
@@ -664,6 +664,7 @@ static int ocfs2_link(struct dentry *old_dentry, | |||
664 | struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); | 664 | struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); |
665 | struct ocfs2_dir_lookup_result lookup = { NULL, }; | 665 | struct ocfs2_dir_lookup_result lookup = { NULL, }; |
666 | sigset_t oldset; | 666 | sigset_t oldset; |
667 | u64 old_de_ino; | ||
667 | 668 | ||
668 | trace_ocfs2_link((unsigned long long)OCFS2_I(inode)->ip_blkno, | 669 | trace_ocfs2_link((unsigned long long)OCFS2_I(inode)->ip_blkno, |
669 | old_dentry->d_name.len, old_dentry->d_name.name, | 670 | old_dentry->d_name.len, old_dentry->d_name.name, |
@@ -686,6 +687,22 @@ static int ocfs2_link(struct dentry *old_dentry, | |||
686 | goto out; | 687 | goto out; |
687 | } | 688 | } |
688 | 689 | ||
690 | err = ocfs2_lookup_ino_from_name(dir, old_dentry->d_name.name, | ||
691 | old_dentry->d_name.len, &old_de_ino); | ||
692 | if (err) { | ||
693 | err = -ENOENT; | ||
694 | goto out; | ||
695 | } | ||
696 | |||
697 | /* | ||
698 | * Check whether another node removed the source inode while we | ||
699 | * were in the vfs. | ||
700 | */ | ||
701 | if (old_de_ino != OCFS2_I(inode)->ip_blkno) { | ||
702 | err = -ENOENT; | ||
703 | goto out; | ||
704 | } | ||
705 | |||
689 | err = ocfs2_check_dir_for_entry(dir, dentry->d_name.name, | 706 | err = ocfs2_check_dir_for_entry(dir, dentry->d_name.name, |
690 | dentry->d_name.len); | 707 | dentry->d_name.len); |
691 | if (err) | 708 | if (err) |