From patchwork Fri Nov 25 07:57:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yue Haibing X-Patchwork-Id: 25875 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3850104wrr; Fri, 25 Nov 2022 00:22:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Ccg2Fs9Io4+aZLDCIMw/TMB8ttSn+G+HPs2dci7wet6NQ1o49U8gB9eXQgou8P4Arbt6E X-Received: by 2002:a05:6402:2053:b0:468:f837:9a16 with SMTP id bc19-20020a056402205300b00468f8379a16mr31208861edb.324.1669364566489; Fri, 25 Nov 2022 00:22:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669364566; cv=none; d=google.com; s=arc-20160816; b=qNpDx0eqmNHUPcUrpxXQ5lJqf0pYnLY5M3FWGo9vcheUKookdA40Z3kzez4aH0b1JZ hDPO3IWcVQ8cgf4zsyKpx2QaL67dLOZx1bzzK22aLrDZmWJrQFls6apBDizw3mVz+Cer fYoJ4X3vkgY5NKQvHEK9PNZKtTO8gMkoQleT5NPxnU3h89/f2EEYQug/FIr8ziJ32xN1 LHNl8gdFzWOi10vOM1Q/bBlRgbx3lvTKNZXwg+fEZVrzLNsapou4HUbVu1ml3TXVLzJk vBN/juMsgrypUAIDvmLNXDj6zhrp1yUBnlfAJx33TsxeNlKhp1fPMoHfmayxSNjTazje UVsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=scA2MAFO6J7OVjYxsqHfbqcJKOyoXg6iZ/WOlc36v3k=; b=CxmFA8umQeAHa933kae+lXjFypNvf0JVDh6faDcw2ddnob13SMgVyFb0h/6TlglqWs mUD5UjXgcIoV+S36P9jxYXbTYIk34WxBFlfsqD3vhnSu9SQEvrRvtoA4q7ikiQNNdS2H Zdy/F83bGIRYD8DlVgT/vCqmj7srDJ5UwfmQobFDILFYF7Mzx1qT4yz2xSeRjsY0BWaO oDcMB0AOYEws1SgPjYSYLQ1qiCp+dAmTkBEybpASay6FnyjWo71T6cFLniOOdn5vpXpa eNzdCgRzsOQ3/eXVCWHnFRSAw8mKA+7UaK7yUa9x6yNyQ6jpkmy+BVfmJC19wiNpwvm2 Mlrg== 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 ss2-20020a170907c00200b007add0e1a187si2214832ejc.594.2022.11.25.00.22.22; Fri, 25 Nov 2022 00:22:46 -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 S229774AbiKYH5t (ORCPT + 99 others); Fri, 25 Nov 2022 02:57:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229756AbiKYH5p (ORCPT ); Fri, 25 Nov 2022 02:57:45 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72FC31180D; Thu, 24 Nov 2022 23:57:44 -0800 (PST) Received: from canpemm500007.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NJRz93VdCz15MqB; Fri, 25 Nov 2022 15:57:09 +0800 (CST) Received: from localhost (10.174.179.215) by canpemm500007.china.huawei.com (7.192.104.62) 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:57:42 +0800 From: YueHaibing To: , , , , CC: , , YueHaibing Subject: [PATCH v2 net] net: hsr: Fix potential use-after-free Date: Fri, 25 Nov 2022 15:57:24 +0800 Message-ID: <20221125075724.27912-1-yuehaibing@huawei.com> X-Mailer: git-send-email 2.10.2.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.174.179.215] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500007.china.huawei.com (7.192.104.62) 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750268268034467761?= X-GMAIL-MSGID: =?utf-8?q?1750455619704226349?= The skb is delivered to netif_rx() which may free it, after calling this, dereferencing skb may trigger use-after-free. Fixes: f421436a591d ("net/hsr: Add support for the High-availability Seamless Redundancy protocol (HSRv0)") Signed-off-by: YueHaibing --- v2: correct Fixes tag --- net/hsr/hsr_forward.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/hsr/hsr_forward.c b/net/hsr/hsr_forward.c index a50429a62f74..56bb27d67a2e 100644 --- a/net/hsr/hsr_forward.c +++ b/net/hsr/hsr_forward.c @@ -351,17 +351,18 @@ static void hsr_deliver_master(struct sk_buff *skb, struct net_device *dev, struct hsr_node *node_src) { bool was_multicast_frame; - int res; + int res, recv_len; was_multicast_frame = (skb->pkt_type == PACKET_MULTICAST); hsr_addr_subst_source(node_src, skb); skb_pull(skb, ETH_HLEN); + recv_len = skb->len; res = netif_rx(skb); if (res == NET_RX_DROP) { dev->stats.rx_dropped++; } else { dev->stats.rx_packets++; - dev->stats.rx_bytes += skb->len; + dev->stats.rx_bytes += recv_len; if (was_multicast_frame) dev->stats.multicast++; }