fsnotify: Fix possible use-after-free in inode iteration on umount
authorJan Kara <jack@suse.cz>
Mon, 12 Dec 2016 15:08:41 +0000 (16:08 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 9 Jan 2017 07:21:57 +0000 (08:21 +0100)
commit576ea9e5e92e9211ae26d75880d4d3142ff1b8d0
treee3bf4684a0a269a932142d3c8e7ca3e476e8906e
parent43983ce75e6119b0ba3249a38f1160805e3d761c
fsnotify: Fix possible use-after-free in inode iteration on umount

commit 5716863e0f8251d3360d4cbfc0e44e08007075df upstream.

fsnotify_unmount_inodes() plays complex tricks to pin next inode in the
sb->s_inodes list when iterating over all inodes. Furthermore the code has a
bug that if the current inode is the last on i_sb_list that does not have e.g.
I_FREEING set, then we leave next_i pointing to inode which may get removed
from the i_sb_list once we drop s_inode_list_lock thus resulting in
use-after-free issues (usually manifesting as infinite looping in
fsnotify_unmount_inodes()).

Fix the problem by keeping current inode pinned somewhat longer. Then we can
make the code much simpler and standard.

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/notify/inode_mark.c