Skip to content

Commit 4413834

Browse files
KAGA-KOKOdledford
authored andcommitted
IB/srpt: Rework srpt_disconnect_ch_sync()
This patch fixes a use-after-free issue for ch->release_done when running the SRP protocol on top of the rdma_rxe driver. Signed-off-by: Bart Van Assche <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent 795bc11 commit 4413834

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

drivers/infiniband/ulp/srpt/ib_srpt.c

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,38 +1841,48 @@ static int srpt_disconnect_ch(struct srpt_rdma_ch *ch)
18411841
return ret;
18421842
}
18431843

1844+
static bool srpt_ch_closed(struct srpt_device *sdev, struct srpt_rdma_ch *ch)
1845+
{
1846+
struct srpt_rdma_ch *ch2;
1847+
bool res = true;
1848+
1849+
rcu_read_lock();
1850+
list_for_each_entry(ch2, &sdev->rch_list, list) {
1851+
if (ch2 == ch) {
1852+
res = false;
1853+
break;
1854+
}
1855+
}
1856+
rcu_read_unlock();
1857+
1858+
return res;
1859+
}
1860+
18441861
/*
18451862
* Send DREQ and wait for DREP. Return true if and only if this function
18461863
* changed the state of @ch.
18471864
*/
18481865
static bool srpt_disconnect_ch_sync(struct srpt_rdma_ch *ch)
18491866
__must_hold(&sdev->mutex)
18501867
{
1851-
DECLARE_COMPLETION_ONSTACK(release_done);
18521868
struct srpt_device *sdev = ch->sport->sdev;
1853-
bool wait;
1869+
int ret;
18541870

18551871
lockdep_assert_held(&sdev->mutex);
18561872

18571873
pr_debug("ch %s-%d state %d\n", ch->sess_name, ch->qp->qp_num,
18581874
ch->state);
18591875

1860-
WARN_ON(ch->release_done);
1861-
ch->release_done = &release_done;
1862-
wait = !list_empty(&ch->list);
1863-
srpt_disconnect_ch(ch);
1876+
ret = srpt_disconnect_ch(ch);
18641877
mutex_unlock(&sdev->mutex);
18651878

1866-
if (!wait)
1867-
goto out;
1868-
1869-
while (wait_for_completion_timeout(&release_done, 180 * HZ) == 0)
1879+
while (wait_event_timeout(sdev->ch_releaseQ, srpt_ch_closed(sdev, ch),
1880+
5 * HZ) == 0)
18701881
pr_info("%s(%s-%d state %d): still waiting ...\n", __func__,
18711882
ch->sess_name, ch->qp->qp_num, ch->state);
18721883

1873-
out:
18741884
mutex_lock(&sdev->mutex);
1875-
return wait;
1885+
return ret == 0;
18761886
}
18771887

18781888
static void srpt_set_enabled(struct srpt_port *sport, bool enabled)
@@ -1916,8 +1926,7 @@ static void srpt_release_channel_work(struct work_struct *w)
19161926
struct se_session *se_sess;
19171927

19181928
ch = container_of(w, struct srpt_rdma_ch, release_work);
1919-
pr_debug("%s: %s-%d; release_done = %p\n", __func__, ch->sess_name,
1920-
ch->qp->qp_num, ch->release_done);
1929+
pr_debug("%s-%d\n", ch->sess_name, ch->qp->qp_num);
19211930

19221931
sdev = ch->sport->sdev;
19231932
BUG_ON(!sdev);
@@ -1946,14 +1955,6 @@ static void srpt_release_channel_work(struct work_struct *w)
19461955

19471956
mutex_lock(&sdev->mutex);
19481957
list_del_rcu(&ch->list);
1949-
if (ch->release_done)
1950-
complete(ch->release_done);
1951-
mutex_unlock(&sdev->mutex);
1952-
1953-
synchronize_rcu();
1954-
1955-
mutex_lock(&sdev->mutex);
1956-
INIT_LIST_HEAD(&ch->list);
19571958
mutex_unlock(&sdev->mutex);
19581959

19591960
wake_up(&sdev->ch_releaseQ);

drivers/infiniband/ulp/srpt/ib_srpt.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ enum rdma_ch_state {
270270
* @sess_name: Session name.
271271
* @ini_guid: Initiator port GUID.
272272
* @release_work: Allows scheduling of srpt_release_channel().
273-
* @release_done: Enables waiting for srpt_release_channel() completion.
274273
*/
275274
struct srpt_rdma_ch {
276275
struct ib_cm_id *cm_id;
@@ -299,7 +298,6 @@ struct srpt_rdma_ch {
299298
u8 sess_name[36];
300299
u8 ini_guid[24];
301300
struct work_struct release_work;
302-
struct completion *release_done;
303301
};
304302

305303
/**

0 commit comments

Comments
 (0)