Skip to content

Commit 0686a81

Browse files
quic-jhugoMani-Sadhasivam
authored andcommitted
bus: mhi: host: Fix race between unprepare and queue_buf
A client driver may use mhi_unprepare_from_transfer() to quiesce incoming data during the client driver's tear down. The client driver might also be processing data at the same time, resulting in a call to mhi_queue_buf() which will invoke mhi_gen_tre(). If mhi_gen_tre() runs after mhi_unprepare_from_transfer() has torn down the channel, a panic will occur due to an invalid dereference leading to a page fault. This occurs because mhi_gen_tre() does not verify the channel state after locking it. Fix this by having mhi_gen_tre() confirm the channel state is valid, or return error to avoid accessing deinitialized data. Cc: stable@vger.kernel.org # 6.8 Fixes: b89b6a8 ("bus: mhi: host: Add spinlock to protect WP access when queueing TREs") Signed-off-by: Jeffrey Hugo <quic_jhugo@quicinc.com> Signed-off-by: Jeff Hugo <jeff.hugo@oss.qualcomm.com> Reviewed-by: Krishna Chaitanya Chundru <krishna.chundru@oss.qualcomm.com> Reviewed-by: Youssef Samir <quic_yabdulra@quicinc.com> Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> Reviewed-by: Troy Hanson <quic_thanson@quicinc.com> Link: https://lore.kernel.org/r/20250306172913.856982-1-jeff.hugo@oss.qualcomm.com [mani: added stable tag] Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
1 parent cba6bdf commit 0686a81

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

drivers/bus/mhi/host/main.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,11 +1188,16 @@ int mhi_gen_tre(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan,
11881188
struct mhi_ring_element *mhi_tre;
11891189
struct mhi_buf_info *buf_info;
11901190
int eot, eob, chain, bei;
1191-
int ret;
1191+
int ret = 0;
11921192

11931193
/* Protect accesses for reading and incrementing WP */
11941194
write_lock_bh(&mhi_chan->lock);
11951195

1196+
if (mhi_chan->ch_state != MHI_CH_STATE_ENABLED) {
1197+
ret = -ENODEV;
1198+
goto out;
1199+
}
1200+
11961201
buf_ring = &mhi_chan->buf_ring;
11971202
tre_ring = &mhi_chan->tre_ring;
11981203

@@ -1210,10 +1215,8 @@ int mhi_gen_tre(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan,
12101215

12111216
if (!info->pre_mapped) {
12121217
ret = mhi_cntrl->map_single(mhi_cntrl, buf_info);
1213-
if (ret) {
1214-
write_unlock_bh(&mhi_chan->lock);
1215-
return ret;
1216-
}
1218+
if (ret)
1219+
goto out;
12171220
}
12181221

12191222
eob = !!(flags & MHI_EOB);
@@ -1231,9 +1234,10 @@ int mhi_gen_tre(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan,
12311234
mhi_add_ring_element(mhi_cntrl, tre_ring);
12321235
mhi_add_ring_element(mhi_cntrl, buf_ring);
12331236

1237+
out:
12341238
write_unlock_bh(&mhi_chan->lock);
12351239

1236-
return 0;
1240+
return ret;
12371241
}
12381242

12391243
int mhi_queue_buf(struct mhi_device *mhi_dev, enum dma_data_direction dir,

0 commit comments

Comments
 (0)