Patch "btrfs: don't access possibly stale fs_info data in device_list_add" has been added to the 5.15-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    btrfs: don't access possibly stale fs_info data in device_list_add

to the 5.15-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     btrfs-don-t-access-possibly-stale-fs_info-data-in-de.patch
and it can be found in the queue-5.15 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit a6683351a79b2437780e7b15aa466a8fb7722c55
Author: Dongliang Mu <mudongliangabcd@xxxxxxxxx>
Date:   Thu Mar 3 22:40:27 2022 +0800

    btrfs: don't access possibly stale fs_info data in device_list_add
    
    [ Upstream commit 79c9234ba596e903907de20573fd4bcc85315b06 ]
    
    Syzbot reported a possible use-after-free in printing information
    in device_list_add.
    
    Very similar with the bug fixed by commit 0697d9a61099 ("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: syzbot+82650a4e0ed38f218363@xxxxxxxxxxxxxxxxxxxxxxxxx
    CC: stable@xxxxxxxxxxxxxxx # 4.19+
    Signed-off-by: Dongliang Mu <mudongliangabcd@xxxxxxxxx>
    Reviewed-by: David Sterba <dsterba@xxxxxxxx>
    Signed-off-by: David Sterba <dsterba@xxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index cec54c6e1cdd..89ce0b449c22 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -955,6 +955,11 @@ static noinline struct btrfs_device *device_list_add(const char *path,
 		/*
 		 * We are going to replace the device path for a given devid,
 		 * make sure it's the same device if the device is mounted
+		 *
+		 * NOTE: the device->fs_info may not be reliable here so pass
+		 * in a NULL to message helpers instead. This avoids a possible
+		 * use-after-free when the fs_info and fs_info->sb are already
+		 * torn down.
 		 */
 		if (device->bdev) {
 			int error;
@@ -968,12 +973,6 @@ static noinline struct btrfs_device *device_list_add(const char *path,
 
 			if (device->bdev->bd_dev != path_dev) {
 				mutex_unlock(&fs_devices->device_list_mutex);
-				/*
-				 * device->fs_info may not be reliable here, so
-				 * pass in a NULL instead. This avoids a
-				 * possible use-after-free when the fs_info and
-				 * fs_info->sb are already torn down.
-				 */
 				btrfs_warn_in_rcu(NULL,
 	"duplicate device %s devid %llu generation %llu scanned by %s (%d)",
 						  path, devid, found_transid,
@@ -981,7 +980,7 @@ static noinline struct btrfs_device *device_list_add(const char *path,
 						  task_pid_nr(current));
 				return ERR_PTR(-EEXIST);
 			}
-			btrfs_info_in_rcu(device->fs_info,
+			btrfs_info_in_rcu(NULL,
 	"devid %llu device path %s changed to %s scanned by %s (%d)",
 					  devid, rcu_str_deref(device->name),
 					  path, current->comm,



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux