Skip to content

Commit ecc5e89

Browse files
KAGA-KOKOgregkh
authored andcommitted
IB/srp: Avoid that a cable pull can trigger a kernel crash
commit 8a0d18c62121d3c554a83eb96e2752861d84d937 upstream. This patch fixes the following kernel crash: general protection fault: 0000 [#1] PREEMPT SMP Workqueue: ib_mad2 timeout_sends [ib_core] Call Trace: ib_sa_path_rec_callback+0x1c4/0x1d0 [ib_core] send_handler+0xb2/0xd0 [ib_core] timeout_sends+0x14d/0x220 [ib_core] process_one_work+0x200/0x630 worker_thread+0x4e/0x3b0 kthread+0x113/0x150 Fixes: commit aef9ec3 ("IB: Add SCSI RDMA Protocol (SRP) initiator") Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Doug Ledford <dledford@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3e32b40 commit ecc5e89

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

drivers/infiniband/ulp/srp/ib_srp.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -670,12 +670,19 @@ static void srp_path_rec_completion(int status,
670670
static int srp_lookup_path(struct srp_rdma_ch *ch)
671671
{
672672
struct srp_target_port *target = ch->target;
673-
int ret;
673+
int ret = -ENODEV;
674674

675675
ch->path.numb_path = 1;
676676

677677
init_completion(&ch->done);
678678

679+
/*
680+
* Avoid that the SCSI host can be removed by srp_remove_target()
681+
* before srp_path_rec_completion() is called.
682+
*/
683+
if (!scsi_host_get(target->scsi_host))
684+
goto out;
685+
679686
ch->path_query_id = ib_sa_path_rec_get(&srp_sa_client,
680687
target->srp_host->srp_dev->dev,
681688
target->srp_host->port,
@@ -689,18 +696,24 @@ static int srp_lookup_path(struct srp_rdma_ch *ch)
689696
GFP_KERNEL,
690697
srp_path_rec_completion,
691698
ch, &ch->path_query);
692-
if (ch->path_query_id < 0)
693-
return ch->path_query_id;
699+
ret = ch->path_query_id;
700+
if (ret < 0)
701+
goto put;
694702

695703
ret = wait_for_completion_interruptible(&ch->done);
696704
if (ret < 0)
697-
return ret;
705+
goto put;
698706

699-
if (ch->status < 0)
707+
ret = ch->status;
708+
if (ret < 0)
700709
shost_printk(KERN_WARNING, target->scsi_host,
701710
PFX "Path record query failed\n");
702711

703-
return ch->status;
712+
put:
713+
scsi_host_put(target->scsi_host);
714+
715+
out:
716+
return ret;
704717
}
705718

706719
static int srp_send_req(struct srp_rdma_ch *ch, bool multich)

0 commit comments

Comments
 (0)