Message ID | 047b210eb3b3a2e26703d8b0570a0a017789c169.1669361183.git.william.xuanziyang@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3835236wrr; Thu, 24 Nov 2022 23:51:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf4GeE+NYIGp6mTUBDbgToDdAVYp3ZgLWJFASPbfYS/xmSs1OMCPLzOKLbmCtHjWsdmgJBch X-Received: by 2002:aa7:cc93:0:b0:462:6b8e:1ddb with SMTP id p19-20020aa7cc93000000b004626b8e1ddbmr32854040edt.276.1669362667883; Thu, 24 Nov 2022 23:51:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669362667; cv=none; d=google.com; s=arc-20160816; b=vgICFofQh9nggoy4A29UjaNOd4DMjA3cnoUJHzeV2DE8jaX8InoncgXPWPiWvaCbxp YP/AEIj5lbwbL+QUjcD48iTEoMyLLZX8BsM1B0SD8611HOZGWAfTm4htIaYp84L9572R phG7eTDn6xrhKOjG0dGYQGb7qvZ4ZVtLfRyrNiboqG0gFUKEx7Ryd2OxdA0cXEGRY4nD 5rInDLMfP4Yf3tzZ+or3DZ4+8VGK0GAlL5Xkke6tkQdvwgISd5iu6rAlTHxgGze0aDR4 0k7LYUYJp/VR8ZceO+ly0J2vMx4RQxJL70SiphIh6DBHbEUfbgDKsqXiWUXby8rL/9AO GM4Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=PrzDgDZopwC9XNcysEL4fsooZp/6hfBDRWV6LFo8mfM=; b=au3z76bfeUpSpApz5aX87YiRLRv/niRfaF9cRrWz5K3fu0sbJYdF9pOaxVcQSlaPuq H92aVA1rQQES5vJuwoC4zuQH5xaWLeqv9pOcugdR2phj42MIMARngOCZ/7+6qfQJRTjD 4kS1dGqJJB0hWe/P0TsWG8FOAOh7UNs3qyZVPECOgJpNMymGP7kr8HUE3y+in0xKhjSv ReL7S2DSThHJm3a9IuMNZkrUMzP/QkdWCA8bEhaxdKabIfc3LI/cj3/iWlQTYQ7X/fqd 8VF+rUY2my3pKkPn/y4qkoJ1SbjmwmiUeTTU5nFHKs3pdYCxHCDWZR4eUaq37A+3f7KQ CVtQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dr4-20020a170907720400b0078db8fe2834si2683930ejc.245.2022.11.24.23.50.44; Thu, 24 Nov 2022 23:51:07 -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 S229668AbiKYHp6 (ORCPT <rfc822;zxc52fgh@gmail.com> + 99 others); Fri, 25 Nov 2022 02:45:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229758AbiKYHpx (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 25 Nov 2022 02:45:53 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0DCF2F03F; Thu, 24 Nov 2022 23:45:52 -0800 (PST) Received: from canpemm500006.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NJRjS6j9nz15Mr5; Fri, 25 Nov 2022 15:45:16 +0800 (CST) Received: from localhost.localdomain (10.175.104.82) 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, 25 Nov 2022 15:45:49 +0800 From: Ziyang Xuan <william.xuanziyang@huawei.com> To: <sgoutham@marvell.com>, <gakula@marvell.com>, <sbhatta@marvell.com>, <hkelam@marvell.com>, <davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>, <pabeni@redhat.com>, <netdev@vger.kernel.org> CC: <linux-kernel@vger.kernel.org> Subject: [PATCH net 2/2] octeontx2-pf: Fix a potential double free in otx2_sq_free_sqbs() Date: Fri, 25 Nov 2022 15:45:46 +0800 Message-ID: <047b210eb3b3a2e26703d8b0570a0a017789c169.1669361183.git.william.xuanziyang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <cover.1669361183.git.william.xuanziyang@huawei.com> References: <cover.1669361183.git.william.xuanziyang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.82] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500006.china.huawei.com (7.192.105.130) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750453628735078185?= X-GMAIL-MSGID: =?utf-8?q?1750453628735078185?= |
Series |
octeontx2-pf: Fix several bugs in exception paths
|
|
Commit Message
Ziyang Xuan
Nov. 25, 2022, 7:45 a.m. UTC
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 <william.xuanziyang@huawei.com>
---
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 1 +
1 file changed, 1 insertion(+)
Comments
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 <william.xuanziyang@huawei.com> > --- > 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. Cheers, Paolo > }
> 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 <william.xuanziyang@huawei.com> >> --- >> 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 >> } > > > . >
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; } sq->sqb_count = 0; }