Skip to content

Commit 295006f

Browse files
guixinliu1995martinkpetersen
authored andcommitted
scsi: mpi3mr: Fix possible crash when setting up bsg fails
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: BUG: kernel NULL pointer dereference, address: 000000000000041c Call Trace: <TASK> mpi3mr_bsg_exit+0x1f/0x50 [mpi3mr] mpi3mr_remove+0x6f/0x340 [mpi3mr] pci_device_remove+0x3f/0xb0 device_release_driver_internal+0x19d/0x220 unbind_store+0xa4/0xb0 kernfs_fop_write_iter+0x11f/0x200 vfs_write+0x1fc/0x3e0 ksys_write+0x67/0xe0 do_syscall_64+0x38/0x80 entry_SYSCALL_64_after_hwframe+0x78/0xe2 Fixes: 4268fa7 ("scsi: mpi3mr: Add bsg device support") Signed-off-by: Guixin Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Bart Van Assche <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 1e95c79 commit 295006f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/scsi/mpi3mr/mpi3mr_app.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2951,6 +2951,7 @@ void mpi3mr_bsg_init(struct mpi3mr_ioc *mrioc)
29512951
.max_hw_sectors = MPI3MR_MAX_APP_XFER_SECTORS,
29522952
.max_segments = MPI3MR_MAX_APP_XFER_SEGMENTS,
29532953
};
2954+
struct request_queue *q;
29542955

29552956
device_initialize(bsg_dev);
29562957

@@ -2966,14 +2967,17 @@ void mpi3mr_bsg_init(struct mpi3mr_ioc *mrioc)
29662967
return;
29672968
}
29682969

2969-
mrioc->bsg_queue = bsg_setup_queue(bsg_dev, dev_name(bsg_dev), &lim,
2970+
q = bsg_setup_queue(bsg_dev, dev_name(bsg_dev), &lim,
29702971
mpi3mr_bsg_request, NULL, 0);
2971-
if (IS_ERR(mrioc->bsg_queue)) {
2972+
if (IS_ERR(q)) {
29722973
ioc_err(mrioc, "%s: bsg registration failed\n",
29732974
dev_name(bsg_dev));
29742975
device_del(bsg_dev);
29752976
put_device(bsg_dev);
2977+
return;
29762978
}
2979+
2980+
mrioc->bsg_queue = q;
29772981
}
29782982

29792983
/**

0 commit comments

Comments
 (0)