From patchwork Wed Nov 23 08:15:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yue Haibing X-Patchwork-Id: 24784 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2660153wrr; Wed, 23 Nov 2022 00:24:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf7X4VaQBC2w10rgEG5WK4mZ0Cu/s0U2OoGIlMSh1DnFxdHu0vH2lDqMSvxJc4llWU5OPiFk X-Received: by 2002:a17:90a:e681:b0:218:cf94:bb70 with SMTP id s1-20020a17090ae68100b00218cf94bb70mr6465111pjy.28.1669191845091; Wed, 23 Nov 2022 00:24:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669191845; cv=none; d=google.com; s=arc-20160816; b=A1u0cMOguH00RXOFieuDF5NxbcPuNAxJY9DmxGTwcvUo22VQ6q/AuBi+Ky+HFWu8SH urMk3vauSkQxCiiv/xS2bs0tG/i6GHuVI0ktz1rKSYFbatYSpp6B0e74DaePJdyeJvVr Y47xp0+AaE49wkmFSPwZIxxQww+0nDHCwttF7H5jtfVQefkd1VkrvF5/a/HT+3ZK/QbY AmMNH8vKdXWWzRavaE2TFm+OrbxaB01KFEfoEP/ZV9muKsvnAGoWXtYP3EU9trnxU2Iu /uvSHb5kYZNTr005qD+/NujOJJQvG43yotzIqw7LUvCv/LYkndXxU/X6GCOKPz/Jaicm WM7Q== 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=/tVG7mLDr+HjLzo4hSe7kvxELppYWkYDs50z7+DEb/4=; b=NUZwaZYf2DjxSJGWH2Fdu6+bAD+v72SFOTwas77snrwmbpwoz+AnGPb/qzUcfHrd62 DhGSjkP10BI/4VyudvdQRp3hj3pK9kjlxk+FF/NGZKQ9kM0GrcRnpE6H581AMNlVxy8a G+r4FpEANMovCYhVhv9gxjs/NUhANUr4BnC7Ou0tGew/8DVgLKOoDyjLM3XIW2ynk5gL PhkiE0DUN+lwJJpWm+FmM28bUqN0DnZYRVCpjDi/tIYfTiYP9kKbKu8ncNOaKGMnwIjE DXit/q6MjWY0tpd7teDsbqtJ8br3+uDj1ob9/Xsd4VwYvR5oOMwd0AF8NTioJ00AHPmN S+Fw== 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 q19-20020a056a00089300b0056bbdb48fcdsi17758649pfj.118.2022.11.23.00.23.52; Wed, 23 Nov 2022 00:24: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 S236362AbiKWIPu (ORCPT + 99 others); Wed, 23 Nov 2022 03:15:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235969AbiKWIPr (ORCPT ); Wed, 23 Nov 2022 03:15:47 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A2F9F1DBC for ; Wed, 23 Nov 2022 00:15:46 -0800 (PST) Received: from canpemm500007.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NHDSy10wxzRpR7; Wed, 23 Nov 2022 16:15:14 +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 16:15:43 +0800 From: YueHaibing To: , CC: , , YueHaibing Subject: [PATCH] firewire: Fix potential use-after-free in fwnet_finish_incoming_packet() Date: Wed, 23 Nov 2022 16:15:11 +0800 Message-ID: <20221123081511.28684-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?1750274508134836450?= X-GMAIL-MSGID: =?utf-8?q?1750274508134836450?= The skb is delivered to netif_rx() which may free it, after calling this, dereferencing skb may trigger use-after-free. Signed-off-by: YueHaibing --- drivers/firewire/net.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/firewire/net.c b/drivers/firewire/net.c index af22be84034b..9e19f942a545 100644 --- a/drivers/firewire/net.c +++ b/drivers/firewire/net.c @@ -479,7 +479,7 @@ static int fwnet_finish_incoming_packet(struct net_device *net, struct sk_buff *skb, u16 source_node_id, bool is_broadcast, u16 ether_type) { - int status; + int status, recv_len; switch (ether_type) { case ETH_P_ARP: @@ -533,13 +533,14 @@ static int fwnet_finish_incoming_packet(struct net_device *net, } skb->protocol = protocol; } + recv_len = skb->len; status = netif_rx(skb); if (status == NET_RX_DROP) { net->stats.rx_errors++; net->stats.rx_dropped++; } else { net->stats.rx_packets++; - net->stats.rx_bytes += skb->len; + net->stats.rx_bytes += recv_len; } return 0;