Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2166517imw; Wed, 6 Jul 2022 00:57:41 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t368mxmMHbV5SWLSf8+UYtJ4G2NDl4vEz+Sb1xxOM4GVtb/51xp9+7JKQ6oNiLzDn45wEJ X-Received: by 2002:a17:90a:e7c2:b0:1ef:8acb:5ff with SMTP id kb2-20020a17090ae7c200b001ef8acb05ffmr16984304pjb.146.1657094261327; Wed, 06 Jul 2022 00:57:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657094261; cv=none; d=google.com; s=arc-20160816; b=XEosDEf+MssAOFfEnBElRlYVChzTnxQJEeFtFDxD8cyU2v7vLcImy1ijChIh4Xquu2 Q4WZOn3fzhaHz+RAfhk+UreFPRo9Ix0LhTHcNiwcWyU+u8E/ZmY6zI8C5cAQAzbUHrBf q8JuiKbWUH4FqFaVcXowSHxwttiUdaR5OQgoCp7sv6i7MnL3jzMPqoyPGGLNzmdcMivC 3ocJBkVDqJ+kHn+Wxj25kX4LVdT4bJmqjxKflvZWx5EZUK3TyunvdhJ7hyIAA/F6yc18 7KuDC8Kpnjcs9/g8eLcwtekhTI0SOdXUXXapBooSa8saUmI5g/9baHdXnjCibCf3aHdG +rCg== 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=SqhwsDxEEv282usXjAYsLO64gR1EHIuqZrjCv4gxdgwmXoKQhKLo66uwpSvugDtm/N jTKWUqNfgXY6qTOVr2OBpC6jqQf3yWj97q4lvpL+Gml2mKQxpU5jojmtFLABVEXSOsiU +pPNwKA0oOcwtS65tNFbaJ3cc/DQsD0zJL0Q5RWxyFKE1V+VMR3Dmrcg9oPRlNG8gXAm erx5/AdZnRijRYMXAZZgTm+DGy+ncAPlrUTEB8Fq8dF0uTfPbfsA8OYxAXs5F71+7Rtm RHWaqGLgxzzqEMQJ5TlC2zRRDga0gY0cp7b/0en8SNxhOLwVbXRBayBBvfAz4CeT+w4o kCdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=j9NkHPTE; 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 126-20020a620484000000b00518c3e572e3si3058490pfe.295.2022.07.06.00.57.28; Wed, 06 Jul 2022 00:57:41 -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=j9NkHPTE; 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 S231758AbiGFHte (ORCPT + 99 others); Wed, 6 Jul 2022 03:49:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230359AbiGFHtd (ORCPT ); Wed, 6 Jul 2022 03:49:33 -0400 Received: from mail-m972.mail.163.com (mail-m972.mail.163.com [123.126.97.2]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8786922B3C; Wed, 6 Jul 2022 00:49:31 -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=j9NkHPTE9z+Curz/JVKVq kue+1kmDGWK21Rqd2/5h7I6ui4Kx8hvL5/hX7Fy/n2aRzBAfds0qZy/2CvNxCR7m 9AeCYvqaZvx/UNfLPX6ny5fmF8zcH59S8uLbz8UaBUAC5XucDdqD6N3a906bLSNe aZYWETGJh4LkIBYUzt2OHg= Received: from localhost.localdomain (unknown [123.112.69.106]) by smtp2 (Coremail) with SMTP id GtxpCgAHhyNhPsViyC90Ng--.47709S4; Wed, 06 Jul 2022 15:49:01 +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: Wed, 6 Jul 2022 15:48:26 +0800 Message-Id: <20220706074826.2254689-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: GtxpCgAHhyNhPsViyC90Ng--.47709S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ar4rWF4fCF17Zw1xZr43ZFb_yoW8Jw4Dpa 15ZwsrCF1qqrWI93ZrCw4UWF1rXayUtryagry7C3yfua4kJw1rWFy0kFyI9Fy5AryxGF48 ZrWvyr47AFn8C37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRhqXJUUUUU= X-Originating-IP: [123.112.69.106] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/1tbiPgs2jFxBtJroWQAAsN 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