ext4: fix hang when processing corrupted orphaned inode list
authorTheodore Ts'o <tytso@mit.edu>
Sat, 30 Apr 2016 04:48:54 +0000 (00:48 -0400)
committerBen Hutchings <ben@decadent.org.uk>
Mon, 22 Aug 2016 21:37:09 +0000 (22:37 +0100)
commitcb7a13ce5b6467783aab8d67de2130bc906bcaac
tree072d0dd213fae63457f29aa5776b887e98754509
parentaecf3aa4ca83e8e2854aa69a326f722590dc5726
ext4: fix hang when processing corrupted orphaned inode list

commit c9eb13a9105e2e418f72e46a2b6da3f49e696902 upstream.

If the orphaned inode list contains inode #5, ext4_iget() returns a
bad inode (since the bootloader inode should never be referenced
directly).  Because of the bad inode, we end up processing the inode
repeatedly and this hangs the machine.

This can be reproduced via:

   mke2fs -t ext4 /tmp/foo.img 100
   debugfs -w -R "ssv last_orphan 5" /tmp/foo.img
   mount -o loop /tmp/foo.img /mnt

(But don't do this if you are using an unpatched kernel if you care
about the system staying functional.  :-)

This bug was found by the port of American Fuzzy Lop into the kernel
to find file system problems[1].  (Since it *only* happens if inode #5
shows up on the orphan list --- 3, 7, 8, etc. won't do it, it's not
surprising that AFL needed two hours before it found it.)

[1] http://events.linuxfoundation.org/sites/events/files/slides/AFL%20filesystem%20fuzzing%2C%20Vault%202016_0.pdf

Reported by: Vegard Nossum <vegard.nossum@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
fs/ext4/ialloc.c