Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp798939rwl; Sun, 25 Dec 2022 07:23:12 -0800 (PST) X-Google-Smtp-Source: AMrXdXvQ5blBK5Er+mtHXmHXbZibiz403hUJupWJ3jlQmtB9ukV7oL30DjAC170+hSRVqI7EVQM8 X-Received: by 2002:a17:907:cbc7:b0:846:ccf3:d901 with SMTP id vk7-20020a170907cbc700b00846ccf3d901mr11927251ejc.52.1671981791869; Sun, 25 Dec 2022 07:23:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671981791; cv=none; d=google.com; s=arc-20160816; b=uNbgOaALagizep9+1qNSvqREHxVc27qin9fYuCFhszv7NIm0rgUd4NcHOJIC7bmKr3 Y7Okh/X1DHy8T/14m4VRe2c+FtRtm2cHio8SGS2Xau+3Bs2HI6Me0fUFeJotgNQIKU9Y 8CuZ6G41+nwNbgUG1ek8b7ZL31wJVvvBim/RGJ3ioYmUJZUu/gdNH9wTj99LXlNT2Tq0 9szHOqqVKoqt8XWQUCRQXxiG4E3MqkluTRZO7JaZlAoOQ3ccj8CXqSQ5CdB+HMimLBpP DR4r8My4nWlo+Nw3DRcqavzo5GsL8pfbui9w7nlI9Jp1YuMr4jCUdVURer40/ihoXYg7 ih8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version:date :subject:cc:to:from:message-id:dkim-signature; bh=4gyYfY5apDGW/eosN7O7fVTHYhGTtevXrZrItFuw+RY=; b=j4TPayTkf+NpkueKkjpKES4ARrGizX42IozI9kFxfCM/QD9L0KxPpSte4VQLpG5tQ+ ZHTWms3B2XiyjKXzpDVIOiYlxu3j4ZlW+FadZKx8N4s/iILg4VGqkp7NumG0NNvu10Kq 50oOJX9Avmpsv5E2ild2a0JrTFIP5ZpbyyW0WJVaQAl3PtfCgWwVYJkT7Q0qQ3VWEsg3 KODRsPFEm7jr8dvJbTNJn4m5JCU+qrQADtpZ0TZ2vrhWAYV7OLjYKMPl1hc9nZEQNi2J T5BourLk1nVtr7/RljCqmpoofGopKX6EdrTXCjAXLFdnD2YvsqPcj86pXynof1TMpII9 ZmHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=oCmK1U64; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o22-20020a170906975600b007c4f75345e1si7596796ejy.443.2022.12.25.07.22.56; Sun, 25 Dec 2022 07:23:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=oCmK1U64; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229445AbiLYPMj (ORCPT + 67 others); Sun, 25 Dec 2022 10:12:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229540AbiLYPMh (ORCPT ); Sun, 25 Dec 2022 10:12:37 -0500 Received: from out162-62-57-210.mail.qq.com (out162-62-57-210.mail.qq.com [162.62.57.210]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7354055B3 for ; Sun, 25 Dec 2022 07:12:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1671981151; bh=4gyYfY5apDGW/eosN7O7fVTHYhGTtevXrZrItFuw+RY=; h=From:To:Cc:Subject:Date; b=oCmK1U64X3go8UcSnrgV6qFnym0HtnCed4YNAPNwKfmCaLXI1yySo3kRZ68diGU1b b37ecjYL+UoOl0km5kKiLFt533fvGIjG/qZ3P+D33UVfE8JfUAtdF29/cpChCEPMF8 Xa1WojyhKF8xh1mx5Skash0OOC+5T7hVSqwUfMQ0= Received: from wen-VirtualBox.lan ([222.182.118.62]) by newxmesmtplogicsvrszc2-0.qq.com (NewEsmtp) with SMTP id 2CC05057; Sun, 25 Dec 2022 23:11:12 +0800 X-QQ-mid: xmsmtpt1671981072toki2hhed Message-ID: X-QQ-XMAILINFO: MR/iVh5QLeie/LjKgMA5F+5e/BGMMcXVUrtcQ09uXcIXZnVQf2Y9PHof42Hm7R q+XXsqJsIHOfpYJo0o4QBA5TKF3Uc2f68G9HY9qzQRS3RzjoDHtdthbpx8rG1dDCGG1B3R/WV9hY zldUkH98qcXF84DEoj23T9yQthTbJcEiN40XmEuBnnjr3xXNqjJE5LcgmH/uSYRGlbJ3W3qqn5nk u+706JgKWAODSz1tTRWoyxMQJeRUtkpey58LQ+Iw+iP3D8iDNTXU00EaYrp99nGMOsbDtolcQieT l/phISKm6/qxu+Yv1vcxRl8IZPwMtyrsklf+EMJp5AIPN0d2+0TCV+r9vY7ckVehWLLSzGs4IyJR DIXN5XVDTHOTQYFNRE6wzP8nAAbIOts9HJja6YST1Yo+vEypZrUaEhgZ6p+i+d29YhNBpinchcp4 XiCssglylaikQStP+FpxAYxgKwQO3B0s43R+q2Z/IfpZYJzMQIc8EIPRQgXnZfZUWy+a14xPBaIN +epWLj/ugm5rl9a9C8KRVL2h07+/XXdU3mhHzcPFhd+PK7ZrOAc3F3m1VcYWganATKyx2b2N+Wo/ bTVEB0LpySwjsue1liZ2WJl8k1jLaGnBeUth8PDJOhEmtqNxmNmd64UmQG9UIdxetHKHPfPwnjEe nQ9I8JJXYJJrOdx+RvawZ6U05ywm0UgUlKZSFaPnpY1fkQaQwslH8t77Wq0czQNkHLA/AvZkaGZo nTfk8CNqaw1M2nsg4X4Q7G5KG74xdBypNO459NmlSnqZoSxGHjgfLjmrLEckGuBHHFJj20Ua9XFh 4HQWNvGUjHnZzE7cu7bX/kxJ8Ef3Mf+OqtY+ZsHzRPDe4viliLz/Ps1BHmEIXDe1wc8/TNnSEM5x mkjtVLii37EdkmSf+7FlkHswi4WiaF1xY9BqB0xzfOE9Sr0nmOc0kLBDEvNweIDrKZXNCOc2DWiD Sad9Y6pZHJmrw2CubzocZDW0VkTkrhUsW1djvqn+MSrCWrHTdOi/keu3MqbCbqLyDzvN3WcSo= From: wenyang.linux@foxmail.com To: Alex Deucher , Hamza Mahfooz , Aurabindo Pillai Cc: Wen Yang , Guenter Roeck , =?UTF-8?q?Harry=C2=A0Wentland=C2=A0?= , =?UTF-8?q?Leo=C2=A0Li=C2=A0?= , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] =?UTF-8?q?drm/amd/display:=C2=A0fix=C2=A0array-bounds?= =?UTF-8?q?=C2=A0errors=C2=A0in=20dc=5Fstream=5Fremove=5Fwriteback()?= Date: Sun, 25 Dec 2022 23:10:58 +0800 X-OQ-MSGID: <20221225151058.749344-1-wenyang.linux@foxmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, HELO_DYNAMIC_IPADDR,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,RDNS_DYNAMIC, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wen Yang The following errors occurred when using gcc 7.5.0-3ubuntu1~18.04: 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:543:55: warning: array subscript is above array bounds [-Warray-bounds]      stream->writeback_info[j] = stream->writeback_info[i];                                  ~~~~~~~~~~~~~~~~~~~~~~^~~ Add a check to make sure that num_wb_info won't overflowing the writeback_info buffer. Fixes: 6fbefb84a98e ("drm/amd/display: Add DC core changes for DCN2") Signed-off-by: Wen Yang Cc: Aurabindo Pillai Cc: Hamza Mahfooz Cc: Guenter Roeck Cc: Alex Deucher Cc: Harry Wentland  Cc: Leo Li  Cc: amd-gfx@lists.freedesktop.org Cc: dri-devel@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org --- drivers/gpu/drm/amd/display/dc/core/dc_stream.c | 9 ++++++++- 1 file changed, 8 insertions(+), 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 20e534f73513..9825c30f2ca0 100644 --- a/drivers/gpu/drm/amd/display/dc/core/dc_stream.c +++ b/drivers/gpu/drm/amd/display/dc/core/dc_stream.c @@ -481,6 +481,7 @@ bool dc_stream_add_writeback(struct dc *dc, } if (!isDrc) { + ASSERT(stream->num_wb_info + 1 <= MAX_DWB_PIPES); stream->writeback_info[stream->num_wb_info++] = *wb_info; } @@ -526,6 +527,11 @@ bool dc_stream_remove_writeback(struct dc *dc, return false; } + if (stream->num_wb_info > MAX_DWB_PIPES) { + dm_error("DC: num_wb_info is invalid!\n"); + return false; + } + // stream->writeback_info[dwb_pipe_inst].wb_enabled = false; for (i = 0; i < stream->num_wb_info; i++) { /*dynamic update*/ @@ -540,7 +546,8 @@ bool dc_stream_remove_writeback(struct dc *dc, if (stream->writeback_info[i].wb_enabled) { if (j < i) /* trim the array */ - stream->writeback_info[j] = stream->writeback_info[i]; + memcpy(&stream->writeback_info[j], &stream->writeback_info[i], + sizeof(struct dc_writeback_info)); j++; } } -- 2.25.1