Skip to content

Commit a6fa67d

Browse files
committed
drm/dp_mst: Fix resetting msg rx state after topology removal
If the MST topology is removed during the reception of an MST down reply or MST up request sideband message, the drm_dp_mst_topology_mgr::up_req_recv/down_rep_recv states could be reset from one thread via drm_dp_mst_topology_mgr_set_mst(false), racing with the reading/parsing of the message from another thread via drm_dp_mst_handle_down_rep() or drm_dp_mst_handle_up_req(). The race is possible since the reader/parser doesn't hold any lock while accessing the reception state. This in turn can lead to a memory corruption in the reader/parser as described by commit bd2fcca ("drm/dp_mst: Fix MST sideband message body length check"). Fix the above by resetting the message reception state if needed before reading/parsing a message. Another solution would be to hold the drm_dp_mst_topology_mgr::lock for the whole duration of the message reception/parsing in drm_dp_mst_handle_down_rep() and drm_dp_mst_handle_up_req(), however this would require a bigger change. Since the fix is also needed for stable, opting for the simpler solution in this patch. Cc: Lyude Paul <lyude@redhat.com> Cc: <stable@vger.kernel.org> Fixes: 1d08261 ("drm/display/dp_mst: Fix down/up message handling after sink disconnect") Closes: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/13056 Reviewed-by: Lyude Paul <lyude@redhat.com> Signed-off-by: Imre Deak <imre.deak@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20241203160223.2926014-2-imre.deak@intel.com
1 parent 86e8f94 commit a6fa67d

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

drivers/gpu/drm/display/drm_dp_mst_topology.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3700,8 +3700,7 @@ int drm_dp_mst_topology_mgr_set_mst(struct drm_dp_mst_topology_mgr *mgr, bool ms
37003700
ret = 0;
37013701
mgr->payload_id_table_cleared = false;
37023702

3703-
memset(&mgr->down_rep_recv, 0, sizeof(mgr->down_rep_recv));
3704-
memset(&mgr->up_req_recv, 0, sizeof(mgr->up_req_recv));
3703+
mgr->reset_rx_state = true;
37053704
}
37063705

37073706
out_unlock:
@@ -3859,6 +3858,11 @@ int drm_dp_mst_topology_mgr_resume(struct drm_dp_mst_topology_mgr *mgr,
38593858
}
38603859
EXPORT_SYMBOL(drm_dp_mst_topology_mgr_resume);
38613860

3861+
static void reset_msg_rx_state(struct drm_dp_sideband_msg_rx *msg)
3862+
{
3863+
memset(msg, 0, sizeof(*msg));
3864+
}
3865+
38623866
static bool
38633867
drm_dp_get_one_sb_msg(struct drm_dp_mst_topology_mgr *mgr, bool up,
38643868
struct drm_dp_mst_branch **mstb)
@@ -4141,6 +4145,17 @@ static int drm_dp_mst_handle_up_req(struct drm_dp_mst_topology_mgr *mgr)
41414145
return 0;
41424146
}
41434147

4148+
static void update_msg_rx_state(struct drm_dp_mst_topology_mgr *mgr)
4149+
{
4150+
mutex_lock(&mgr->lock);
4151+
if (mgr->reset_rx_state) {
4152+
mgr->reset_rx_state = false;
4153+
reset_msg_rx_state(&mgr->down_rep_recv);
4154+
reset_msg_rx_state(&mgr->up_req_recv);
4155+
}
4156+
mutex_unlock(&mgr->lock);
4157+
}
4158+
41444159
/**
41454160
* drm_dp_mst_hpd_irq_handle_event() - MST hotplug IRQ handle MST event
41464161
* @mgr: manager to notify irq for.
@@ -4175,6 +4190,8 @@ int drm_dp_mst_hpd_irq_handle_event(struct drm_dp_mst_topology_mgr *mgr, const u
41754190
*handled = true;
41764191
}
41774192

4193+
update_msg_rx_state(mgr);
4194+
41784195
if (esi[1] & DP_DOWN_REP_MSG_RDY) {
41794196
ret = drm_dp_mst_handle_down_rep(mgr);
41804197
*handled = true;

include/drm/display/drm_dp_mst_helper.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,13 @@ struct drm_dp_mst_topology_mgr {
699699
*/
700700
bool payload_id_table_cleared : 1;
701701

702+
/**
703+
* @reset_rx_state: The down request's reply and up request message
704+
* receiver state must be reset, after the topology manager got
705+
* removed. Protected by @lock.
706+
*/
707+
bool reset_rx_state : 1;
708+
702709
/**
703710
* @payload_count: The number of currently active payloads in hardware. This value is only
704711
* intended to be used internally by MST helpers for payload tracking, and is only safe to

0 commit comments

Comments
 (0)