From: Eric Biggers <[email protected]>

commit facb03dddec04e4aac1bb2139accdceb04deb1f3 upstream.

If an inode has no links, we need to mark it bad rather than allowing it
to be accessed.  This avoids WARNINGs in inc_nlink() and drop_nlink() when
doing directory operations on a fuzzed filesystem.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: [email protected]
Reported-by: [email protected]
Signed-off-by: Eric Biggers <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Cc: Alexander Viro <[email protected]>
Cc: Qiujun Huang <[email protected]>
Cc: <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>

---
 fs/minix/inode.c |   14 ++++++++++++++
 1 file changed, 14 insertions(+)

--- a/fs/minix/inode.c
+++ b/fs/minix/inode.c
@@ -468,6 +468,13 @@ static struct inode *V1_minix_iget(struc
                iget_failed(inode);
                return ERR_PTR(-EIO);
        }
+       if (raw_inode->i_nlinks == 0) {
+               printk("MINIX-fs: deleted inode referenced: %lu\n",
+                      inode->i_ino);
+               brelse(bh);
+               iget_failed(inode);
+               return ERR_PTR(-ESTALE);
+       }
        inode->i_mode = raw_inode->i_mode;
        i_uid_write(inode, raw_inode->i_uid);
        i_gid_write(inode, raw_inode->i_gid);
@@ -501,6 +508,13 @@ static struct inode *V2_minix_iget(struc
                iget_failed(inode);
                return ERR_PTR(-EIO);
        }
+       if (raw_inode->i_nlinks == 0) {
+               printk("MINIX-fs: deleted inode referenced: %lu\n",
+                      inode->i_ino);
+               brelse(bh);
+               iget_failed(inode);
+               return ERR_PTR(-ESTALE);
+       }
        inode->i_mode = raw_inode->i_mode;
        i_uid_write(inode, raw_inode->i_uid);
        i_gid_write(inode, raw_inode->i_gid);


Reply via email to