| From 93d0309cb1e6e1b332db85fb722ed9d11deeecd9 Mon Sep 17 00:00:00 2001 |
| From: Sasha Levin <sashal@kernel.org> |
| Date: Sat, 20 Jul 2024 18:44:02 +0530 |
| Subject: drm/amd/display: Fix index out of bounds in DCN30 degamma hardware |
| format translation |
| |
| From: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com> |
| |
| [ Upstream commit bc50b614d59990747dd5aeced9ec22f9258991ff ] |
| |
| This commit addresses a potential index out of bounds issue in the |
| `cm3_helper_translate_curve_to_degamma_hw_format` function in the DCN30 |
| color management module. The issue could occur when the index 'i' |
| exceeds the number of transfer function points (TRANSFER_FUNC_POINTS). |
| |
| The fix adds a check to ensure 'i' is within bounds before accessing the |
| transfer function points. If 'i' is out of bounds, the function returns |
| false to indicate an error. |
| |
| Reported by smatch: |
| drivers/gpu/drm/amd/amdgpu/../display/dc/dcn30/dcn30_cm_common.c:338 cm3_helper_translate_curve_to_degamma_hw_format() error: buffer overflow 'output_tf->tf_pts.red' 1025 <= s32max |
| drivers/gpu/drm/amd/amdgpu/../display/dc/dcn30/dcn30_cm_common.c:339 cm3_helper_translate_curve_to_degamma_hw_format() error: buffer overflow 'output_tf->tf_pts.green' 1025 <= s32max |
| drivers/gpu/drm/amd/amdgpu/../display/dc/dcn30/dcn30_cm_common.c:340 cm3_helper_translate_curve_to_degamma_hw_format() error: buffer overflow 'output_tf->tf_pts.blue' 1025 <= s32max |
| |
| Cc: Tom Chung <chiahsuan.chung@amd.com> |
| Cc: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com> |
| Cc: Roman Li <roman.li@amd.com> |
| Cc: Alex Hung <alex.hung@amd.com> |
| Cc: Aurabindo Pillai <aurabindo.pillai@amd.com> |
| Cc: Harry Wentland <harry.wentland@amd.com> |
| Cc: Hamza Mahfooz <hamza.mahfooz@amd.com> |
| Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com> |
| Reviewed-by: Tom Chung <chiahsuan.chung@amd.com> |
| Signed-off-by: Alex Deucher <alexander.deucher@amd.com> |
| Signed-off-by: Sasha Levin <sashal@kernel.org> |
| --- |
| drivers/gpu/drm/amd/display/dc/dcn30/dcn30_cm_common.c | 2 ++ |
| 1 file changed, 2 insertions(+) |
| |
| diff --git a/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_cm_common.c b/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_cm_common.c |
| index e0df9b0065f9c..e0b1fc92ed186 100644 |
| --- a/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_cm_common.c |
| +++ b/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_cm_common.c |
| @@ -355,6 +355,8 @@ bool cm3_helper_translate_curve_to_degamma_hw_format( |
| i += increment) { |
| if (j == hw_points - 1) |
| break; |
| + if (i >= TRANSFER_FUNC_POINTS) |
| + return false; |
| rgb_resulted[j].red = output_tf->tf_pts.red[i]; |
| rgb_resulted[j].green = output_tf->tf_pts.green[i]; |
| rgb_resulted[j].blue = output_tf->tf_pts.blue[i]; |
| -- |
| 2.43.0 |
| |