Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1474550rwb; Thu, 1 Dec 2022 18:34:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf5TXVXhS6uFJrpw0xVP0Ii37CBI5kEkRCa0CSZ0s2LHADbNVZRcpdZ6uCf3VM7nzF+ncTGu X-Received: by 2002:aa7:cd04:0:b0:46b:34c:5574 with SMTP id b4-20020aa7cd04000000b0046b034c5574mr23706781edw.175.1669948441292; Thu, 01 Dec 2022 18:34:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669948441; cv=none; d=google.com; s=arc-20160816; b=riKolHCvDPxqN7dZJFmbQNI/cxfut63iDV/WUd8rGzYw5nkuoyakQvXcwIHJ70aRGL uMzmhPI2w85TAig57dJ6TJpTaccV5xTn5z1+AmULaCXfN/gRx7ih9X3q0G8XNkbtUlLw ULp67swy3rMnnMpj9sy2rLr8LVfE0/ol9EM1JrmgEZCJIyyb3n208OWjPoitOKxxZo1T a46c/WkzWhRGS5d3u6QIaK06lPQYcAH5kZsYpp+SEGp8XNzBYbQkJ5HCdLrezpYpX6Nn lX9OHqWs2Ny0BU/JmShwByCWZY4RdUDazjZRH1gziTi/51cUWCEV+nxne4JLYaWjXlHe jRFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=RiW+fWhLHmUVpOMO7lKyMi/AYhlrJsUPo4MbabAxkGo=; b=uKLFXK0AwUa5Z4ovEWA3xvTx3JR/Z5UagyBRIgCcOqISByXDk+8fE6svF7mTibAip1 DRHSUcGFTGAX3MIE32ibhiTTJuj+L0UrfFogdJxSqbTbg2/cxD9+YGklUk7YwVJqlHeh YkGQKhTXLvjhfOiWWYQuTxO900b20C69UsYwbHiTbWnNVF4cJ9mkYVLnkB69uHYtqVGG GjVDzk9pxbHBm/FkA/3rt6n4SViOc/oQTZTyikwqsjuCLtyEwWRdTsWKYXn2PGvl0bcA SFi0XZ9fjhqbAuLneWIkd7hiHtalqAWJ+ULZw6Xu+xA/506j5BZnnfGoWuHALBRO19Gd 3gTw== 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k3-20020aa7d2c3000000b004602a1b7da9si4720669edr.133.2022.12.01.18.33.40; Thu, 01 Dec 2022 18:34:01 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231465AbiLBBkF (ORCPT + 81 others); Thu, 1 Dec 2022 20:40:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230185AbiLBBjt (ORCPT ); Thu, 1 Dec 2022 20:39:49 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B77AA4308; Thu, 1 Dec 2022 17:39:48 -0800 (PST) Received: from canpemm500006.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4NNbBY1b9zzJp4h; Fri, 2 Dec 2022 09:36:21 +0800 (CST) Received: from [10.174.179.200] (10.174.179.200) by canpemm500006.china.huawei.com (7.192.105.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 2 Dec 2022 09:39:45 +0800 Subject: Re: [PATCH net 2/2] octeontx2-pf: Fix a potential double free in otx2_sq_free_sqbs() To: Paolo Abeni , , , , , , , , CC: References: <047b210eb3b3a2e26703d8b0570a0a017789c169.1669361183.git.william.xuanziyang@huawei.com> From: "Ziyang Xuan (William)" Message-ID: <1a39ec51-0879-a17f-7f4c-4ca0edbeb2a7@huawei.com> Date: Fri, 2 Dec 2022 09:39:45 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.200] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To canpemm500006.china.huawei.com (7.192.105.130) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 > Hello, > > On Fri, 2022-11-25 at 15:45 +0800, Ziyang Xuan wrote: >> otx2_sq_free_sqbs() will be called twice when goto "err_free_nix_queues" >> label in otx2_init_hw_resources(). The first calling is within >> otx2_free_sq_res() at "err_free_nix_queues" label, and the second calling >> is at later "err_free_sq_ptrs" label. >> >> In otx2_sq_free_sqbs(), If sq->sqb_ptrs[i] is not 0, the memory page it >> points to will be freed, and sq->sqb_ptrs[i] do not be assigned 0 after >> memory page be freed. If otx2_sq_free_sqbs() is called twice, the memory >> page pointed by sq->sqb_ptrs[i] will be freeed twice. To fix the bug, >> assign 0 to sq->sqb_ptrs[i] after memory page be freed. >> >> Fixes: caa2da34fd25 ("octeontx2-pf: Initialize and config queues") >> Signed-off-by: Ziyang Xuan >> --- >> drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 1 + >> 1 file changed, 1 insertion(+) >> >> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c >> index 9e10e7471b88..5a25fe51d102 100644 >> --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c >> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c >> @@ -1146,6 +1146,7 @@ void otx2_sq_free_sqbs(struct otx2_nic *pfvf) >> DMA_FROM_DEVICE, >> DMA_ATTR_SKIP_CPU_SYNC); >> put_page(virt_to_page(phys_to_virt(pa))); >> + sq->sqb_ptrs[sqb] = 0; > > The above looks not needed... >> } >> sq->sqb_count = 0; > > ... as this will prevent the next invocation of otx2_sq_free_sqbs() > from traversing and freeing any sq->sqb_ptrs[] element. Yes, you are right. I did pay much attention to sq->sqb_ptrs[], and omitted the for loop condition. Thank you! > > Cheers, > > Paolo >> } > > > . >