From: Andrew Morton sigh. Cc: Eric Sandeen Cc: Signed-off-by: Andrew Morton --- fs/ext3/namei.c | 4 ++++ fs/ext4/namei.c | 4 ++++ 2 files changed, 8 insertions(+) diff -puN fs/ext3/namei.c~return-enoent-from-ext3_link-when-racing-with-unlink-fix fs/ext3/namei.c --- a/fs/ext3/namei.c~return-enoent-from-ext3_link-when-racing-with-unlink-fix +++ a/fs/ext3/namei.c @@ -2191,6 +2191,10 @@ static int ext3_link (struct dentry * ol if (inode->i_nlink >= EXT3_LINK_MAX) return -EMLINK; + /* + * Return -ENOENT if we've raced with unlink and i_nlink is 0. Doing + * otherwise has the potential to corrupt the orphan inode list. + */ if (inode->i_nlink == 0) return -ENOENT; diff -puN fs/ext4/namei.c~return-enoent-from-ext3_link-when-racing-with-unlink-fix fs/ext4/namei.c --- a/fs/ext4/namei.c~return-enoent-from-ext3_link-when-racing-with-unlink-fix +++ a/fs/ext4/namei.c @@ -2189,6 +2189,10 @@ static int ext4_link (struct dentry * ol if (inode->i_nlink >= EXT4_LINK_MAX) return -EMLINK; + /* + * Return -ENOENT if we've raced with unlink and i_nlink is 0. Doing + * otherwise has the potential to corrupt the orphan inode list. + */ if (inode->i_nlink == 0) return -ENOENT; _