From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0468FC433FE for ; Fri, 18 Nov 2022 17:11:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242331AbiKRRLk (ORCPT ); Fri, 18 Nov 2022 12:11:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235475AbiKRRLf (ORCPT ); Fri, 18 Nov 2022 12:11:35 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 674B38C791; Fri, 18 Nov 2022 09:11:34 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F418B6265E; Fri, 18 Nov 2022 17:11:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1B74C433C1; Fri, 18 Nov 2022 17:11:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668791493; bh=KWwzNSV7Rl2am6gtz8aTkwn6BkiBMh1VJdUCRx5KM8o=; h=Date:From:To:Subject:References:In-Reply-To:From; b=ekpjulwdwM3mjoP/FGVfzRoKGn00Lpr71FAhMqFMUJbmfNIXK6+cdo+Sr5y5dV1Xa JLhEKb9VJcy/rgwJgyXrTfOzIz1oo5ctjPaC6HxvCOFqJHQVuuBXczre9bGwFAcipf eGiKfxeUyWBvWD6F10SiflHcSxutSckgKFY8sa6u9Q1HhvQptGqFyyvdCnnRvs5mT2 VZitUA/c1BkXTA5VjDGrrn/DiZZM9qvY80m8B5VSmKdGVuOqhlXt29Z0x5jGsffsue AJ987t/tbic3eF8oiewCB/Entv9JHlDhPm3ErFXiBb1a83yAJfPDzfoNqJLB9vw1aZ l1S+AECybhcCA== Date: Fri, 18 Nov 2022 19:11:28 +0200 From: Leon Romanovsky To: Zhang Changzhong , Edward Cree , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net] sfc: fix potential memleak in __ef100_hard_start_xmit() Message-ID: References: <1668671409-10909-1-git-send-email-zhangchangzhong@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 18, 2022 at 09:15:43AM +0000, Martin Habets wrote: > On Thu, Nov 17, 2022 at 03:05:27PM +0200, Leon Romanovsky wrote: > > On Thu, Nov 17, 2022 at 08:41:52PM +0800, Zhang Changzhong wrote: > > > > > > > > > On 2022/11/17 19:36, Leon Romanovsky wrote: > > > > On Thu, Nov 17, 2022 at 03:50:09PM +0800, Zhang Changzhong wrote: > > > >> The __ef100_hard_start_xmit() returns NETDEV_TX_OK without freeing skb > > > >> in error handling case, add dev_kfree_skb_any() to fix it. > > > >> > > > >> Fixes: 51b35a454efd ("sfc: skeleton EF100 PF driver") > > > >> Signed-off-by: Zhang Changzhong > > > >> --- > > > >> drivers/net/ethernet/sfc/ef100_netdev.c | 1 + > > > >> 1 file changed, 1 insertion(+) > > > >> > > > >> diff --git a/drivers/net/ethernet/sfc/ef100_netdev.c b/drivers/net/ethernet/sfc/ef100_netdev.c > > > >> index 88fa295..ddcc325 100644 > > > >> --- a/drivers/net/ethernet/sfc/ef100_netdev.c > > > >> +++ b/drivers/net/ethernet/sfc/ef100_netdev.c > > > >> @@ -218,6 +218,7 @@ netdev_tx_t __ef100_hard_start_xmit(struct sk_buff *skb, > > > >> skb->len, skb->data_len, channel->channel); > > > >> if (!efx->n_channels || !efx->n_tx_channels || !channel) { > > > >> netif_stop_queue(net_dev); > > > >> + dev_kfree_skb_any(skb); > > > >> goto err; > > > >> } > > > > > > > > ef100 doesn't release in __ef100_enqueue_skb() either. SKB shouldn't be > > > > NULL or ERR at this stage. > > > > > > SKB shouldn't be NULL or ERR, so it can be freed. But this code looks weird. > > > > Please take a look __ef100_enqueue_skb() and see if it frees SKB on > > error or not. If not, please fix it. > > That function looks ok to me, but I appreciate the extra eyes on it. __ef100_enqueue_skb() has the following check in error path: 498 err: 499 efx_enqueue_unwind(tx_queue, old_insert_count); 500 if (!IS_ERR_OR_NULL(skb)) 501 dev_kfree_skb_any(skb); 502 The issue is that skb is never error or null here and this "if" is actually always true and can be deleted. Thanks