]> git.karo-electronics.de Git - karo-tx-linux.git/commit
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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 8 May 2013 02:51:54 +0000 (19:51 -0700)
commit6615e6db12bf29ab3d1062c9144c4e0828d2c588
tree6c1c6b4d57131a375068cc26603c9bb24297c6e1
parent0e079960ed813d36aa7625da4c388ae0d6e9d320
sysfs: fix use after free in case of concurrent read/write and readdir

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>
fs/sysfs/dir.c