From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7AC54C433F5 for ; Sun, 9 Oct 2022 23:57:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D145410E5FE; Sun, 9 Oct 2022 23:57:51 +0000 (UTC) Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id E2DD410E5FD; Sun, 9 Oct 2022 23:57:47 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 99F8BB80DDF; Sun, 9 Oct 2022 23:57:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45AD7C43141; Sun, 9 Oct 2022 23:57:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665359865; bh=53Kx9p1JunFuha73ZI0vJqmUjAwzpNLy4hgWi6hm6KY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J/fn43i6Z0se8LFm9tq1eCLcBQKjStxe574WxUQ5odmjkfI3avVxDZaV/ltoELFAK JNOsrJsxfQyys4Y9DTDU6Xz0FDRe5i0jOqZf+0LBVKzEVnrMgbEGbiEPw076I/26Qi TsrT88zGZVr0rshkrG1elmpYWmrqccdV6Gr4s3p1fihA6U8nZZSsafoddEToCkWWp0 MLx5hK52mBAOgwAkKvrjQgHziuTbw3vaqcbgshSM/RI3wzcBrBJ1sanvM1we+B4eKe VcnH0nhC/JDUYCeNEEQtbFhd3s0hWh5eWf/zb4v8/7j0q6g/lJ3SniCCz86H7ViInG /jRsuRs4JZSNw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 14/14] drm/amd/display: fix array-bounds error in dc_stream_remove_writeback() Date: Sun, 9 Oct 2022 19:57:10 -0400 Message-Id: <20221009235710.1231937-14-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221009235710.1231937-1-sashal@kernel.org> References: <20221009235710.1231937-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sasha Levin , amd-gfx@lists.freedesktop.org, sunpeng.li@amd.com, airlied@gmail.com, dri-devel@lists.freedesktop.org, Xinhui.Pan@amd.com, Rodrigo.Siqueira@amd.com, hersenwu@amd.com, alex.hung@amd.com, Aurabindo Pillai , paul.hsieh@amd.com, Hamza Mahfooz , daniel@ffwll.ch, Alex Deucher , hanghong.ma@amd.com, Pavle.Kotarac@amd.com, harry.wentland@amd.com, christian.koenig@amd.com, Jimmy.Kizito@amd.com, Alvin.Lee2@amd.com Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" From: Hamza Mahfooz [ Upstream commit 5d8c3e836fc224dfe633e41f7f2856753b39a905 ] 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. Reviewed-by: Aurabindo Pillai Signed-off-by: Hamza Mahfooz Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- 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 bb09243758fe..95d36cb79e28 100644 --- a/drivers/gpu/drm/amd/display/dc/core/dc_stream.c +++ b/drivers/gpu/drm/amd/display/dc/core/dc_stream.c @@ -458,7 +458,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.35.1