From 7523a2de6d789ce1b8f5601f9305ccfa68924c3a Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Mon, 28 May 2012 17:02:25 -0400 Subject: ext4: disallow hard-linked directory in ext4_lookup commit 7e936b737211e6b54e34b71a827e56b872e958d8 upstream. A hard-linked directory to its parent can cause the VFS to deadlock, and is a sign of a corrupted file system. So detect this case in ext4_lookup(), before the rmdir() lockup scenario can take place. Signed-off-by: Andreas Dilger Signed-off-by: "Theodore Ts'o" Signed-off-by: Ben Hutchings --- fs/ext4/namei.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'fs/ext4') diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index aa4c782c9dd7..4dd0890e9435 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1037,6 +1037,12 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, stru EXT4_ERROR_INODE(dir, "bad inode number: %u", ino); return ERR_PTR(-EIO); } + if (unlikely(ino == dir->i_ino)) { + EXT4_ERROR_INODE(dir, "'%.*s' linked to parent dir", + dentry->d_name.len, + dentry->d_name.name); + return ERR_PTR(-EIO); + } inode = ext4_iget(dir->i_sb, ino); if (inode == ERR_PTR(-ESTALE)) { EXT4_ERROR_INODE(dir, -- cgit v1.2.3