Re: patch for race in do_unlink

Linus Torvalds (
Mon, 4 Aug 1997 09:39:08 -0700 (PDT)

On Mon, 4 Aug 1997, Bill Hawes wrote:
> I've attached a patch for 2.1.47 to fix a race involving unlinking.
> It's possible for one process to have unlinked an inode (yielding a
> negative dentry) while another one is proceeding to unlink the same
> object. The second one results in a call to ext2_unlink with a NULL
> inode, leading to unhappiness of the oops variety.

Btw, you still have a race in your patch.

You need to test for the negative dentry _after_ getting the parent lock.
So the patch should be something like this (modulo white-space - this got

--- v2.1.47/linux/fs/namei.c Sun Jul 27 12:11:01 1997
+++ linux/fs/namei.c Mon Aug 4 09:37:25 1997
@@ -831,6 +834,10 @@

dir = lock_parent(dentry);

+ error = -ENOENT;
+ if (!dentry->d_inode)
+ goto exit_lock;
error = -EROFS;
if (IS_RDONLY(dir))
goto exit_lock;

but yes, you're correct, this was a real bug.