Skip to contentSkip to conversation

btrfs: fix NPD during canceling replace when the target is missing

PATCH In review Anand Jain 2 participants 3 messages Feb 20, 2018 – Feb 21, 2018 Btrfs file system

lore
Share & tools
lore

Anand Jain

author
#0 lore raw

PATCH 1/1 btrfs: fix NPD during canceling replace when the target is missing

Replace target can be missing after a reboot during the replace. So check if device is null.

BUG: unable to handle kernel NULL pointer dereference at 00000000000000b0
IP: btrfs_destroy_dev_replace_tgtdev+0x43/0xf0 [btrfs]
Call Trace:
btrfs_dev_replace_cancel+0x22b/0x250 [btrfs]
btrfs_ioctl+0x2216/0x2590 [btrfs]
? do_vfs_ioctl+0x625/0x650
do_vfs_ioctl+0x625/0x650
? security_file_ioctl+0x30/0x50
SyS_ioctl+0x4e/0x80
do_syscall_64+0x5d/0x160
entry_SYSCALL64_slow_path+0x25/0x25
---
 fs/btrfs/dev-replace.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/dev-replace.c +2 -1
index 87f975143c05..476981c2cf55 100644
@@ -749,7 +749,8 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
 		   btrfs_dev_name(src_device), src_device->devid,
 		   btrfs_dev_name(tgt_device));
 
-	btrfs_destroy_dev_replace_tgtdev(fs_info, tgt_device);
+	if (tgt_device)
+		btrfs_destroy_dev_replace_tgtdev(fs_info, tgt_device);
 
 leave:
 	mutex_unlock(&dev_replace->lock_finishing_cancel_unmount);
Signature · 1 line
2.15.0
#1 lore raw
Quoted 25 lines · Anand Jain

Replace target can be missing after a reboot during the replace. So check if device is null.

BUG: unable to handle kernel NULL pointer dereference at 00000000000000b0
IP: btrfs_destroy_dev_replace_tgtdev+0x43/0xf0 [btrfs]
Call Trace:
btrfs_dev_replace_cancel+0x22b/0x250 [btrfs]
btrfs_ioctl+0x2216/0x2590 [btrfs]
? do_vfs_ioctl+0x625/0x650
do_vfs_ioctl+0x625/0x650
? security_file_ioctl+0x30/0x50
SyS_ioctl+0x4e/0x80
do_syscall_64+0x5d/0x160
entry_SYSCALL64_slow_path+0x25/0x25
---
 fs/btrfs/dev-replace.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/dev-replace.c +0 -0
index 87f975143c05..476981c2cf55 100644

fs/btrfs/dev-replace.c int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info) · line 753

Quoted 6 lines
fs/btrfs/dev-replace.c +2 -1
@@ -749,7 +749,8 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
 		   btrfs_dev_name(src_device), src_device->devid,
 		   btrfs_dev_name(tgt_device));
 
-	btrfs_destroy_dev_replace_tgtdev(fs_info, tgt_device);
+	if (tgt_device)
+		btrfs_destroy_dev_replace_tgtdev(fs_info, tgt_device);

I'll just discard the patch you sent a week ago that removes the 'if' in the first place.

https://patchwork.kernel.org/patch/10215103/

author
#2 lore raw
Quoted 29 lines · David Sterba
Quoted 28 lines · Anand Jain

Replace target can be missing after a reboot during the replace. So check if device is null.

BUG: unable to handle kernel NULL pointer dereference at 00000000000000b0
IP: btrfs_destroy_dev_replace_tgtdev+0x43/0xf0 [btrfs]
Call Trace:
btrfs_dev_replace_cancel+0x22b/0x250 [btrfs]
btrfs_ioctl+0x2216/0x2590 [btrfs]
? do_vfs_ioctl+0x625/0x650
do_vfs_ioctl+0x625/0x650
? security_file_ioctl+0x30/0x50
SyS_ioctl+0x4e/0x80
do_syscall_64+0x5d/0x160
entry_SYSCALL64_slow_path+0x25/0x25
---
  fs/btrfs/dev-replace.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/dev-replace.c +0 -0
index 87f975143c05..476981c2cf55 100644
@@ -749,7 +749,8 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
  		   btrfs_dev_name(src_device), src_device->devid,
  		   btrfs_dev_name(tgt_device));
 
Quoted 8 lines

fs/btrfs/dev-replace.c int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info) · line 753

Quoted 3 lines
fs/btrfs/dev-replace.c +2 -1
-	btrfs_destroy_dev_replace_tgtdev(fs_info, tgt_device);
+	if (tgt_device)
+		btrfs_destroy_dev_replace_tgtdev(fs_info, tgt_device);

I'll just discard the patch you sent a week ago that removes the 'if' in the first place.

https://patchwork.kernel.org/patch/10215103/

Oops. I completely forgot about this patch! right, pls discard. If replace target is missing, we don't alloc a missing device as usual, I missed this part.

Thanks, Anand