Received: by 2002:a05:7412:1492:b0:e2:908c:2ebd with SMTP id s18csp18881rdh; Mon, 21 Aug 2023 06:36:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFCBk73hvFJg0O/ktVoxEwjHvCuk1p85x3BqVtDjVuETF7gwU9sygAhLlsOLgRT/4UUpfrh X-Received: by 2002:a05:6402:1a33:b0:523:100b:462b with SMTP id be19-20020a0564021a3300b00523100b462bmr4996696edb.5.1692625019617; Mon, 21 Aug 2023 06:36:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692625019; cv=none; d=google.com; s=arc-20160816; b=VuV75LhfBqDRBAIBwksG0W2ySSQ2FIvOvYy11UY0sL1KRYvIgJ4WgCey4z34iGusWd qd9FLQOVk6hVIjA0rlVoPUnskOgSKoRthjZBl4ct+cp82vxX3d6N23qaMSKh/kEQ325y IqH5M1C8tclZzC/tt1OXZXq+Uya+vSchtY6vYxVpE//ERcZIh5q5ZpZYApuPKXXhZVD2 O3OEh82vT9TR1OSzDl8x5yxVNuWlsf3DJBnRJeEexlpWp+1AURFoDZdFkdMD16yHpK0f WB3W1swhwutt6TfiMLjZNvQg8zffaTs07mDwuknn6zKDjEvznvg4eaM9QCv9v89a4xAQ KY7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from:cc:to :content-language:subject:user-agent:mime-version:date:message-id; bh=EG/jO1C106HDJDiMVIelI5dzQ7hs6K7ApIVdomQlpAM=; fh=sXR7lIQhEoEfCTqLtdDjKxTrn9NhjTzHnahvxubSJjQ=; b=MdoYSa3jhGhkh3Rzh080SMMLIcc8ZRX3Dd4KM1MoKnljHcqzxCJjT3F81AlI9HARg/ viyGhycvTF0z1J1Dye17SjR80kSiABKF6KRA6nCEDlndPoKKSw238L6ZJBOwmAOZFOzF cCxUoQB/qFHjHVQ4ceN53Js5iR65s8pU+vU3JDRCSFPUYQgoFho8ZP7bosTU16Hv2F5I ghRjKSyG2fMmDJaGZ86tKhDhKc4DtasH7CGLnESNg2YsnfLsWxVb7uPE2ps9If6gGSxt T8jWgESnTYingNHQn18gRotgC9/E0yIrHWyW/U/s3Nwva43QqPVuuXEE5q9WpgM4STaE 6FQg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m5-20020aa7c2c5000000b005233d031616si5923578edp.556.2023.08.21.06.36.34; Mon, 21 Aug 2023 06:36:59 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233065AbjHUGwm (ORCPT + 99 others); Mon, 21 Aug 2023 02:52:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229721AbjHUGwl (ORCPT ); Mon, 21 Aug 2023 02:52:41 -0400 Received: from mail.nfschina.com (unknown [42.101.60.195]) by lindbergh.monkeyblade.net (Postfix) with SMTP id C187EAD; Sun, 20 Aug 2023 23:52:38 -0700 (PDT) Received: from [172.30.11.106] (unknown [180.167.10.98]) by mail.nfschina.com (Maildata Gateway V2.8.8) with ESMTPSA id E04366061F6CA; Mon, 21 Aug 2023 14:52:34 +0800 (CST) Message-ID: Date: Mon, 21 Aug 2023 14:52:34 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH] drm/amdgpu: Avoid possible buffer overflow Content-Language: en-US To: Christophe JAILLET , alexander.deucher@amd.com, christian.koenig@amd.com, Xinhui.Pan@amd.com, airlied@gmail.com, daniel@ffwll.ch Cc: Hawking.Zhang@amd.com, le.ma@amd.com, lijo.lazar@amd.com, yifan1.zhang@amd.com, candice.li@amd.com, Yuliang.Shi@amd.com, guchun.chen@amd.com, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org X-MD-Sfrom: suhui@nfschina.com X-MD-SrcIP: 180.167.10.98 From: Su Hui In-Reply-To: <7ac675b6-a000-6ad7-36f3-a3ce186414b6@wanadoo.fr> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,RDNS_NONE, 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 On 2023/8/21 14:47, Christophe JAILLET wrote: > Le 21/08/2023 à 08:19, Su Hui a écrit : >> smatch error: >> drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c:1257 >> amdgpu_discovery_reg_base_init() error: >> testing array offset 'adev->vcn.num_vcn_inst' after use. >> >> change the assignment order to avoid buffer overflow. >> >> Fixes: c40bdfb2ffa4 ("drm/amdgpu: fix incorrect VCN revision in SRIOV") >> Signed-off-by: Su Hui >> --- >>   drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 5 +++-- >>   1 file changed, 3 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c >> b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c >> index 8e1cfc87122d..ba95526c3d45 100644 >> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c >> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c >> @@ -1250,11 +1250,12 @@ static int >> amdgpu_discovery_reg_base_init(struct amdgpu_device *adev) >>                    *     0b10 : encode is disabled >>                    *     0b01 : decode is disabled >>                    */ >> - adev->vcn.vcn_config[adev->vcn.num_vcn_inst] = >> -                    ip->revision & 0xc0; >> + >>                   ip->revision &= ~0xc0; >>                   if (adev->vcn.num_vcn_inst < >>                       AMDGPU_MAX_VCN_INSTANCES) { >> + adev->vcn.vcn_config[adev->vcn.num_vcn_inst] = >> +                        ip->revision & 0xc0; > > Hi, > I don't think that the patch is correct. > > Because of the "ip->revision &= ~0xc0" which is now above it, > "ip->revision & 0xc0" should now always be 0. > > Maybe both lines should be moved within the "if"? > > CJ Hi, Oh, really sorry for this, I just missed this line. you are right, I will send v2 soon. Thanks for your reminder! Su Hui > > > > > >> adev->vcn.num_vcn_inst++; >>                       adev->vcn.inst_mask |= >>                           (1U << ip->instance_number); >