Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1200459pxa; Thu, 20 Aug 2020 05:29:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDj67Nh5uPvrGWOVg+KRzBiDQVyg55gX01VMmxsdcl7MaMCmVsAAggbHT+1wXeYikPGnN1 X-Received: by 2002:a17:906:fb07:: with SMTP id lz7mr2942891ejb.49.1597926546154; Thu, 20 Aug 2020 05:29:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597926546; cv=none; d=google.com; s=arc-20160816; b=Yc8QB7KqeVlfuTSJmCYQQhlirIbU4pQ0fakXEBRbV9mBCZ9N8nFNKgM7yLB5vv2OTr 5KvZbbiZQZPs9dU7bifYLddIuBN37udWZaia3KXRyZWr5mHJTDI9qoVZRl3T9XstPiem W3HsKxnBmj7cc7c/ToU+9dtCzA20FCjixWYKf6Pcp4Z24U5BzuhmX7zEeIkEPy7E+BVi s95pER+9HJM2YW2snzmwqpCV08Ycuzaat+xMc+JGghg+3SfIHv/gk0AHp5FKjtQz0Nji pon/9utaODLbQvTSd+CqUv8pQgE4ZQfkl/W71Iu1oI62olPGgivdgC2iMHIYdbv++eJr GsPw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=t/1tvZqRjDfESzMMi+UgVgy9HWZqs79vrTdKjZyoLjM=; b=hopzkEaZd68Xk0/tq2ywLDjtOXO2K9z0JB49RSfkFdFiRYPyPqchmc5jRITt+c5WPW BR5mlyG4qHpPU4cfLYm+S3Ena8igxK6AYCnLJ6bZt5iO4zHKtnicHaMEv0M8py+uAIzN iMxJwLdVsrsWGvMOTEI0IE/A39dgiRwhkxHPZcm5yx+sfkykiK3UE3Hfuv41UHywbm99 nJJfktErxmeJq7fNvcYGK5XSVRYKXE1AawSrwBN+BseQbRl9uuGk3J0NIxW87oj/p911 GIAYv7a1CfZDBlamk69wsBy5fEc86FCkkx8kPdw5f4v+5FA5b3Gg6Y0SSu6UO4t2ygxj NQZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xrvSMPRT; 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=fail (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 r8si1096812ejr.677.2020.08.20.05.28.42; Thu, 20 Aug 2020 05:29:06 -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=xrvSMPRT; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728219AbgHTM0I (ORCPT + 99 others); Thu, 20 Aug 2020 08:26:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:34682 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729474AbgHTJxE (ORCPT ); Thu, 20 Aug 2020 05:53:04 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BEC422067C; Thu, 20 Aug 2020 09:53:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597917183; bh=Ioa8RekqZZPooY2b/9Qub7r0er0Y5L/4+KS2IvOM9s8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xrvSMPRTdzXFhFbNmEHffdgVyW6go/+4hOiCYys8bod0bZPAwN56zkWRo7zZVszPB V+KxU3Sh0wLTSgEMjlLspOEIN8kKOTW6qVNXKcbLJwrHnJdrI1X6WtBbUEYuTCDBV+ GaOnSxTvNMLPaafLH9C70goVJgmkQG7FJMaspu+4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Alexander Duyck Subject: [PATCH 4.19 32/92] driver core: Avoid binding drivers to dead devices Date: Thu, 20 Aug 2020 11:21:17 +0200 Message-Id: <20200820091539.256776256@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091537.490965042@linuxfoundation.org> References: <20200820091537.490965042@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lukas Wunner commit 654888327e9f655a9d55ad477a9583e90e8c9b5c upstream. Commit 3451a495ef24 ("driver core: Establish order of operations for device_add and device_del via bitflag") sought to prevent asynchronous driver binding to a device which is being removed. It added a per-device "dead" flag which is checked in the following code paths: * asynchronous binding in __driver_attach_async_helper() * synchronous binding in device_driver_attach() * asynchronous binding in __device_attach_async_helper() It did *not* check the flag upon: * synchronous binding in __device_attach() However __device_attach() may also be called asynchronously from: deferred_probe_work_func() bus_probe_device() device_initial_probe() __device_attach() So if the commit's intention was to check the "dead" flag in all asynchronous code paths, then a check is also necessary in __device_attach(). Add the missing check. Fixes: 3451a495ef24 ("driver core: Establish order of operations for device_add and device_del via bitflag") Signed-off-by: Lukas Wunner Cc: stable@vger.kernel.org # v5.1+ Cc: Alexander Duyck Link: https://lore.kernel.org/r/de88a23a6fe0ef70f7cfd13c8aea9ab51b4edab6.1594214103.git.lukas@wunner.de Signed-off-by: Greg Kroah-Hartman --- drivers/base/dd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -792,7 +792,9 @@ static int __device_attach(struct device int ret = 0; device_lock(dev); - if (dev->driver) { + if (dev->p->dead) { + goto out_unlock; + } else if (dev->driver) { if (device_is_bound(dev)) { ret = 1; goto out_unlock;