Skip to content

Commit 79c9234

Browse files
mudongliangkdave
authored andcommitted
btrfs: don't access possibly stale fs_info data in device_list_add
Syzbot reported a possible use-after-free in printing information in device_list_add. Very similar with the bug fixed by commit 0697d9a ("btrfs: don't access possibly stale fs_info data for printing duplicate device"), but this time the use occurs in btrfs_info_in_rcu. Call Trace: kasan_report.cold+0x83/0xdf mm/kasan/report.c:459 btrfs_printk+0x395/0x425 fs/btrfs/super.c:244 device_list_add.cold+0xd7/0x2ed fs/btrfs/volumes.c:957 btrfs_scan_one_device+0x4c7/0x5c0 fs/btrfs/volumes.c:1387 btrfs_control_ioctl+0x12a/0x2d0 fs/btrfs/super.c:2409 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:874 [inline] __se_sys_ioctl fs/ioctl.c:860 [inline] __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:860 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x44/0xae Fix this by modifying device->fs_info to NULL too. Reported-and-tested-by: [email protected] CC: [email protected] # 4.19+ Signed-off-by: Dongliang Mu <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent bf7bd72 commit 79c9234

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

fs/btrfs/volumes.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -921,24 +921,23 @@ static noinline struct btrfs_device *device_list_add(const char *path,
921921
/*
922922
* We are going to replace the device path for a given devid,
923923
* make sure it's the same device if the device is mounted
924+
*
925+
* NOTE: the device->fs_info may not be reliable here so pass
926+
* in a NULL to message helpers instead. This avoids a possible
927+
* use-after-free when the fs_info and fs_info->sb are already
928+
* torn down.
924929
*/
925930
if (device->bdev) {
926931
if (device->devt != path_devt) {
927932
mutex_unlock(&fs_devices->device_list_mutex);
928-
/*
929-
* device->fs_info may not be reliable here, so
930-
* pass in a NULL instead. This avoids a
931-
* possible use-after-free when the fs_info and
932-
* fs_info->sb are already torn down.
933-
*/
934933
btrfs_warn_in_rcu(NULL,
935934
"duplicate device %s devid %llu generation %llu scanned by %s (%d)",
936935
path, devid, found_transid,
937936
current->comm,
938937
task_pid_nr(current));
939938
return ERR_PTR(-EEXIST);
940939
}
941-
btrfs_info_in_rcu(device->fs_info,
940+
btrfs_info_in_rcu(NULL,
942941
"devid %llu device path %s changed to %s scanned by %s (%d)",
943942
devid, rcu_str_deref(device->name),
944943
path, current->comm,

0 commit comments

Comments
 (0)