Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp202254rwb; Wed, 9 Nov 2022 22:51:26 -0800 (PST) X-Google-Smtp-Source: AMsMyM5v34exufeA0YqjtOBGe0NbIcuOUyMhwlPc6D0bUktYOYyhSAutaQxbaDNRnHJYwbfkPFYF X-Received: by 2002:a17:907:a608:b0:7ad:a198:3177 with SMTP id vt8-20020a170907a60800b007ada1983177mr2321721ejc.750.1668063086346; Wed, 09 Nov 2022 22:51:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668063086; cv=none; d=google.com; s=arc-20160816; b=O4tr95q/Zj9JCs9RfKqBufZZUlIjnCAw/SpTtwKjTEOHdrZjxuwhlFuVVieElvOrwH 8MGaKKFYR+K2mKwvaBfMyJSCiM5disVUoJCquMf28xpNEOHrwSr835Z57oMzMse1g2qP NK9ntE8ZdqCzx6s8uZrecMcLqx0IVcVlUbvgfAD1QIzw0a9UAVDrEvIA0N1SefGqC5Uf SjXLDKiyamafKJRDPKVnPFSRvFC0Fc8AMIKaQQ3hc+X7QHyfPnNYd+BTN5/yaIzYg1pT biGZeORghw1TBFxkV5o7Yyrifz83R5N48FB4KRsl2h9vxmjOMQ0LR5DlCEAl+RAZ0kCW 4icA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=c0QiLogYFaQPpiHrEqod0RPB7kYCg4w92qhCQR9CDPw=; b=HRFV6i1E4wQVCK8DbKIVqpgP0h5eBY38R7nSllGcp5Wn54r8rGSi+jChcXl4olZqB1 JDNN9s4hkFfmgEMfUA0C108I6D6N8SL8kVyeDwSdbFIJ2rl3bMGOn+ozxcxI/HQ9rL2W fUzpZFDa/ky1R/e3JsLQeDc/1GbYmgRTWkXC2V2hurTppXUJXj8LojpGX+bwKi9+otLY EpilpZSWmcf5EV7KWytBuYAFjVHOobiTKvsAbdt3f2p+rxna9Y0D8yme+y4VfMprY/hZ StJvrkEyl11fX5LV+Kx6QueQdOKrFe1cEbdrMgV9zL60PandiS0h4S8UCwTbCfZE9446 rvPw== 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 v8-20020a056402348800b0045ca1098d05si19256897edc.349.2022.11.09.22.51.03; Wed, 09 Nov 2022 22:51:26 -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 S232273AbiKJGOw (ORCPT + 92 others); Thu, 10 Nov 2022 01:14:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbiKJGOs (ORCPT ); Thu, 10 Nov 2022 01:14:48 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5224D275FC; Wed, 9 Nov 2022 22:14:44 -0800 (PST) Received: from canpemm500006.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N7BPN3MsFzHvdV; Thu, 10 Nov 2022 14:14:16 +0800 (CST) Received: from localhost.localdomain (10.175.104.82) by canpemm500006.china.huawei.com (7.192.105.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 10 Nov 2022 14:14:41 +0800 From: Ziyang Xuan To: , , , , , , , , CC: Subject: [PATCH] can: can327: fix potential skb leak when netdev is down Date: Thu, 10 Nov 2022 14:14:37 +0800 Message-ID: <20221110061437.411525-1-william.xuanziyang@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.82] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500006.china.huawei.com (7.192.105.130) 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 In can327_feed_frame_to_netdev(), it did not free the skb when netdev is down, and all callers of can327_feed_frame_to_netdev() did not free allocated skb too. That would trigger skb leak. Fix it by adding kfree_skb() in can327_feed_frame_to_netdev() when netdev is down. Not tested, just compiled. Fixes: 43da2f07622f ("can: can327: CAN/ldisc driver for ELM327 based OBD-II adapters") Signed-off-by: Ziyang Xuan --- drivers/net/can/can327.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/can327.c b/drivers/net/can/can327.c index 0aa1af31d0fe..17bca63f3dd3 100644 --- a/drivers/net/can/can327.c +++ b/drivers/net/can/can327.c @@ -263,8 +263,10 @@ static void can327_feed_frame_to_netdev(struct can327 *elm, struct sk_buff *skb) { lockdep_assert_held(&elm->lock); - if (!netif_running(elm->dev)) + if (!netif_running(elm->dev)) { + kfree_skb(skb); return; + } /* Queue for NAPI pickup. * rx-offload will update stats and LEDs for us. -- 2.25.1