drm/amd/display: Validate max_fclk_mhz in DML2 policy builder
PATCH 1/1 drm/amd/display: Validate max_fclk_mhz in DML2 policy builder
dml2_policy_build_synthetic_soc_states() validates that several derived maximum clock values are non-zero before constructing synthetic SOC states.
However, max_fclk_mhz is not included in the validation despite later logic assuming the presence of at least one valid FCLK level. If all FCLK entries are zero, num_fclk_dpms remains zero, causing an integer underflow (0 - 1) and out-of-bounds array access.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- drivers/gpu/drm/amd/display/dc/dml2_0/dml2_policy.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/dml2_0/dml2_policy.c +2 -1
@@ -157,7 +157,8 @@ int dml2_policy_build_synthetic_soc_states(struct dml2_policy_build_synthetic_so num_uclk_dpms++; } -if (!max_dcfclk_mhz || !max_dispclk_mhz || !max_dppclk_mhz || !max_phyclk_mhz || !max_dtbclk_mhz) +if (!max_dcfclk_mhz || !max_dispclk_mhz || !max_dppclk_mhz || !max_phyclk_mhz || + !max_dtbclk_mhz || !max_fclk_mhz)return -1 ; p->out_states->num_states =0 ;
Signature · 1 line
2.25.1
[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] Missing bounds check in insert_entry_into_table_sorted allows array out-of-bounds write. --
commit 803110810943a93ffdbd8a40adba9348d5b58b1b
Author: Danila Chernetsov <[email protected]>
drm/amd/display: Validate max_fclk_mhz in DML2 policy builder
This commit adds a validation check for max_fclk_mhz to prevent an integer underflow and out-of-bounds array access when all FCLK entries are zero.
Quoted 5 lines
drivers/gpu/drm/amd/display/dc/dml2_0/dml2_policy.c +0
-0
drivers/gpu/drm/amd/display/dc/dml2_0/dml2_policy.c int dml2_policy_build_synthetic_soc_states(struct dml2_policy_build_synthetic_so · line 164
Quoted 9 lines
drivers/gpu/drm/amd/display/dc/dml2_0/dml2_policy.c +2
-1@@ -157,7 +157,8 @@ int dml2_policy_build_synthetic_soc_states(struct dml2_policy_build_synthetic_so num_uclk_dpms++; } -if (!max_dcfclk_mhz || !max_dispclk_mhz || !max_dppclk_mhz || !max_phyclk_mhz || !max_dtbclk_mhz) +if (!max_dcfclk_mhz || !max_dispclk_mhz || !max_dppclk_mhz || !max_phyclk_mhz || + !max_dtbclk_mhz || !max_fclk_mhz)return -1 ; p->out_states->num_states =0 ;
[Severity: High]
This isn't a bug introduced by this patch, but can the subsequent state insertions overflow the out_states array?
Looking at dml2_policy_build_synthetic_soc_states(), it calls insert_entry_into_table_sorted() multiple times:
// Insert all the DCFCLK STAs first
for (i = 0; i < p->num_dcfclk_stas; i++) {
...
insert_entry_into_table_sorted(p->in_bbox, p->out_states, &s->entry);
}
// Insert the UCLK DPMS
for (i = 0; i < num_uclk_dpms; i++) {
...
insert_entry_into_table_sorted(p->in_bbox, p->out_states, &s->entry);
}
// Insert FCLK DPMs (if present)
if (num_fclk_dpms > 2) {
for (i = 0; i < num_fclk_dpms; i++) {
...
insert_entry_into_table_sorted(p->in_bbox, p->out_states, &s->entry);
}
}If num_uclk_dpms and num_fclk_dpms can each be derived from the 30-element input array, the combined insertions could exceed __DML_MAX_STATE_ARRAY_SIZE__.
Inside insert_entry_into_table_sorted(), elements are shifted without a bounds check:
for (i = table->num_states; i > index; i--) {
table->state_array[i] = table->state_array[i - 1];
}
...
table->num_states++;Could this write past the end of table->state_array if the total number of inserted states across these loops exceeds 30?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 62 lines · On 07/06/2026 00:50, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing bounds check ininsert_entry_into_table_sortedallows array out-of-bounds write. --commit
803110810943a93ffdbd8a40adba9348d5b58b1b
Author: Danila Chernetsov <[email protected]>drm/amd/display: Validate
max_fclk_mhzin DML2 policy builderThis commit adds a validation check for
max_fclk_mhzto prevent an integer underflow and out-of-bounds array access when all FCLK entries are zero.Quoted 5 lines
drivers/gpu/drm/amd/display/dc/dml2_0/dml2_policy.c +0
-0drivers/gpu/drm/amd/display/dc/dml2_0/dml2_policy.c int dml2_policy_build_synthetic_soc_states(struct dml2_policy_build_synthetic_so · line 164
Quoted 9 lines
drivers/gpu/drm/amd/display/dc/dml2_0/dml2_policy.c +2
-1@@ -157,7 +157,8 @@ int dml2_policy_build_synthetic_soc_states(struct dml2_policy_build_synthetic_so num_uclk_dpms++; } -if (!max_dcfclk_mhz || !max_dispclk_mhz || !max_dppclk_mhz || !max_phyclk_mhz || !max_dtbclk_mhz) +if (!max_dcfclk_mhz || !max_dispclk_mhz || !max_dppclk_mhz || !max_phyclk_mhz || + !max_dtbclk_mhz || !max_fclk_mhz)return -1 ; p->out_states->num_states =0 ;[Severity: High]
This isn't a bug introduced by this patch, but can the subsequent state insertions overflow theout_statesarray?Looking at
dml2_policy_build_synthetic_soc_states(), it callsinsert_entry_into_table_sorted()multiple times:// Insert all the DCFCLK STAs first for (i = 0; i < p->num_dcfclk_stas; i++) { ... insert_entry_into_table_sorted(p->in_bbox, p->out_states, &s->entry); } // Insert the UCLK DPMS for (i = 0; i < num_uclk_dpms; i++) { ... insert_entry_into_table_sorted(p->in_bbox, p->out_states, &s->entry); } // Insert FCLK DPMs (if present) if (num_fclk_dpms > 2) { for (i = 0; i < num_fclk_dpms; i++) { ... insert_entry_into_table_sorted(p->in_bbox, p->out_states, &s->entry); } }If
num_uclk_dpmsandnum_fclk_dpmscan each be derived from the 30-element input array, the combined insertions could exceed__DML_MAX_STATE_ARRAY_SIZE__.Inside
insert_entry_into_table_sorted(), elements are shifted without a bounds check:
Quoted 9 lines
for (i = table->num_states; i > index; i--) { table->state_array[i] = table->state_array[i - 1]; } ... table->num_states++;Could this write past the end of
table->state_arrayif the total number of inserted states across these loops exceeds 30?
Thanks for the review. Both reported issues are pre-existing in the codebase and are completely unrelated to my changes. This patch does not introduce, touch, or modify this logic. I request the maintainers to review my patch as is.
Best regards,
Danila Chernetsov