Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6963426rwb; Tue, 22 Nov 2022 23:29:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf43uXNxyIJsN001TSRMnL0yjRVoPHkGNvkCsmeN3iEdYM8DPRIYcZTQZFPByq4zEny+UU67 X-Received: by 2002:a63:c14e:0:b0:470:4f30:6d80 with SMTP id p14-20020a63c14e000000b004704f306d80mr13575242pgi.285.1669188545766; Tue, 22 Nov 2022 23:29:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669188545; cv=none; d=google.com; s=arc-20160816; b=CrLXHuClpnByQ+tjZQzR0g+8p1PeTBHbJBfpcgOwFOxKxhousfjVmKg3yu5wD7czVj f9x0ahbUcGRzJiSiyXtKsRIPl0FgaAl/9de8TflDXnse/R7caJT76KT5xiW5sy0HW77K rQKyjeban9ZtDOzTWhjAdXeicGsloxz8KYdGdwvZyDGl1Bv/Dr080IUny0MRVDPRSqah 8b1rlKYuVpyYWR4DiXygM72rzu9dk3whPWCg+dum0YIyPn5CwVAHpuQcolQJaWIQgM8y CrS1bQDTzZpXMF+kKrcEGzCeFSVYLYUJO5GDd7SPnhfOq9BC+3ZfEK7gygQsPDPHH7Uz JMmg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i10-20020a17090a974a00b0021382853a8asi1017037pjw.81.2022.11.22.23.28.51; Tue, 22 Nov 2022 23:29:05 -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 + 89 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 Content-Type: text/plain 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 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++; } -- 2.17.1