Skip to contentSkip to conversation

drm/amd/display: Avoid reading audio pattern past AUDIO_CHANNELS_COUNT

PATCH In review Harry Wentland 2 participants 3 messages Apr 28, 2022

Subsystems (3)
lore
Share & tools
lore

Harry Wentland

author maintainer
#0 lore raw

PATCH 1/1 drm/amd/display: Avoid reading audio pattern past AUDIO_CHANNELS_COUNT

A faulty receiver might report an erroneous channel count. We should guard against reading beyond AUDIO_CHANNELS_COUNT as that would overflow the dpcd_pattern_period array.

---
 drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c +1 -1
index c15c46b81111..55a5a6a49fe2 100644
@@ -4464,7 +4464,7 @@ static void dp_test_get_audio_test_data(struct dc_link *link, bool disable_video
 		&dpcd_pattern_type.value,
 		sizeof(dpcd_pattern_type));
 
-	channel_count = dpcd_test_mode.bits.channel_count + 1;
+	channel_count = min(dpcd_test_mode.bits.channel_count + 1, AUDIO_CHANNELS_COUNT);
 
 	// read pattern periods for requested channels when sawTooth pattern is requested
 	if (dpcd_pattern_type.value == AUDIO_TEST_PATTERN_SAWTOOTH ||
Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Harry Wentland

A faulty receiver might report an erroneous channel count. We should guard against reading beyond AUDIO_CHANNELS_COUNT as that would overflow the dpcd_pattern_period array.

Quoted 20 lines
---
 drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c +1 -2
index c15c46b81111..55a5a6a49fe2 100644
@@ -4464,7 +4464,7 @@ static void dp_test_get_audio_test_data(struct dc_link *link, bool disable_video
                &dpcd_pattern_type.value,
                sizeof(dpcd_pattern_type));
 
-       channel_count = dpcd_test_mode.bits.channel_count + 1;
+       channel_count = min(dpcd_test_mode.bits.channel_count + 1, AUDIO_CHANNELS_COUNT);
 
        // read pattern periods for requested channels when sawTooth pattern is requested
        if (dpcd_pattern_type.value == AUDIO_TEST_PATTERN_SAWTOOTH ||
--

2.35.1

author maintainer
#2 lore raw
Quoted 9 lines · Alex Deucher
Quoted 6 lines · Harry Wentland

A faulty receiver might report an erroneous channel count. We should guard against reading beyond AUDIO_CHANNELS_COUNT as that would overflow the dpcd_pattern_period array.

Thanks. Merged.

Harry

Quoted 21 lines
Quoted 21 lines
---
 drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c +1 -2
index c15c46b81111..55a5a6a49fe2 100644
@@ -4464,7 +4464,7 @@ static void dp_test_get_audio_test_data(struct dc_link *link, bool disable_video
                &dpcd_pattern_type.value,
                sizeof(dpcd_pattern_type));
 
-       channel_count = dpcd_test_mode.bits.channel_count + 1;
+       channel_count = min(dpcd_test_mode.bits.channel_count + 1, AUDIO_CHANNELS_COUNT);
 
        // read pattern periods for requested channels when sawTooth pattern is requested
        if (dpcd_pattern_type.value == AUDIO_TEST_PATTERN_SAWTOOTH ||
--

2.35.1