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 X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 892D2C48BDF for ; Tue, 15 Jun 2021 09:44:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5FCED6142E for ; Tue, 15 Jun 2021 09:44:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231359AbhFOJqZ (ORCPT ); Tue, 15 Jun 2021 05:46:25 -0400 Received: from new1-smtp.messagingengine.com ([66.111.4.221]:41207 "EHLO new1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231214AbhFOJqY (ORCPT ); Tue, 15 Jun 2021 05:46:24 -0400 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailnew.nyi.internal (Postfix) with ESMTP id BC6F15806F5; Tue, 15 Jun 2021 05:44:19 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Tue, 15 Jun 2021 05:44:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kroah.com; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=uPRVNROLX/rJzi54lhE5A5sUE5N 81CrRfRMujXEzKCI=; b=YIj48d/M0xtnFPhKoReFlLF2MgTT2wIjG3dCUw0POkS 78qjGB7YTQ+QaIgDYrBR9fUM520Frbx6/6oIageDNFmAC0EU3nf1gFlOLgy5oTSr QGA0JSvnIFRwaaIszPRXkaVxCMYEOzpsBlKmqlCICDzSHhr53KT0rW935jFTw7hH PomCPG5vE9clDp+4XSumnRz+oswwZpeE8xXcBmYym7Qedt7Mk9f8KA8VGIBcyZh6 tnrxBmiOL2xv3xM9m7DGv+Zl+VusEM0FBVHTs39CQhMT+fcP9JuYHELWTk9FvdDP l2h59pq6+/DyyyFpiOAsgZnFcKqdBlrR5GtpmBVyrQQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=uPRVNR OLX/rJzi54lhE5A5sUE5N81CrRfRMujXEzKCI=; b=bulS1Y6BZFhLrSkfsOFFLi TeJ9+8VKGHf6lca+3/cbsIzdY9d/sTK9Bt4xMOVdKLCirWrnzzbPNE1AtI0V/XSH qiQ9nWX+kL/uLRxg0F61aw4Yr0qVvwEYBsGN0rJhSEcCNcpLYAFr66kHlR1OqBok kZhnsTNzwauj0GaLB5XS2tMqxdJ9AZIsOz/9JTazAIUiBogCCsn6r5kWxms0+0Z9 oegcsu/Vq7rjVP//ENmbG/kCvq2VppGSBNtuxSjHWw3dWuqnuWtd8WUtDnKhtuU4 ZZa4mA1etS+STeebJbZ6kEso/ADVAyH/YDXT5zJMXT+Jp8ab+JYX6Mreglaw5lTg == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfedvjedgudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefirhgvghcu mffjuceoghhrvghgsehkrhhorghhrdgtohhmqeenucggtffrrghtthgvrhhnpeevueehje fgfffgiedvudekvdektdelleelgefhleejieeugeegveeuuddukedvteenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehgrhgvgheskhhrohgrhh drtghomh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 15 Jun 2021 05:44:18 -0400 (EDT) Date: Tue, 15 Jun 2021 11:44:15 +0200 From: Greg KH To: Dongliang Mu Cc: Steve Glendinning , "David S. Miller" , Jakub Kicinski , Pavel Skripkin , netdev@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel Subject: Re: [PATCH] net: usb: fix possible use-after-free in smsc75xx_bind Message-ID: References: <20210614153712.2172662-1-mudongliangabcd@gmail.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 Tue, Jun 15, 2021 at 03:56:32PM +0800, Dongliang Mu wrote: > On Tue, Jun 15, 2021 at 3:38 PM Greg KH wrote: > > > > On Mon, Jun 14, 2021 at 11:37:12PM +0800, Dongliang Mu wrote: > > > The commit 46a8b29c6306 ("net: usb: fix memory leak in smsc75xx_bind") > > > fails to clean up the work scheduled in smsc75xx_reset-> > > > smsc75xx_set_multicast, which leads to use-after-free if the work is > > > scheduled to start after the deallocation. In addition, this patch also > > > removes one dangling pointer - dev->data[0]. > > > > > > This patch calls cancel_work_sync to cancel the schedule work and set > > > the dangling pointer to NULL. > > > > > > Fixes: 46a8b29c6306 ("net: usb: fix memory leak in smsc75xx_bind") > > > Signed-off-by: Dongliang Mu > > > --- > > > drivers/net/usb/smsc75xx.c | 3 +++ > > > 1 file changed, 3 insertions(+) > > > > > > diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c > > > index b286993da67c..f81740fcc8d5 100644 > > > --- a/drivers/net/usb/smsc75xx.c > > > +++ b/drivers/net/usb/smsc75xx.c > > > @@ -1504,7 +1504,10 @@ static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf) > > > return 0; > > > > > > err: > > > + cancel_work_sync(&pdata->set_multicast); > > > kfree(pdata); > > > + pdata = NULL; > > > > Why do you have to set pdata to NULL afterward? > > > > It does not have to. pdata will be useless when the function exits. I > just referred to the implementation of smsc75xx_unbind. It's wrong there too :)