Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp120637imw; Mon, 4 Jul 2022 06:20:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v9hqBvvbcO+sJYgt35bsvnn4HC/mbR7xBTcIVKLO5PKNxJyhLhOHVG4MacVl8ywBm3lJoa X-Received: by 2002:a17:906:794e:b0:726:3fbb:5761 with SMTP id l14-20020a170906794e00b007263fbb5761mr28214858ejo.346.1656940845747; Mon, 04 Jul 2022 06:20:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656940845; cv=none; d=google.com; s=arc-20160816; b=cmJo+mJPsJAjprlLR/ZMKwXt776E1vqr/EsTjdwVyeLO47Fh7qLwpjcB+saAt1YEqh s+DZt4og0qN2XxmazA9gETKWQB+TlM38yP22tBNTy4kftC6w+CaGGim/QgA5Ivfp4Jao Hjz8MfHsmYeVebqQb3O2OyoPD3Vi0F64eJk4DTPne9ljl+4VjFE+9orZ6PQT08+CgF3S D3QhExMfrKptWU57vET3c7yZPJF7+YQCe3SSiD98p3yupafr4F0zxf7h696iSafZN7xM BXdBAvhZpLSYW6EJJjW5wJhrazdHPu1QVPxQ2nrtRu3X4695L15Kn9Fg4JlW7Cr9KQH4 IFSg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=I8+m1YAsVZ4gl1y1umKlRTUNyEHJgsOKvTyV1H7WmOY=; b=VYXCmS7Grm4xPABNMvmgIVbYkULtFOWFCPV0mFVFrIB91P2H/NA6pL7pkSGutbpH0q XxLpUvfltq3vX84bsy9n8q2v3ufTFtbswTnrE+954mAcVyxVvwGGzJu+B/Wg9hflkGv3 hEfL55VkUp57LBBcXTbzz70ncalYVnl5JWGuh/ib7iF4S0frRmX/oQlBihVQUC7THdkD DLC3AF12XzYarvX0WrMAqyv+s8VRyyh5Cl1YUjQ+gsMg4W56NnbNIyciyFWNbBfrRalG q0D7hbVmALZYQQ+KTN8HoKqEtuj2M+toRmOzjGFlKvysEeT46u088eAAOwgGVWmKzi0Z kKlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=a7yHIyd+; 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=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jr2-20020a170906a98200b007277dd43476si4534429ejb.347.2022.07.04.06.20.14; Mon, 04 Jul 2022 06:20:45 -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; dkim=pass header.i=@163.com header.s=s110527 header.b=a7yHIyd+; 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=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234457AbiGDMdf (ORCPT + 99 others); Mon, 4 Jul 2022 08:33:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233824AbiGDMdd (ORCPT ); Mon, 4 Jul 2022 08:33:33 -0400 X-Greylist: delayed 1886 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 04 Jul 2022 05:33:31 PDT Received: from mail-m975.mail.163.com (mail-m975.mail.163.com [123.126.97.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1F15D110A; Mon, 4 Jul 2022 05:33:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=I8+m1 YAsVZ4gl1y1umKlRTUNyEHJgsOKvTyV1H7WmOY=; b=a7yHIyd+riruU9BRhBA3c QjZM9E+QfId6cMC/g7FBzsYIQLux1c4EoMi10gSb+L5u1RWRSW2KEybR1NpOsCWy urjRBkg0aWk2iaI3tQf2oVEAaMQ/cN4OYbmNrP7jFyrI/Ix8jLKNGh5cY/qWmoI2 vhDkX1Y9e8NABbDJvXJWW4= Received: from localhost.localdomain (unknown [123.112.69.106]) by smtp5 (Coremail) with SMTP id HdxpCgBHyTYB3sJix5uRMQ--.31990S4; Mon, 04 Jul 2022 20:33:11 +0800 (CST) From: Jianglei Nie To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jianglei Nie Subject: [PATCH] net: macsec: fix potential resource leak in macsec_add_rxsa() and macsec_add_txsa() Date: Mon, 4 Jul 2022 20:33:04 +0800 Message-Id: <20220704123304.2239147-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: HdxpCgBHyTYB3sJix5uRMQ--.31990S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ar4rWF4fCF17Zw1xZr43ZFb_yoW8Jw4Dpa 15ZwsrCF1qqrWI93ZrCw4UWF1rXayUtryagry7C3yfua4kJw1rWFy0kFyI9Fy5AryxGF48 ZrWvyr47AFn8C37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRxOz-UUUUU= X-Originating-IP: [123.112.69.106] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/xtbBOQU0jF-POU5l6QABsu X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 init_rx_sa() allocates relevant resource for rx_sa->stats and rx_sa-> key.tfm with alloc_percpu() and macsec_alloc_tfm(). When some error occurs after init_rx_sa() is called in macsec_add_rxsa(), the function released rx_sa with kfree() without releasing rx_sa->stats and rx_sa-> key.tfm, which will lead to a resource leak. We should call macsec_rxsa_put() instead of kfree() to decrease the ref count of rx_sa and release the relevant resource if the refcount is 0. The same bug exists in macsec_add_txsa() for tx_sa as well. This patch fixes the above two bugs. Signed-off-by: Jianglei Nie --- drivers/net/macsec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c index 817577e713d7..ac3ff624a8dd 100644 --- a/drivers/net/macsec.c +++ b/drivers/net/macsec.c @@ -1842,7 +1842,7 @@ static int macsec_add_rxsa(struct sk_buff *skb, struct genl_info *info) return 0; cleanup: - kfree(rx_sa); + macsec_rxsa_put(rx_sa); rtnl_unlock(); return err; } @@ -2085,7 +2085,7 @@ static int macsec_add_txsa(struct sk_buff *skb, struct genl_info *info) cleanup: secy->operational = was_operational; - kfree(tx_sa); + macsec_txsa_put(tx_sa); rtnl_unlock(); return err; } -- 2.25.1