Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3924248pxj; Mon, 21 Jun 2021 09:28:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxM8BJgFwsWkC1RGWxuEvTlzpdy9ZVucAU8R0/modXKQB+0aVND09rQWWhorqntAC0wwRdS X-Received: by 2002:a17:906:1986:: with SMTP id g6mr25624844ejd.265.1624292937622; Mon, 21 Jun 2021 09:28:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624292937; cv=none; d=google.com; s=arc-20160816; b=tybetuyCuX2W9ec5t2KnMhNvrc/KmGBId7vkjzwKH2sOCfLVd3uJ6ZuZAaMgbp2rlK 0i1vEu6fDo74HKGmPlZSAX5iAtvizo4wnoznrvzr7w8TYb40utfo5ilweEfjMbn31059 Sy+VJdB8ayL0kozyJz8kA8vZbj8yUwdhTUKksDxnJcfCMONGZVKE/sea3B8DsZGB4zgN ZJLBWkK+XB8yi15Ouh6ZUPlSzisjQBB5SfxtfPGWuDzbfi/IOSsIQVixpm1djT1FHhxk Fr3quO98AgfKkKV8Eo6DlyGgsWTgYXBEfD32OcfqsYvAMlYhf1b7VcnMI2p/soL7v4Kf RaVg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uenvWt1duo/TANVnjcK+9iDK50P9FCTpF4IQ6p5LbDY=; b=lqx8IyXlcDyiJ/6jYO8UQjQhRSdZE0hoAdh+I0IT/3yvrUnHoHCyEHS141yFB6jWzf yGDxTJ92hUz7U0HTLZ00HEFBFziNds9+X5lhRCtWW3DWHSiGuoRjevrr2bBNrY7jfm7d B4/EnShfy+g8mH8FsS3iLtc5RU6Xz5cDHd/6q8RZ/yXvRT1ZXTjTdox1lblSGgt8eh1T tVyW4eEew5paynPoQOUP5y9ZTbX67a8jQMsIDwGhvOQJc3rX3iT87tRHJO13LFjN0nt+ vimkXUz4/+BZxIELmqApyf+znTBsJuBDhCOwbTMfmDjUKlGAdV/qz3X/+gnwrfM8Gtkf krCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WmJIzER2; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v13si8744402edc.559.2021.06.21.09.28.34; Mon, 21 Jun 2021 09:28:57 -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=@linuxfoundation.org header.s=korg header.b=WmJIzER2; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232065AbhFUQ3x (ORCPT + 99 others); Mon, 21 Jun 2021 12:29:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:48560 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231635AbhFUQ2G (ORCPT ); Mon, 21 Jun 2021 12:28:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 490C360231; Mon, 21 Jun 2021 16:23:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292592; bh=tQVdZcFxjbkS0neonPwjuVD2m4RLxCuAka41aGj1nLc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WmJIzER2BK+J7BTKIaAOT+SfRXGJKWSsoA4U+grBRGPYEbPxiQKqMPhMsVH3dz6cQ wQ5LyrWnRRtshpxPsx/7LGF4G8Czp0SIvpOD88k0JoG7S/vxjsaQ3wp0TJ2adGcrxI qoHfSRWrhP/ogHk2o4YesE4gGxz7UI3tqrzECuac= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dongliang Mu , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 058/146] net: usb: fix possible use-after-free in smsc75xx_bind Date: Mon, 21 Jun 2021 18:14:48 +0200 Message-Id: <20210621154914.270525635@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154911.244649123@linuxfoundation.org> References: <20210621154911.244649123@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dongliang Mu [ Upstream commit 56b786d86694e079d8aad9b314e015cd4ac02a3d ] 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 a dangling pointer - dev->data[0]. This patch calls cancel_work_sync to cancel the scheduled work and set the dangling pointer to NULL. Fixes: 46a8b29c6306 ("net: usb: fix memory leak in smsc75xx_bind") Signed-off-by: Dongliang Mu Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/usb/smsc75xx.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c index d44657b54d2b..378a12ae2d95 100644 --- a/drivers/net/usb/smsc75xx.c +++ b/drivers/net/usb/smsc75xx.c @@ -1483,7 +1483,7 @@ static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf) ret = smsc75xx_wait_ready(dev, 0); if (ret < 0) { netdev_warn(dev->net, "device not ready in smsc75xx_bind\n"); - goto err; + goto free_pdata; } smsc75xx_init_mac_address(dev); @@ -1492,7 +1492,7 @@ static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf) ret = smsc75xx_reset(dev); if (ret < 0) { netdev_warn(dev->net, "smsc75xx_reset error %d\n", ret); - goto err; + goto cancel_work; } dev->net->netdev_ops = &smsc75xx_netdev_ops; @@ -1503,8 +1503,11 @@ static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf) dev->net->max_mtu = MAX_SINGLE_PACKET_SIZE; return 0; -err: +cancel_work: + cancel_work_sync(&pdata->set_multicast); +free_pdata: kfree(pdata); + dev->data[0] = 0; return ret; } @@ -1515,7 +1518,6 @@ static void smsc75xx_unbind(struct usbnet *dev, struct usb_interface *intf) cancel_work_sync(&pdata->set_multicast); netif_dbg(dev, ifdown, dev->net, "free pdata\n"); kfree(pdata); - pdata = NULL; dev->data[0] = 0; } } -- 2.30.2