Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3154146pxj; Mon, 14 Jun 2021 16:06:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxypvt1eb0GDBqJyfpdOkqcolFxLWpzhOFAdTrhxi8VScS9IU5X21IzsMdeliH/Q0cDanCF X-Received: by 2002:aa7:d413:: with SMTP id z19mr19973973edq.37.1623712016098; Mon, 14 Jun 2021 16:06:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623712016; cv=none; d=google.com; s=arc-20160816; b=1F3eiwRgxhGA70zPzZmU4hxF5J/jaI6j7fu+6H+pO9+4e/t52Bhezk2D9wBz4QG9UT da0mDIJFPCP4fiwB9Cof/mkPSyoh9EAwiN2kN30Uw8LrlUznLzRHUQMZUF9pFtCOLUee +NUOpejA5wg6sbdys47u3hM6vh2EVDQYvyWsJs3HhzGgZNcaLDiedYng0UesQyxd4216 6rUWbyECxtD8SH4s3qHFD6mHwC3lpCIFhSZo0MHGufunzsUjduoBawvjbulIH8JkiIf2 slUeIiJCryrqxvfhUYCd7hWRRzc2w2BKWWSSGS2lcOzHWOpmh92BHyB0N0s872qftFgt KWFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=xptdFCYBt+DjA9CbQxpyV5Tq5GSDlhdqPmEhWjQXrUg=; b=dK45WdHoxitir5Xi85sJdkk3IeQrTWJzZipN8PkhKe1D/8dzmL6pZUq8jhZHFxyxHi ANRaKa3pXFMto8GkLmv5Nh3sqygt0YoF4nXPuCvLzDH6iXGESk6/i8V4h1NM7Vs1Qok7 U6H+XTeqWFQqWYmz8RDVxttNrKwzbQfzvBIvXAsIZwMMad1TYLcBz+8XDMLmB/AA8p/O 2xIiSGUVD4BWBUDz4WXVIhH1fMa/Obo/0pX0ksGqr9kpfebFInJTrIJEVWgwPORAze1h G9x85mB4UNJ7ajXstkJTWg6hjWQsjk3YkI4VX10MLDtJcLdHipTcmoRYAQmX4jHdDYvO EKZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MHouzfSa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d5si14280559edn.231.2021.06.14.16.06.26; Mon, 14 Jun 2021 16:06:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MHouzfSa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231136AbhFNXE5 (ORCPT + 99 others); Mon, 14 Jun 2021 19:04:57 -0400 Received: from mail-ed1-f42.google.com ([209.85.208.42]:43529 "EHLO mail-ed1-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229760AbhFNXE4 (ORCPT ); Mon, 14 Jun 2021 19:04:56 -0400 Received: by mail-ed1-f42.google.com with SMTP id s6so48560827edu.10; Mon, 14 Jun 2021 16:02:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xptdFCYBt+DjA9CbQxpyV5Tq5GSDlhdqPmEhWjQXrUg=; b=MHouzfSasrE3u/M3ZGURu717kwnTWfQprP27KA63w+Af6l4ZfunAfkZo9STcczn+zz SzDBnuIVED0rEhGUWBpGcQeSJWGwCyp812i3mH7UwHr+pNN03Lq4i5Ej33AhryhBYVQm 8NjFnw242+Ghtl3sTzidgZZUopZoOOJnbD3pXjVOXNPkj5WFM1bTH6GZVwd/1ShOD4nc 3MXntAkjMfsi6GHJ2euph0PQ2pQ6+KZwpESxDjLyZ5/uBsMtwsLYISE41XG9EMV0wwvy FQqFH0+6hSIbn23/J+801S9hSgPfJkPZbAIs0PVF07h0M2fVHZ8HXsA2BFTXiWQNfNE8 SJdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xptdFCYBt+DjA9CbQxpyV5Tq5GSDlhdqPmEhWjQXrUg=; b=Vcv6TEsL4AaruIsn1s/XJRQqZVizRcQ6G22slDJGnGrBVXOe6QM0YGL544DZX3N6mQ uX+T2fgIpoKuNPC7pPxu1+X2DOGrKUjKAN+inK3uR1mAGRs/L5QXlibkEfe91G+Xwj7Z VptKDAu9FhOYGSqin++gLtl9MpojTHvOD4+I0FkGwb+6gZCwfrSIWIS+/Ha0EGGGTpzk Ic3avxLMh7uwlfmVx6/FncKKYr3JKNpH1nBjkbHZ0BfxToZjnGU7ScunWJMK5cwpUHkl P7Ej9lupRBW7m81Ey2I5cZLIVt6DXBfTtd14+sj6xkntchPuNQ9ZRfNsWolJVS+AQpPi c+Rg== X-Gm-Message-State: AOAM532zbbGMtk4RlNL0jL/zZzEOsS4oSM3nNWl1IiuCJhaC67L5vbAu kVc5ljFgrB+3h4UCyPwmPjQPAVcg6ewYJCZOmW4= X-Received: by 2002:a05:6402:54f:: with SMTP id i15mr19390460edx.339.1623711699919; Mon, 14 Jun 2021 16:01:39 -0700 (PDT) MIME-Version: 1.0 References: <20210614153712.2172662-1-mudongliangabcd@gmail.com> <20210614190045.5b4c92e6@gmail.com> In-Reply-To: <20210614190045.5b4c92e6@gmail.com> From: Dongliang Mu Date: Tue, 15 Jun 2021 07:01:13 +0800 Message-ID: Subject: Re: [PATCH] net: usb: fix possible use-after-free in smsc75xx_bind To: Pavel Skripkin Cc: Steve Glendinning , "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 15, 2021 at 12:00 AM Pavel Skripkin wrote: > > On Mon, 14 Jun 2021 23:37:12 +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; > > + dev->data[0] = 0; > > return ret; > > } > > > > Hi, Dongliang! > > Just my thougth about this patch: > > INIT_WORK(&pdata->set_multicast, smsc75xx_deferred_multicast_write); > does not queue anything, it just initalizes list structure and assigns > callback function. The actual work sheduling happens in > smsc75xx_set_multicast() which is smsc75xx_netdev_ops member. > Yes, you are right. However, as written in the commit message, smsc75xx_set_multicast will be called by smsc75xx_reset [1]. If smsc75xx_set_multicast is called before any check failure occurs, this work(set_multicast) will be queued into the global list with schedule_work(&pdata->set_multicast); [2] At last, if the pdata or dev->data[0] is freed before the set_multicast really executes, it may lead to a UAF. Is this correct? BTW, even if the above is true, I don't know if I call the API ``cancel_work_sync(&pdata->set_multicast)'' properly if the schedule_work is not called. [1] https://elixir.bootlin.com/linux/latest/source/drivers/net/usb/smsc75xx.c#L1322 [2] https://elixir.bootlin.com/linux/latest/source/drivers/net/usb/smsc75xx.c#L583 > In case of any error in smsc75xx_bind() the device registration fails > and smsc75xx_netdev_ops won't be registered, so, i guess, there is no > chance of UAF. > > > Am I missing something? :) > > > > With regards, > Pavel Skripkin