Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp3953069rwi; Wed, 2 Nov 2022 05:16:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6WgQXb8ekbGcHmP/WK22l+qyEoBPlpOXzPeki+PQmmHLChxRM2EZmVZ7lu5KUaxjpbplze X-Received: by 2002:a17:906:db02:b0:780:24e:cf9 with SMTP id xj2-20020a170906db0200b00780024e0cf9mr22844885ejb.460.1667391371681; Wed, 02 Nov 2022 05:16:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667391371; cv=none; d=google.com; s=arc-20160816; b=Zg0Zyw01zDf7okjaosmUtE8BtX2eLOHEncU/x/LcQK4LwEuxtZq5wSJOza39b3G9Pz TZkKrFCzUfdDXFCFCMN+mi8G8/eWotlAXw7VUq9a4IUI3NW2LKbUaumys0Lhnnc1kwuj riDv1LPRJ2qNis1xWHCsTBCKRhW1/YqQ0npQ3FVHdUClVOie1VKLrUf3zE6ZkJZ5eqF+ VV3ZREx0NeBen05IaGlEfOEX3y+71wfiv4500xuQp8+7FXwzPiuEGhwvzy9/cq0L2JoH a7lq522rNZT8HO2abLud8BASKKkoAgLBBrQ2O/xkqtpb2I2041wIxc0FJZg/6PdbYap9 lR2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=0ly3+kR1TxlQepikVDpnjbbBO9FZ/y+wEtPmrVFp5Gk=; b=T3Obpij+0mBb3uwvd34tjz86w7Qz8vWwmkUj7o2kG02qFudGx+zzt3D4DdCJI09HjY rMydHVj0JlZXWbRXrLsRI90WJtwHeKAbGhjKo9teh+LkgiN2JxgH9ce3KN/fTbC+Z0Pz 4jeq2T4DTwzjIUQPZd0ezwaEwksdNFYb+fgT9goGWqFonB4fvUQwJSul80Vucj6rOGYH AUugftZRPUrqHu6A4tM59MfI9+5dlHXROIT0ij5R8ch8nvMJe/WKTW2pyJwzlLRk+qbt OaRnIuEY9o0HUs6d0imoa8I2SAC/BSGC69V6Im3I/eFFqjFXOeNQSMee2ToUw1IpWLp9 EJqw== 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=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id du10-20020a17090772ca00b0073d751c96adsi16248198ejc.1000.2022.11.02.05.15.47; Wed, 02 Nov 2022 05:16:11 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230515AbiKBMIi (ORCPT + 99 others); Wed, 2 Nov 2022 08:08:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230366AbiKBMIg (ORCPT ); Wed, 2 Nov 2022 08:08:36 -0400 Received: from out30-43.freemail.mail.aliyun.com (out30-43.freemail.mail.aliyun.com [115.124.30.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D43B722516; Wed, 2 Nov 2022 05:08:34 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R831e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045168;MF=chentao.kernel@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0VTo8Xcs_1667390902; Received: from VM20210331-5.tbsite.net(mailfrom:chentao.kernel@linux.alibaba.com fp:SMTPD_---0VTo8Xcs_1667390902) by smtp.aliyun-inc.com; Wed, 02 Nov 2022 20:08:30 +0800 From: Tao Chen To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Johannes Berg , Oliver Hartkopp , Petr Machata , Kees Cook , Harshit Mogalapalli Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Tao Chen Subject: [PATCH net-next] netlink: Fix potential skb memleak in netlink_ack Date: Wed, 2 Nov 2022 20:08:20 +0800 Message-Id: <7a382b9503d10d235238ca55938bc933d92a1de7.1667389213.git.chentao.kernel@linux.alibaba.com> X-Mailer: git-send-email 2.2.1 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL 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 We should clean the skb resource if nlmsg_put/append failed , so fix it. Fiexs: commit 738136a0e375 ("netlink: split up copies in the ack construction") Signed-off-by: Tao Chen --- net/netlink/af_netlink.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index c6b8207e..9d73dae 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -2500,7 +2500,7 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err, skb = nlmsg_new(payload + tlvlen, GFP_KERNEL); if (!skb) - goto err_bad_put; + goto err_skb; rep = nlmsg_put(skb, NETLINK_CB(in_skb).portid, nlh->nlmsg_seq, NLMSG_ERROR, sizeof(*errmsg), flags); @@ -2528,6 +2528,8 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err, return; err_bad_put: + kfree_skb(skb); +err_skb: NETLINK_CB(in_skb).sk->sk_err = ENOBUFS; sk_error_report(NETLINK_CB(in_skb).sk); } -- 2.2.1