]> www.infradead.org Git - users/jedix/linux-maple.git/commit
nilfs2: fix potential UAF of struct nilfs_sc_info in nilfs_segctor_thread()
authorRyusuke Konishi <konishi.ryusuke@gmail.com>
Mon, 27 Mar 2023 17:53:18 +0000 (02:53 +0900)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 5 Apr 2023 23:01:34 +0000 (16:01 -0700)
commit541c48e51f9351b9f759c802a1bbd61f1d05f007
treea735a20e53d852b602db79a23fe6bf84303b19f1
parentf6a095081e8a8c2da3d4adc8082923edfbfb3c9c
nilfs2: fix potential UAF of struct nilfs_sc_info in nilfs_segctor_thread()

The finalization of nilfs_segctor_thread() can race with
nilfs_segctor_kill_thread() which terminates that thread, potentially
causing a use-after-free BUG as KASAN detected.

At the end of nilfs_segctor_thread(), it assigns NULL to "sc_task" member
of "struct nilfs_sc_info" to indicate the thread has finished, and then
notifies nilfs_segctor_kill_thread() of this using waitqueue
"sc_wait_task" on the struct nilfs_sc_info.

However, here, immediately after the NULL assignment to "sc_task", it is
possible that nilfs_segctor_kill_thread() will detect it and return to
continue the deallocation, freeing the nilfs_sc_info structure before the
thread does the notification.

This fixes the issue by protecting the NULL assignment to "sc_task" and
its notification, with spinlock "sc_state_lock" of the struct
nilfs_sc_info.  Since nilfs_segctor_kill_thread() does a final check to
see if "sc_task" is NULL with "sc_state_lock" locked, this can eliminate
the race.

Link: https://lkml.kernel.org/r/20230327175318.8060-1-konishi.ryusuke@gmail.com
Reported-by: syzbot+b08ebcc22f8f3e6be43a@syzkaller.appspotmail.com
Link: https://lkml.kernel.org/r/00000000000000660d05f7dfa877@google.com
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/nilfs2/segment.c