drm/amd/display: fix division by zero in get_estimated_bw()
Subsystems (3)
PATCH 1/1 drm/amd/display: fix division by zero in get_estimated_bw()
get_estimated_bw() divides by link->dpia_bw_alloc_config.bw_granularity, which is zeroed by reset_bw_alloc_struct() and only populated once DP_TUNNELING_BW_ALLOC_CAP_CHANGED has been handled.
link_dp_dpia_handle_bw_alloc_status(), the DPCD interrupt handler, calls get_estimated_bw() whenever DP_TUNNELING_ESTIMATED_BW_CHANGED is set, independently of whether DP_TUNNELING_BW_ALLOC_CAP_CHANGED has ever fired for that link. A connected USB4/DPIA tunneling device that reports an estimated-bandwidth change before ever reporting a capability change drives a division by zero in this IRQ path.
link_dpia_send_bw_alloc_request() already guards the same bw_granularity division; add the identical guard here rather than introducing a new pattern.
--- .../gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c +5 -0
@@ -103,6 +103,11 @@ static int get_estimated_bw(struct dc_link *link) {uint8_t bw_estimated_bw =0 ; +if (link->dpia_bw_alloc_config.bw_granularity ==0 ) { +DC_LOG_ERROR ("%s: BW granularity is zero!\n" , __func__); +return 0 ; + } + core_link_read_dpcd( link, ESTIMATED_BW,
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Uncapped request_bw is assigned to allocated_bw, causing an oversized value that leads to an integer underflow during bandwidth validation. --
--- Patch [1]: [PATCH] drm/amd/display: fix division by zero in get_estimated_bw() --- commit d3870b3b2da2897f934f4033da62b969b6443914
Author: Hari Mishal <[email protected]>
drm/amd/display: fix division by zero in get_estimated_bw()
This commit fixes a division by zero in get_estimated_bw() by returning 0 if bw_granularity is zero. This prevents a crash when a connected DPIA device reports an estimated bandwidth change before reporting a capability change.
Quoted 3 lines
link_dpia_send_bw_alloc_request()already guards the samebw_granularitydivision; add the identical guard here rather than introducing a new pattern.
[Severity: High]
This is a pre-existing issue, but since the commit message references link_dpia_send_bw_alloc_request(), I noticed a potential integer underflow issue involving allocated_bw.
In link_dpia_send_bw_alloc_request(), the uncapped request_bw variable is assigned to allocated_bw:
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c:link_dpia_send_bw_alloc_request() {
...
temp = req_bw * link->dpia_bw_alloc_config.bw_granularity;
request_reg_val = temp / Kbps_TO_Gbps;
if (temp % Kbps_TO_Gbps)
++request_reg_val;
}
link->dpia_bw_alloc_config.allocated_bw = request_bw;
...
}Later, in link_dpia_validate_dp_tunnel_bandwidth(), remaining_bw is calculated using unsigned 32-bit subtraction:
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c:link_dpia_validate_dp_tunnel_bandwidth() {
...
if (router_sets[j].cm_id == dp_tunnel_settings->cm_id) {
uint32_t remaining_bw =
dp_tunnel_settings->estimated_bw - dp_tunnel_settings->allocated_bw;
...
}If a connected DPIA display requests more bandwidth than estimated, allocated_bw will be strictly greater than estimated_bw.
Could this cause the subtraction to underflow to an extremely large positive value (~4.29 billion), thereby bypassing the subsequent capacity checks (required_bw > total_bw) and allowing illegal configurations that oversubscribe the DP tunnel?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Weekly promotion tests found no regression.
This patch is
Quoted 42 lines · Hari Mishal
[Some people who received this message don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
get_estimated_bw()divides bylink->dpia_bw_alloc_config.bw_granularity, which is zeroed byreset_bw_alloc_struct()and only populated onceDP_TUNNELING_BW_ALLOC_CAP_CHANGEDhas been handled.
link_dp_dpia_handle_bw_alloc_status(), the DPCD interrupt handler, callsget_estimated_bw()wheneverDP_TUNNELING_ESTIMATED_BW_CHANGEDis set, independently of whetherDP_TUNNELING_BW_ALLOC_CAP_CHANGEDhas ever fired for that link. A connected USB4/DPIA tunneling device that reports an estimated-bandwidth change before ever reporting a capability change drives a division by zero in this IRQ path.
link_dpia_send_bw_alloc_request()already guards the samebw_granularitydivision; add the identical guard here rather than introducing a new pattern.Fixes 8e5cfe547bf3 ("drm/amd/display: upstream link_dp_dpia_bw.c")Assisted-by gkh_clanker_t1000Signed-off-by Hari Mishal <[email protected]>--- .../gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c +5
-1@@ -103,6 +103,11 @@ static int get_estimated_bw(struct dc_link *link) {uint8_t bw_estimated_bw =0 ; +if (link->dpia_bw_alloc_config.bw_granularity ==0 ) { +DC_LOG_ERROR ("%s: BW granularity is zero!\n" , __func__); +return 0 ; + } + core_link_read_dpcd( link, ESTIMATED_BW, --2.43.0