* [Ocfs2-devel] [PATCH V2] ocfs2: Check existence of old dentry in ocfs2_link()
@ 2014-02-08 2:16 Xue jiufei
2014-02-10 21:47 ` Mark Fasheh
0 siblings, 1 reply; 2+ messages in thread
From: Xue jiufei @ 2014-02-08 2:16 UTC (permalink / raw)
To: ocfs2-devel
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>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Mark Fasheh <mfasheh@suse.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Mark Fasheh <mfasheh@suse.de>
---
fs/ocfs2/namei.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
index f4d609b..3683643 100644
--- a/fs/ocfs2/namei.c
+++ b/fs/ocfs2/namei.c
@@ -664,6 +664,7 @@ static int ocfs2_link(struct dentry *old_dentry,
struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
struct ocfs2_dir_lookup_result lookup = { NULL, };
sigset_t oldset;
+ u64 old_de_ino;
trace_ocfs2_link((unsigned long long)OCFS2_I(inode)->ip_blkno,
old_dentry->d_name.len, old_dentry->d_name.name,
@@ -686,6 +687,22 @@ static int ocfs2_link(struct dentry *old_dentry,
goto out;
}
+ err = ocfs2_lookup_ino_from_name(dir, old_dentry->d_name.name,
+ old_dentry->d_name.len, &old_de_ino);
+ if (err) {
+ err = -ENOENT;
+ goto out;
+ }
+
+ /*
+ * Check whether another node removed the source inode while we
+ * were in the vfs.
+ */
+ if (old_de_ino != OCFS2_I(inode)->ip_blkno) {
+ err = -ENOENT;
+ goto out;
+ }
+
err = ocfs2_check_dir_for_entry(dir, dentry->d_name.name,
dentry->d_name.len);
if (err)
--
1.8.4.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [Ocfs2-devel] [PATCH V2] ocfs2: Check existence of old dentry in ocfs2_link()
2014-02-08 2:16 [Ocfs2-devel] [PATCH V2] ocfs2: Check existence of old dentry in ocfs2_link() Xue jiufei
@ 2014-02-10 21:47 ` Mark Fasheh
0 siblings, 0 replies; 2+ messages in thread
From: Mark Fasheh @ 2014-02-10 21:47 UTC (permalink / raw)
To: ocfs2-devel
On Sat, Feb 08, 2014 at 10:16:28AM +0800, Xue jiufei wrote:
> 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>
> Cc: Joel Becker <jlbec@evilplan.org>
> Cc: Mark Fasheh <mfasheh@suse.com>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This version adds the comment I wanted, thanks.
> Reviewed-by: Mark Fasheh <mfasheh@suse.de>
--Mark
--
Mark Fasheh
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-02-10 21:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-08 2:16 [Ocfs2-devel] [PATCH V2] ocfs2: Check existence of old dentry in ocfs2_link() Xue jiufei
2014-02-10 21:47 ` Mark Fasheh
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.