sysfs: fix use after free in case of concurrent read/write and readdir
authorMing Lei <ming.lei@canonical.com>
Tue, 2 Apr 2013 02:12:26 +0000 (10:12 +0800)
committerBen Hutchings <ben@decadent.org.uk>
Mon, 13 May 2013 14:02:13 +0000 (15:02 +0100)
commit f7db5e7660b122142410dcf36ba903c73d473250 upstream.

The inode->i_mutex isn't hold when updating filp->f_pos
in read()/write(), so the filp->f_pos might be read as
0 or 1 in readdir() when there is concurrent read()/write()
on this same file, then may cause use after free in readdir().

The bug can be reproduced with Li Zefan's test code on the
link:

https://patchwork.kernel.org/patch/2160771/

This patch fixes the use after free under this situation.

Reported-by: Li Zefan <lizefan@huawei.com>
Signed-off-by: Ming Lei <ming.lei@canonical.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[bwh: Backported to 3.2: file position is child inode number, not hash]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

No differences found