Anand Jain
16a200f66e
btrfs: check for missing device in btrfs_trim_fs
...
A fstrim on a degraded raid1 can trigger the following null pointer
dereference:
BTRFS info (device loop0): allowing degraded mounts
BTRFS info (device loop0): disk space caching is enabled
BTRFS info (device loop0): has skinny extents
BTRFS warning (device loop0): devid 2 uuid 97ac16f7-e14d-4db1-95bc-3d489b424adb is missing
BTRFS warning (device loop0): devid 2 uuid 97ac16f7-e14d-4db1-95bc-3d489b424adb is missing
BTRFS info (device loop0): enabling ssd optimizations
BUG: kernel NULL pointer dereference, address: 0000000000000620
PGD 0 P4D 0
Oops: 0000 [#1 ] SMP NOPTI
CPU: 0 PID: 4574 Comm: fstrim Not tainted 5.13.0-rc7+ #31
Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
RIP: 0010:btrfs_trim_fs+0x199/0x4a0 [btrfs]
RSP: 0018:ffff959541797d28 EFLAGS: 00010293
RAX: 0000000000000000 RBX: ffff946f84eca508 RCX: a7a67937adff8608
RDX: ffff946e8122d000 RSI: 0000000000000000 RDI: ffffffffc02fdbf0
RBP: ffff946ea4615000 R08: 0000000000000001 R09: 0000000000000000
R10: 0000000000000000 R11: ffff946e8122d960 R12: 0000000000000000
R13: ffff959541797db8 R14: ffff946e8122d000 R15: ffff959541797db8
FS: 00007f55917a5080(0000) GS:ffff946f9bc00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000000620 CR3: 000000002d2c8001 CR4: 00000000000706f0
Call Trace:
btrfs_ioctl_fitrim+0x167/0x260 [btrfs]
btrfs_ioctl+0x1c00/0x2fe0 [btrfs]
? selinux_file_ioctl+0x140/0x240
? syscall_trace_enter.constprop.0+0x188/0x240
? __x64_sys_ioctl+0x83/0xb0
__x64_sys_ioctl+0x83/0xb0
Reproducer:
$ mkfs.btrfs -fq -d raid1 -m raid1 /dev/loop0 /dev/loop1
$ mount /dev/loop0 /btrfs
$ umount /btrfs
$ btrfs dev scan --forget
$ mount -o degraded /dev/loop0 /btrfs
$ fstrim /btrfs
The reason is we call btrfs_trim_free_extents() for the missing device,
which uses device->bdev (NULL for missing device) to find if the device
supports discard.
Fix is to check if the device is missing before calling
btrfs_trim_free_extents().
CC: stable@vger.kernel.org # 5.4+
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-22 15:49:49 +02:00
..
2021-05-07 11:18:52 -07:00
2021-01-24 14:27:20 +01:00
2021-02-23 13:39:45 -08:00
2021-06-18 13:49:07 -07:00
2021-03-24 14:14:27 -04:00
2021-03-30 16:54:49 -07:00
2021-01-24 14:27:20 +01:00
2021-07-22 15:49:49 +02:00
2021-04-23 10:14:32 +01:00
2021-05-06 10:27:02 -07:00
2021-05-27 15:26:32 -05:00
2021-04-23 14:42:39 -07:00
2021-05-07 00:26:34 -07:00
2021-01-05 23:02:47 -05:00
2021-04-26 08:51:23 -07:00
2021-06-04 15:01:08 +02:00
2021-03-29 13:28:18 -05:00
2021-05-13 18:32:26 +02:00
2021-04-12 15:04:29 +02:00
2020-09-18 16:45:50 -04:00
2021-05-13 15:58:46 +08:00
2021-04-27 20:45:07 +09:00
2020-12-09 09:39:38 -05:00
2021-05-02 09:14:01 -07:00
2021-06-06 14:24:13 -07:00
2021-05-12 07:38:00 -07:00
2021-05-07 00:26:34 -07:00
2021-04-23 10:14:32 +01:00
2021-05-02 09:14:01 -07:00
2021-06-01 23:16:42 +02:00
2021-01-24 14:27:20 +01:00
2021-05-14 19:41:32 -07:00
2021-05-02 09:14:01 -07:00
2021-05-06 19:24:13 -07:00
2021-06-16 09:24:42 -07:00
2021-05-14 19:41:32 -07:00
2021-05-06 19:24:13 -07:00
2021-04-09 23:32:16 -04:00
2021-05-04 18:08:40 -07:00
2021-04-12 15:04:29 +02:00
2021-02-23 13:39:45 -08:00
2021-01-25 09:36:23 -05:00
2021-01-24 14:27:20 +01:00
2021-05-25 13:48:04 +01:00
2021-06-03 10:14:42 -04:00
2021-03-22 10:19:00 -04:00
2021-05-07 11:23:41 -07:00
2021-05-07 00:34:51 -07:00
2021-06-14 12:16:37 +02:00
2021-02-24 13:38:26 -08:00
2021-06-05 08:58:12 -07:00
2021-01-24 14:27:20 +01:00
2021-03-12 22:15:22 -05:00
2021-04-29 08:06:05 -04:00
2021-04-30 15:17:08 -07:00
2021-06-15 10:47:51 -07:00
2021-04-27 18:09:44 -07:00
2020-09-18 16:45:50 -04:00
2020-09-18 16:45:50 -04:00
2021-05-10 16:27:49 +02:00
2021-02-24 13:38:26 -08:00
2021-05-07 00:26:34 -07:00
2020-10-24 12:26:05 -07:00
2021-05-14 19:41:32 -07:00
2021-01-12 14:26:31 +01:00
2021-01-24 14:27:20 +01:00
2021-03-23 14:08:18 -04:00
2021-05-04 18:08:40 -07:00
2021-04-15 22:36:45 -04:00
2021-04-15 22:36:45 -04:00
2021-05-02 00:43:35 +09:00
2021-03-12 22:15:00 -05:00
2021-04-22 17:31:32 +10:00
2021-05-27 08:11:24 -07:00
2021-04-29 11:06:13 -07:00
2021-04-30 11:20:39 -07:00
2021-01-15 12:17:25 -05:00
2021-01-24 14:27:20 +01:00
2021-01-24 14:27:20 +01:00
2021-03-08 10:21:11 -05:00
2021-03-08 10:21:11 -05:00
2021-04-19 09:56:37 +10:00
2021-03-13 11:27:30 -08:00
2021-05-22 07:40:34 -10:00
2021-05-05 13:50:15 -07:00
2021-01-06 08:42:51 -05:00
2021-06-10 14:02:29 -07:00
2021-03-21 11:43:58 -04:00
2021-05-15 08:28:08 -07:00
2021-04-15 22:36:45 -04:00
2021-04-09 14:54:23 -07:00
2020-11-15 09:49:10 -05:00
2021-05-06 19:24:13 -07:00
2021-02-24 13:38:26 -08:00
2021-02-23 13:39:45 -08:00
2021-02-24 13:38:26 -08:00
2020-10-25 20:02:08 -04:00
2021-05-03 11:05:28 -07:00
2021-04-30 11:20:35 -07:00
2021-01-13 17:26:50 +01:00
2021-01-24 14:27:19 +01:00
2021-05-05 11:27:20 -07:00
2021-02-23 13:39:45 -08:00
2021-06-10 16:33:51 -06:00
2021-05-26 09:03:56 -06:00
2021-05-25 19:39:58 -06:00
2021-04-12 15:04:23 +02:00
2021-05-07 11:23:41 -07:00
2021-04-19 09:56:37 +10:00
2020-10-05 13:37:04 +02:00
2021-03-23 11:20:25 +01:00
2021-05-05 13:44:19 -07:00
2021-04-23 10:14:32 +01:00
2021-01-24 14:29:34 +01:00
2021-03-11 07:47:48 -07:00
2021-04-27 12:49:42 -07:00
2021-05-12 14:13:16 +02:00
2021-02-23 13:39:45 -08:00
2021-02-24 13:38:26 -08:00
2021-03-08 15:18:43 +01:00
2021-01-24 14:27:20 +01:00
2021-01-24 14:43:45 +01:00
2021-01-25 23:29:36 -05:00
2021-04-17 11:39:49 -07:00
2021-01-24 14:27:19 +01:00
2021-03-16 22:13:10 +01:00
2021-04-27 15:50:15 -07:00
2021-05-18 16:20:54 -05:00
2021-02-21 11:02:48 -08:00
2021-04-17 23:03:50 -04:00
2021-02-13 17:17:53 +01:00
2021-04-22 12:22:11 -07:00
2021-05-05 11:27:22 -07:00
2021-01-24 14:27:18 +01:00
2021-03-23 11:20:26 +01:00