Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1088090ybt; Wed, 1 Jul 2020 18:35:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0+eYzD8cL0Ubv7tFm4k5aCWEQ4XgIg09oOkUXB7GRig7M0h+9UAwjFON7FDgQ9Z64yTIk X-Received: by 2002:a17:906:a01:: with SMTP id w1mr25949899ejf.197.1593653723475; Wed, 01 Jul 2020 18:35:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593653723; cv=none; d=google.com; s=arc-20160816; b=QvdsBI7MTN9J17zfCcCa+TdqG23N/Mw270DWZYvDkRtH9OfFwPqOpS9ulDrpgmhpeE BDSaWWTkX//x8uM6TUN8DY6FKzHEtecDWFKfTY6luX8/CWBiXdTZ8H668ojqJ/MB7YrM DVm6Zc2xiMlye73dF7et4NZ5r0QF3N+ms+2tMiaFm6Tii5VREfgflri40g5BV184/+s9 X/wircpy86S1TZHgBzz6Dburl5HQ4YhlnV57j11edlEX9J6St/IQFW/d3xR9tOvvYIIw 6Bo59lvhvjccvOtkvyfhdare343++C7MQVurwMN8zYX7NNvFZ0VjzfCJsy/XplYWjb5A lWqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Q7RjdWXUcYv/pWedencuQtt0mb3Y2fFYfvlqAyDgMiE=; b=qfyvXopxgU1zLGmZXmJotcPgYwzzDtcA9MNl1Wibc0eOW0lZNKkbr7c6KoTqQ/mhf6 KInLHJFhGSjI/wuhDx41Drj1mfGZlSwXzMRAHBgRuYQRQeox0AnrAP68Wq2USiwUZe46 vKyo1GWaAgv3Voo1FOcL8AnGH163qyjXoNgIfkTPLl4RywJE0fUu8c/JivHP3KXiXL0x 7CDsOO4Z1xhQjkpbrdo7iFMVHdb4WyzoSCwywY8zBkPwwS2Ybqcuv30nh2KjsTtM+DQl HKLS4CyQubJl2nl588ZD5TDwErH+e5Cju1EpAFUl9OcIp10vNYUyynKZRcvo0l3pR1In LsXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tFHUeN3I; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o1si4768130edq.365.2020.07.01.18.35.00; Wed, 01 Jul 2020 18:35:23 -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=@kernel.org header.s=default header.b=tFHUeN3I; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729157AbgGBBe5 (ORCPT + 99 others); Wed, 1 Jul 2020 21:34:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:54160 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728385AbgGBBXe (ORCPT ); Wed, 1 Jul 2020 21:23:34 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 204792083E; Thu, 2 Jul 2020 01:23:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593653014; bh=j+luVCOiuymvrU9XJJwT00XGVyNwYxhXbV+YSqKKWww=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tFHUeN3IpOWrN5KelyWzWMreCvWoxRRc53UGyZQ2UZFOfiKBze3dYVNCjOdHaiPUa o+m89Imt4VEKRooEVEjuINbnqn7gInfbk8h20lphNFxTVeHnn5gGExlXi+2NBwQiNT KT1OcT8c1XLobOEvEDn4QFiPqSTISkp5q58kj8P0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Tuomas Tynkkynen , syzbot+29dc7d4ae19b703ff947@syzkaller.appspotmail.com, "David S . Miller" , Sasha Levin , netdev@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH AUTOSEL 5.7 31/53] usbnet: smsc95xx: Fix use-after-free after removal Date: Wed, 1 Jul 2020 21:21:40 -0400 Message-Id: <20200702012202.2700645-31-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200702012202.2700645-1-sashal@kernel.org> References: <20200702012202.2700645-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tuomas Tynkkynen [ Upstream commit b835a71ef64a61383c414d6bf2896d2c0161deca ] Syzbot reports an use-after-free in workqueue context: BUG: KASAN: use-after-free in mutex_unlock+0x19/0x40 kernel/locking/mutex.c:737 mutex_unlock+0x19/0x40 kernel/locking/mutex.c:737 __smsc95xx_mdio_read drivers/net/usb/smsc95xx.c:217 [inline] smsc95xx_mdio_read+0x583/0x870 drivers/net/usb/smsc95xx.c:278 check_carrier+0xd1/0x2e0 drivers/net/usb/smsc95xx.c:644 process_one_work+0x777/0xf90 kernel/workqueue.c:2274 worker_thread+0xa8f/0x1430 kernel/workqueue.c:2420 kthread+0x2df/0x300 kernel/kthread.c:255 It looks like that smsc95xx_unbind() is freeing the structures that are still in use by the concurrently running workqueue callback. Thus switch to using cancel_delayed_work_sync() to ensure the work callback really is no longer active. Reported-by: syzbot+29dc7d4ae19b703ff947@syzkaller.appspotmail.com Signed-off-by: Tuomas Tynkkynen Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/usb/smsc95xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c index 355be77f42418..3cf4dc3433f91 100644 --- a/drivers/net/usb/smsc95xx.c +++ b/drivers/net/usb/smsc95xx.c @@ -1324,7 +1324,7 @@ static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf) struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); if (pdata) { - cancel_delayed_work(&pdata->carrier_check); + cancel_delayed_work_sync(&pdata->carrier_check); netif_dbg(dev, ifdown, dev->net, "free pdata\n"); kfree(pdata); pdata = NULL; -- 2.25.1