dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/amd/display: fix array-bounds error in dc_stream_remove_writeback()
@ 2022-09-27 19:12 Hamza Mahfooz
  2022-09-27 20:35 ` Pillai, Aurabindo
  2022-10-06  6:46 ` Guenter Roeck
  0 siblings, 2 replies; 8+ messages in thread
From: Hamza Mahfooz @ 2022-09-27 19:12 UTC (permalink / raw)
  To: linux-kernel
  Cc: Stylon Wang, amd-gfx, dri-devel, Leo Li, Paul Hsieh, Pan, Xinhui,
	Rodrigo Siqueira, Hersen Wu, David Airlie, Aurabindo Pillai,
	Alex Hung, Hamza Mahfooz, Alex Deucher, Leo (Hanghong) Ma,
	Pavle Kotarac, Christian König, Jimmy Kizito, Lee, Alvin

Address the following error:
drivers/gpu/drm/amd/amdgpu/../display/dc/core/dc_stream.c: In function ‘dc_stream_remove_writeback’:
drivers/gpu/drm/amd/amdgpu/../display/dc/core/dc_stream.c:527:55: error: array subscript [0, 0] is outside array bounds of ‘struct dc_writeback_info[1]’ [-Werror=array-bounds]
  527 |                                 stream->writeback_info[j] = stream->writeback_info[i];
      |                                 ~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from ./drivers/gpu/drm/amd/amdgpu/../display/dc/dc.h:1269,
                 from ./drivers/gpu/drm/amd/amdgpu/../display/dc/inc/core_types.h:29,
                 from ./drivers/gpu/drm/amd/amdgpu/../display/dc/basics/dc_common.h:29,
                 from drivers/gpu/drm/amd/amdgpu/../display/dc/core/dc_stream.c:27:
./drivers/gpu/drm/amd/amdgpu/../display/dc/dc_stream.h:241:34: note: while referencing ‘writeback_info’
  241 |         struct dc_writeback_info writeback_info[MAX_DWB_PIPES];
      |

Currently, we aren't checking to see if j remains within
writeback_info[]'s bounds. So, add a check to make sure that we aren't
overflowing the buffer.

Signed-off-by: Hamza Mahfooz <hamza.mahfooz@amd.com>
---
 drivers/gpu/drm/amd/display/dc/core/dc_stream.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_stream.c b/drivers/gpu/drm/amd/display/dc/core/dc_stream.c
index 3ca1592ce7ac..ae13887756bf 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc_stream.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc_stream.c
@@ -520,7 +520,7 @@ bool dc_stream_remove_writeback(struct dc *dc,
 	}
 
 	/* remove writeback info for disabled writeback pipes from stream */
-	for (i = 0, j = 0; i < stream->num_wb_info; i++) {
+	for (i = 0, j = 0; i < stream->num_wb_info && j < MAX_DWB_PIPES; i++) {
 		if (stream->writeback_info[i].wb_enabled) {
 			if (i != j)
 				/* trim the array */
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-10-11  9:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-27 19:12 [PATCH] drm/amd/display: fix array-bounds error in dc_stream_remove_writeback() Hamza Mahfooz
2022-09-27 20:35 ` Pillai, Aurabindo
2022-09-29 15:36   ` Felix Kuehling
2022-09-29 15:41     ` Hamza Mahfooz
2022-09-29 16:05       ` Felix Kuehling
2022-10-06  6:46 ` Guenter Roeck
2022-10-06 17:23   ` Guenter Roeck
2022-10-11  9:49     ` Thorsten Leemhuis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).