From patchwork Sat Nov 5 09:05:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tao Chen X-Patchwork-Id: 15930 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp891734wru; Sat, 5 Nov 2022 02:15:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7nKWv5ur+StlupBoDk0z4l9xVeW7orNK0fYAKfFusjeUeUyv0DXvHs83NrebJKXozQBkF6 X-Received: by 2002:a17:907:808:b0:730:54cc:b597 with SMTP id wv8-20020a170907080800b0073054ccb597mr38331322ejb.434.1667639704329; Sat, 05 Nov 2022 02:15:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667639704; cv=none; d=google.com; s=arc-20160816; b=VPbulkxo/tDsAIYE/Z9zPip7uXNXI7IdpkYzebu7h4Byf4ttG+hQr7bpHzCEAlmixO ySiIca0Y/68Bf8iouaq8k+IzVmKzyG+ge3WcG+k9Eo5YKuviL8Gi81JLPkkMDEXj8tFS 4yJT6GM1mEoX/9UC3l5s/LqmUwprXQnblC2fnRq9+HiUlGV1zKZ6YpSJjTJiEjqSbZqR 6txnQ7l+xalRA+3IS95lQmdI6jk0R3oREHVtN9qVBODsLOSRfgRnzVq//UloRKJIhbXn tRqnyDHg+zqniZe171nSmUeYneywLIbKD/0iKsuTcjAIqNMPSH07JPSYuINkpkXbAz/r mBwA== 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=cY517pq7J7ddUELqW0gEsRo1j0/5Xph/kPc+Bauh2aM=; b=ME5nLqrX+/owJZx3XqQbSddO4q4PLfY2jK6jQ/gY1q9SjskUEe/o20UCgVCLKxmZs0 1Mquo20kKysxeBasTjREEDmCKmQpweW3y3A3a/+6vfHFD+0F+1GxkrIIYwfVi6+YAp0d d2qqmYVsEO06rFrX3292u3iHb3hAORcr+2L3UPG81Ty8LHlRRQULhLmp/43vbnyE7/H1 0J132Ea7ZIGbl3hHIrhlurhBOh0lOAj9WgemBKhsUKo8VJpmyQrQqD0CF1sEJ+08hcQV uUlSWfquoIrLDD7jinoxIfm584oK9r2Rh5PYD4fIoFNiZHQUucEIR2IpbD/O5P6qPINf GxJQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r2-20020aa7da02000000b00461c9bb5205si1930351eds.152.2022.11.05.02.14.39; Sat, 05 Nov 2022 02:15:04 -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 S229563AbiKEJFh (ORCPT + 99 others); Sat, 5 Nov 2022 05:05:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbiKEJFf (ORCPT ); Sat, 5 Nov 2022 05:05:35 -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 DAC8023E87; Sat, 5 Nov 2022 02:05:33 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R691e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=chentao.kernel@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0VU-.bn2_1667639119; Received: from VM20210331-5.tbsite.net(mailfrom:chentao.kernel@linux.alibaba.com fp:SMTPD_---0VU-.bn2_1667639119) by smtp.aliyun-inc.com; Sat, 05 Nov 2022 17:05:29 +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 v2] netlink: Fix potential skb memleak in netlink_ack Date: Sat, 5 Nov 2022 17:05:04 +0800 Message-Id: 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748646970701118278?= X-GMAIL-MSGID: =?utf-8?q?1748646970701118278?= Fix coverity issue 'Resource leak'. We should clean the skb resource if nlmsg_put/append failed. Fixes: 738136a0e375 ("netlink: split up copies in the ack construction") Signed-off-by: Tao Chen --- Changes in v2: -Fix some comments -Use "nlmsg_free" interface --- 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..b8afec3 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: + nlmsg_free(skb); +err_skb: NETLINK_CB(in_skb).sk->sk_err = ENOBUFS; sk_error_report(NETLINK_CB(in_skb).sk); }