From patchwork Wed Nov 23 06:30:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yue Haibing X-Patchwork-Id: 24739 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2626618wrr; Tue, 22 Nov 2022 22:44:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf4OtFSkwPTf4wiaFf08I3Vd6zfbcf0fGDt/7U5EgRypi03cMMpFV0EYmPwsVUnWNoIDPAlD X-Received: by 2002:a17:906:c449:b0:7ae:cbae:af1 with SMTP id ck9-20020a170906c44900b007aecbae0af1mr22902238ejb.31.1669185894182; Tue, 22 Nov 2022 22:44:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669185894; cv=none; d=google.com; s=arc-20160816; b=e9rpF3gUW1BUoWLPf12ayXrZY4n3Ihbho4XyMfW+UimTXqX+7CIrvJtO1FUZx6GFXP nwa9aWdTtenbSE4nDzfo073F7WFL50HlAQ/tBNuvCB2jN6WWptOzHFb4WBhChy5R599t Gb2M5fIpnyMKM6MyA1aebdaKLwqrjIU81GSCH2VNBswQCKwTjpbUATjsJTMt91cafJK1 ItsFAGaN9NBa44kX/JaipQ4SxGGKoIv3PL/f0/4IVvAwv4x/SaMDkmDJx6Z7j2j3knKm 9jiWenHLjOLxwze6tXU9VwZnNkN+SrbUmL5JHoK1qiuygadNO8FmEr66Dta9eb3KwTTG Ed6w== 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=vVfrtIpYf96KEwnyfvdEquTT3FUpcAgJNMy1kp/nUsg=; b=aH1aPYyQCCgECQMPPj5UTtyNRv75VlpR8oZVnJ/e0nMoa9OzFC7hayEON18tsGYQEB Ho1vyoAymHsLrprx5pSPhPIOdkT/gpkKHU5Ax3iHD/8Y1NARWo+W6WRMc5MPRCsurXFj 5z/ArsjvVuIxwjX4Oxf+dG9Iq6Y+TJlB4dQspg4yj+hAGuSa5k3346ZTVxCR66Nhk1lC nBe4mu2xwuNURXmZFXek5PYOfxfOEA9BYwrwr0ppYe+80VSldPApTqLAZVyFmKKgX837 rZaVwEMIbAGQZKb65DdmO0gWbxjY33a9Fipju0uMvsOO17RcabKtG/UlzfuJNjCfEynt B+Qw== 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 m9-20020a056402050900b00462e4cbe815si12364101edv.550.2022.11.22.22.44.28; Tue, 22 Nov 2022 22:44:54 -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 S235990AbiKWGbM (ORCPT + 99 others); Wed, 23 Nov 2022 01:31:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234531AbiKWGbK (ORCPT ); Wed, 23 Nov 2022 01:31:10 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC2B15C74E; Tue, 22 Nov 2022 22:31:09 -0800 (PST) Received: from canpemm500007.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NHB8F43Wpz15Mlp; Wed, 23 Nov 2022 14:30:37 +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; Wed, 23 Nov 2022 14:31:07 +0800 From: YueHaibing To: , , , , CC: , , YueHaibing Subject: [PATCH net] net: hsr: Fix potential use-after-free Date: Wed, 23 Nov 2022 14:30:57 +0800 Message-ID: <20221123063057.25952-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: dggems701-chm.china.huawei.com (10.3.19.178) 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?1750268268034467761?= The skb is delivered to netif_rx() which may free it, after calling this, dereferencing skb may trigger use-after-free. Fixes: f266a683a480 ("net/hsr: Better frame dispatch") Signed-off-by: YueHaibing --- 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++; }