* [PATCH v3] scsi: mpi3mr: fix possible crash when setup bsg fail
@ 2024-12-26 12:18 Guixin Liu
2024-12-30 1:33 ` Guixin Liu
2025-01-06 18:30 ` Bart Van Assche
0 siblings, 2 replies; 4+ messages in thread
From: Guixin Liu @ 2024-12-26 12:18 UTC (permalink / raw)
To: Sathya Prakash Veerichetty, Kashyap Desai, Sumit Saxena,
Sreekanth Reddy, James E . J . Bottomley, Martin K . Petersen
Cc: mpi3mr-linuxdrv.pdl, linux-scsi
If bsg_setup_queue() fails, the bsg_queue is assigned a non-NULL value.
Consequently, in mpi3mr_bsg_exit(), the condition
"if(!mrioc->bsg_queue)" will not be satisfied, preventing execution
from entering bsg_remove_queue(), which could lead to the following
crash:
[ 85.349992] BUG: kernel NULL pointer dereference, address:
000000000000041c
[ 85.349998] #PF: supervisor read access in kernel mode
[ 85.350000] #PF: error_code(0x0000) - not-present page
[ 85.350002] PGD 0 P4D 0
[ 85.350004] Oops: 0000 [#1] PREEMPT SMP NOPTI
[ 85.350006] CPU: 2 PID: 4675 Comm: bash Kdump: loaded Tainted: G
E 6.6.63-cbp.git.f6b4ae219.an23.x86_64 #1
[ 85.350009] Hardware name: IEIT SYSTEMS
NF5280-M7-A0-R0-00/NF5280-M7-A0-R0-00, BIOS 06.04.01 07/22/2024
[ 85.350010] RIP: 0010:bsg_remove_queue+0x10/0x50
[ 85.350019] Code: 01 00 00 e9 92 92 fe ff 66 90 90 90 90 90 90 90 90
90 90 90 90 90 90 90 90 90 f3 0f 1e fa 0f 1f 44 00 00 48 85 ff 74 3a 55
53 <48> 8b af 28 04 00 00 48 89 fb 48 8b bd c8 00 00 00 e8 1a f9 ff ff
[ 85.350021] RSP: 0018:ffffc9000f637d40 EFLAGS: 00010282
[ 85.350022] RAX: 0000000000000001 RBX: ffff88810a20aa50 RCX:
0000000000000000
[ 85.350023] RDX: 0000000000000000 RSI: 0000000000000293 RDI:
fffffffffffffff4
[ 85.350024] RBP: ffff88810a20ad58 R08: 0000000000000004 R09:
ffffc9000f637cfc
[ 85.350025] R10: 0000000000000037 R11: ffffffffa8d22d60 R12:
ffff88810a20aa50
[ 85.350026] R13: ffff888110e52160 R14: ffff888110e57160 R15:
ffff8882123399a0
[ 85.350027] FS: 00007f6f2d673740(0000) GS:ffff88903e100000(0000)
knlGS:0000000000000000
[ 85.350028] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 85.350029] CR2: 000000000000041c CR3: 000000112dec6003 CR4:
0000000000f70ee0
[ 85.350030] DR0: 0000000000000000 DR1: 0000000000000000 DR2:
0000000000000000
[ 85.350031] DR3: 0000000000000000 DR6: 00000000fffe07f0 DR7:
0000000000000400
[ 85.350032] PKRU: 55555554
[ 85.350033] Call Trace:
[ 85.350035] <TASK>
[ 85.350037] ? __die+0x23/0x70
[ 85.350043] ? page_fault_oops+0x75/0x170
[ 85.350046] ? notify_change+0x44e/0x4f0
[ 85.350052] ? exc_page_fault+0x67/0x140
[ 85.350059] ? asm_exc_page_fault+0x26/0x30
[ 85.350065] ? __pfx_pci_conf1_read+0x10/0x10
[ 85.350071] ? bsg_remove_queue+0x10/0x50
[ 85.350077] mpi3mr_bsg_exit+0x1f/0x50 [mpi3mr]
[ 85.350090] mpi3mr_remove+0x6f/0x340 [mpi3mr]
[ 85.350097] pci_device_remove+0x3f/0xb0
[ 85.350104] device_release_driver_internal+0x19d/0x220
[ 85.350110] unbind_store+0xa4/0xb0
[ 85.350114] kernfs_fop_write_iter+0x11f/0x200
[ 85.350119] vfs_write+0x1fc/0x3e0
[ 85.350126] ksys_write+0x67/0xe0
[ 85.350128] do_syscall_64+0x38/0x80
[ 85.350133] entry_SYSCALL_64_after_hwframe+0x78/0xe2
[ 85.350136] RIP: 0033:0x7f6f2c32e4e8
[ 85.350138] Code: 89 02 48 c7 c0 ff ff ff ff eb b3 0f 1f 80 00 00 00
00 f3 0f 1e fa 48 8d 05 75 72 2a 00 8b 00 85 c0 75 17 b8 01 00 00 00 0f
05 <48> 3d 00 f0 ff ff 77 58 c3 0f 1f 80 00 00 00 00 41 54 49 89 d4 55
[ 85.350139] RSP: 002b:00007fff133ad218 EFLAGS: 00000246 ORIG_RAX:
0000000000000001
[ 85.350140] RAX: ffffffffffffffda RBX: 000000000000000d RCX:
00007f6f2c32e4e8
[ 85.350141] RDX: 000000000000000d RSI: 0000557e657fca70 RDI:
0000000000000001
[ 85.350142] RBP: 0000557e657fca70 R08: 000000000000000a R09:
00007f6f2c390160
[ 85.350142] R10: 000000000000000a R11: 0000000000000246 R12:
00007f6f2c5d16e0
[ 85.350143] R13: 000000000000000d R14: 00007f6f2c5cc860 R15:
000000000000000d
[ 85.350144] </TASK>
Fixes: 4268fa751365 ("scsi: mpi3mr: Add bsg device support")
Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
---
Changes from v2 to v3:
- Add the crash stack to commit body.
Changes from v1 to v2:
- Add return statement when setup bsg queue fail, sorry for the v1
trouble.
drivers/scsi/mpi3mr/mpi3mr_app.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/mpi3mr/mpi3mr_app.c b/drivers/scsi/mpi3mr/mpi3mr_app.c
index 10b8e4dc64f8..7589f48aebc8 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_app.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_app.c
@@ -2951,6 +2951,7 @@ void mpi3mr_bsg_init(struct mpi3mr_ioc *mrioc)
.max_hw_sectors = MPI3MR_MAX_APP_XFER_SECTORS,
.max_segments = MPI3MR_MAX_APP_XFER_SEGMENTS,
};
+ struct request_queue *q;
device_initialize(bsg_dev);
@@ -2966,14 +2967,17 @@ void mpi3mr_bsg_init(struct mpi3mr_ioc *mrioc)
return;
}
- mrioc->bsg_queue = bsg_setup_queue(bsg_dev, dev_name(bsg_dev), &lim,
+ q = bsg_setup_queue(bsg_dev, dev_name(bsg_dev), &lim,
mpi3mr_bsg_request, NULL, 0);
- if (IS_ERR(mrioc->bsg_queue)) {
+ if (IS_ERR(q)) {
ioc_err(mrioc, "%s: bsg registration failed\n",
dev_name(bsg_dev));
device_del(bsg_dev);
put_device(bsg_dev);
+ return;
}
+
+ mrioc->bsg_queue = q;
}
/**
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v3] scsi: mpi3mr: fix possible crash when setup bsg fail
2024-12-26 12:18 [PATCH v3] scsi: mpi3mr: fix possible crash when setup bsg fail Guixin Liu
@ 2024-12-30 1:33 ` Guixin Liu
2025-01-06 18:30 ` Bart Van Assche
1 sibling, 0 replies; 4+ messages in thread
From: Guixin Liu @ 2024-12-30 1:33 UTC (permalink / raw)
To: Sathya Prakash Veerichetty, Kashyap Desai, Sumit Saxena,
Sreekanth Reddy, James E . J . Bottomley, Martin K . Petersen
Cc: mpi3mr-linuxdrv.pdl, linux-scsi
Friendly ping...
BR,
Guixin Liu
在 2024/12/26 20:18, Guixin Liu 写道:
> If bsg_setup_queue() fails, the bsg_queue is assigned a non-NULL value.
> Consequently, in mpi3mr_bsg_exit(), the condition
> "if(!mrioc->bsg_queue)" will not be satisfied, preventing execution
> from entering bsg_remove_queue(), which could lead to the following
> crash:
>
> [ 85.349992] BUG: kernel NULL pointer dereference, address:
> 000000000000041c
> [ 85.349998] #PF: supervisor read access in kernel mode
> [ 85.350000] #PF: error_code(0x0000) - not-present page
> [ 85.350002] PGD 0 P4D 0
> [ 85.350004] Oops: 0000 [#1] PREEMPT SMP NOPTI
> [ 85.350006] CPU: 2 PID: 4675 Comm: bash Kdump: loaded Tainted: G
> E 6.6.63-cbp.git.f6b4ae219.an23.x86_64 #1
> [ 85.350009] Hardware name: IEIT SYSTEMS
> NF5280-M7-A0-R0-00/NF5280-M7-A0-R0-00, BIOS 06.04.01 07/22/2024
> [ 85.350010] RIP: 0010:bsg_remove_queue+0x10/0x50
> [ 85.350019] Code: 01 00 00 e9 92 92 fe ff 66 90 90 90 90 90 90 90 90
> 90 90 90 90 90 90 90 90 90 f3 0f 1e fa 0f 1f 44 00 00 48 85 ff 74 3a 55
> 53 <48> 8b af 28 04 00 00 48 89 fb 48 8b bd c8 00 00 00 e8 1a f9 ff ff
> [ 85.350021] RSP: 0018:ffffc9000f637d40 EFLAGS: 00010282
> [ 85.350022] RAX: 0000000000000001 RBX: ffff88810a20aa50 RCX:
> 0000000000000000
> [ 85.350023] RDX: 0000000000000000 RSI: 0000000000000293 RDI:
> fffffffffffffff4
> [ 85.350024] RBP: ffff88810a20ad58 R08: 0000000000000004 R09:
> ffffc9000f637cfc
> [ 85.350025] R10: 0000000000000037 R11: ffffffffa8d22d60 R12:
> ffff88810a20aa50
> [ 85.350026] R13: ffff888110e52160 R14: ffff888110e57160 R15:
> ffff8882123399a0
> [ 85.350027] FS: 00007f6f2d673740(0000) GS:ffff88903e100000(0000)
> knlGS:0000000000000000
> [ 85.350028] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> [ 85.350029] CR2: 000000000000041c CR3: 000000112dec6003 CR4:
> 0000000000f70ee0
> [ 85.350030] DR0: 0000000000000000 DR1: 0000000000000000 DR2:
> 0000000000000000
> [ 85.350031] DR3: 0000000000000000 DR6: 00000000fffe07f0 DR7:
> 0000000000000400
> [ 85.350032] PKRU: 55555554
> [ 85.350033] Call Trace:
> [ 85.350035] <TASK>
> [ 85.350037] ? __die+0x23/0x70
> [ 85.350043] ? page_fault_oops+0x75/0x170
> [ 85.350046] ? notify_change+0x44e/0x4f0
> [ 85.350052] ? exc_page_fault+0x67/0x140
> [ 85.350059] ? asm_exc_page_fault+0x26/0x30
> [ 85.350065] ? __pfx_pci_conf1_read+0x10/0x10
> [ 85.350071] ? bsg_remove_queue+0x10/0x50
> [ 85.350077] mpi3mr_bsg_exit+0x1f/0x50 [mpi3mr]
> [ 85.350090] mpi3mr_remove+0x6f/0x340 [mpi3mr]
> [ 85.350097] pci_device_remove+0x3f/0xb0
> [ 85.350104] device_release_driver_internal+0x19d/0x220
> [ 85.350110] unbind_store+0xa4/0xb0
> [ 85.350114] kernfs_fop_write_iter+0x11f/0x200
> [ 85.350119] vfs_write+0x1fc/0x3e0
> [ 85.350126] ksys_write+0x67/0xe0
> [ 85.350128] do_syscall_64+0x38/0x80
> [ 85.350133] entry_SYSCALL_64_after_hwframe+0x78/0xe2
> [ 85.350136] RIP: 0033:0x7f6f2c32e4e8
> [ 85.350138] Code: 89 02 48 c7 c0 ff ff ff ff eb b3 0f 1f 80 00 00 00
> 00 f3 0f 1e fa 48 8d 05 75 72 2a 00 8b 00 85 c0 75 17 b8 01 00 00 00 0f
> 05 <48> 3d 00 f0 ff ff 77 58 c3 0f 1f 80 00 00 00 00 41 54 49 89 d4 55
> [ 85.350139] RSP: 002b:00007fff133ad218 EFLAGS: 00000246 ORIG_RAX:
> 0000000000000001
> [ 85.350140] RAX: ffffffffffffffda RBX: 000000000000000d RCX:
> 00007f6f2c32e4e8
> [ 85.350141] RDX: 000000000000000d RSI: 0000557e657fca70 RDI:
> 0000000000000001
> [ 85.350142] RBP: 0000557e657fca70 R08: 000000000000000a R09:
> 00007f6f2c390160
> [ 85.350142] R10: 000000000000000a R11: 0000000000000246 R12:
> 00007f6f2c5d16e0
> [ 85.350143] R13: 000000000000000d R14: 00007f6f2c5cc860 R15:
> 000000000000000d
> [ 85.350144] </TASK>
>
> Fixes: 4268fa751365 ("scsi: mpi3mr: Add bsg device support")
> Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
> ---
> Changes from v2 to v3:
> - Add the crash stack to commit body.
>
> Changes from v1 to v2:
> - Add return statement when setup bsg queue fail, sorry for the v1
> trouble.
> drivers/scsi/mpi3mr/mpi3mr_app.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_app.c b/drivers/scsi/mpi3mr/mpi3mr_app.c
> index 10b8e4dc64f8..7589f48aebc8 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_app.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_app.c
> @@ -2951,6 +2951,7 @@ void mpi3mr_bsg_init(struct mpi3mr_ioc *mrioc)
> .max_hw_sectors = MPI3MR_MAX_APP_XFER_SECTORS,
> .max_segments = MPI3MR_MAX_APP_XFER_SEGMENTS,
> };
> + struct request_queue *q;
>
> device_initialize(bsg_dev);
>
> @@ -2966,14 +2967,17 @@ void mpi3mr_bsg_init(struct mpi3mr_ioc *mrioc)
> return;
> }
>
> - mrioc->bsg_queue = bsg_setup_queue(bsg_dev, dev_name(bsg_dev), &lim,
> + q = bsg_setup_queue(bsg_dev, dev_name(bsg_dev), &lim,
> mpi3mr_bsg_request, NULL, 0);
> - if (IS_ERR(mrioc->bsg_queue)) {
> + if (IS_ERR(q)) {
> ioc_err(mrioc, "%s: bsg registration failed\n",
> dev_name(bsg_dev));
> device_del(bsg_dev);
> put_device(bsg_dev);
> + return;
> }
> +
> + mrioc->bsg_queue = q;
> }
>
> /**
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v3] scsi: mpi3mr: fix possible crash when setup bsg fail
2024-12-26 12:18 [PATCH v3] scsi: mpi3mr: fix possible crash when setup bsg fail Guixin Liu
2024-12-30 1:33 ` Guixin Liu
@ 2025-01-06 18:30 ` Bart Van Assche
2025-01-07 2:04 ` Guixin Liu
1 sibling, 1 reply; 4+ messages in thread
From: Bart Van Assche @ 2025-01-06 18:30 UTC (permalink / raw)
To: Guixin Liu, Sathya Prakash Veerichetty, Kashyap Desai,
Sumit Saxena, Sreekanth Reddy, James E . J . Bottomley,
Martin K . Petersen
Cc: mpi3mr-linuxdrv.pdl, linux-scsi
On 12/26/24 4:18 AM, Guixin Liu wrote:
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_app.c b/drivers/scsi/mpi3mr/mpi3mr_app.c
> index 10b8e4dc64f8..7589f48aebc8 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_app.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_app.c
> @@ -2951,6 +2951,7 @@ void mpi3mr_bsg_init(struct mpi3mr_ioc *mrioc)
> .max_hw_sectors = MPI3MR_MAX_APP_XFER_SECTORS,
> .max_segments = MPI3MR_MAX_APP_XFER_SEGMENTS,
> };
> + struct request_queue *q;
>
> device_initialize(bsg_dev);
>
> @@ -2966,14 +2967,17 @@ void mpi3mr_bsg_init(struct mpi3mr_ioc *mrioc)
> return;
> }
>
> - mrioc->bsg_queue = bsg_setup_queue(bsg_dev, dev_name(bsg_dev), &lim,
> + q = bsg_setup_queue(bsg_dev, dev_name(bsg_dev), &lim,
> mpi3mr_bsg_request, NULL, 0);
> - if (IS_ERR(mrioc->bsg_queue)) {
> + if (IS_ERR(q)) {
> ioc_err(mrioc, "%s: bsg registration failed\n",
> dev_name(bsg_dev));
> device_del(bsg_dev);
> put_device(bsg_dev);
> + return;
> }
> +
> + mrioc->bsg_queue = q;
> }
Next time, when including a call stack in the patch description, please
clean it up. This means removing the timestamps, the register dumps and
also the stack frames that start with " ? ". Anyway:
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v3] scsi: mpi3mr: fix possible crash when setup bsg fail
2025-01-06 18:30 ` Bart Van Assche
@ 2025-01-07 2:04 ` Guixin Liu
0 siblings, 0 replies; 4+ messages in thread
From: Guixin Liu @ 2025-01-07 2:04 UTC (permalink / raw)
To: Bart Van Assche, Sathya Prakash Veerichetty, Kashyap Desai,
Sumit Saxena, Sreekanth Reddy, James E . J . Bottomley,
Martin K . Petersen
Cc: mpi3mr-linuxdrv.pdl, linux-scsi
在 2025/1/7 02:30, Bart Van Assche 写道:
> On 12/26/24 4:18 AM, Guixin Liu wrote:
>> diff --git a/drivers/scsi/mpi3mr/mpi3mr_app.c
>> b/drivers/scsi/mpi3mr/mpi3mr_app.c
>> index 10b8e4dc64f8..7589f48aebc8 100644
>> --- a/drivers/scsi/mpi3mr/mpi3mr_app.c
>> +++ b/drivers/scsi/mpi3mr/mpi3mr_app.c
>> @@ -2951,6 +2951,7 @@ void mpi3mr_bsg_init(struct mpi3mr_ioc *mrioc)
>> .max_hw_sectors = MPI3MR_MAX_APP_XFER_SECTORS,
>> .max_segments = MPI3MR_MAX_APP_XFER_SEGMENTS,
>> };
>> + struct request_queue *q;
>> device_initialize(bsg_dev);
>> @@ -2966,14 +2967,17 @@ void mpi3mr_bsg_init(struct mpi3mr_ioc *mrioc)
>> return;
>> }
>> - mrioc->bsg_queue = bsg_setup_queue(bsg_dev, dev_name(bsg_dev),
>> &lim,
>> + q = bsg_setup_queue(bsg_dev, dev_name(bsg_dev), &lim,
>> mpi3mr_bsg_request, NULL, 0);
>> - if (IS_ERR(mrioc->bsg_queue)) {
>> + if (IS_ERR(q)) {
>> ioc_err(mrioc, "%s: bsg registration failed\n",
>> dev_name(bsg_dev));
>> device_del(bsg_dev);
>> put_device(bsg_dev);
>> + return;
>> }
>> +
>> + mrioc->bsg_queue = q;
>> }
>
> Next time, when including a call stack in the patch description, please
> clean it up. This means removing the timestamps, the register dumps and
> also the stack frames that start with " ? ". Anyway:
>
> Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Thanks, I will send a v4 to clean up the stack, sorry for the trouble.
Best Regards,
Guixin Liu
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-01-07 2:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-26 12:18 [PATCH v3] scsi: mpi3mr: fix possible crash when setup bsg fail Guixin Liu
2024-12-30 1:33 ` Guixin Liu
2025-01-06 18:30 ` Bart Van Assche
2025-01-07 2:04 ` Guixin Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox