From patchwork Thu Aug 20 09:19:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 265830 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=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 CA6E5C433DF for ; Thu, 20 Aug 2020 09:38:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A22A622CA1 for ; Thu, 20 Aug 2020 09:38:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597916334; bh=SZvPBRzilFSWQsUwBrp/oT8mvvxNfp7riXtTnZ+NGLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=oBrRZQDOtNZNF5Vgz8wm5s1GtxKNJNIRjK9PcdNSr9/uf1YRsHYigD3LzsJ1LA3mB QfoUv783LJm1MHvbrFfFpKGot4fYMzyG9ffDKszhLhLKGCj1UGW3X2Utz1o818oF3u 2uSb4oAQoSBah7tWqZ/wUJWKfLZcTxoPmcNgEPUQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728906AbgHTJix (ORCPT ); Thu, 20 Aug 2020 05:38:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:57114 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728901AbgHTJiw (ORCPT ); Thu, 20 Aug 2020 05:38:52 -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 D948B2075E; Thu, 20 Aug 2020 09:38:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597916331; bh=SZvPBRzilFSWQsUwBrp/oT8mvvxNfp7riXtTnZ+NGLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Op+4RJOpSF8Zz4E+4wnl72Jf88ghTveds4+vW9KZsNxXRhTVWTzZHVBzFHa2Roz2n q0xoVjldmomco+Arn4gDk5C4e4UDqjYoLe5p268FgyxYgWIRBRyaWrVbuvJ7oY48zp RMcxS33lZyH9xG5Mlw9GVmcybmTTmiwtEQpZfVk0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Alexander Duyck Subject: [PATCH 5.7 062/204] driver core: Avoid binding drivers to dead devices Date: Thu, 20 Aug 2020 11:19:19 +0200 Message-Id: <20200820091609.364387087@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091606.194320503@linuxfoundation.org> References: <20200820091606.194320503@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 @@ -846,7 +846,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;