From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796387499; b=erx7x6aV9g674rDPEQiB63OoEj++yNOSq3R6bXyDcE3f5uznHH2rTi9NRAI3qjA3SHJ9 7r+iQJc8SFYwc76WvG+MmN/bZmypK6ppXAY521yIzQ+4jcjS6eVQjog7s93Q96eVj5mfF rJDdrmi/RnN/ydH//4DoS2dT+Asx+uR5BpJemHBJveULjcwDN2DBWuAtWtVeKuwmagp1g LSh+Qe5apK5s4zV2UsLeUJ7h1cHIM3IWvT2sVdZBAfSt7b92mXWUqP/he5d8qdUzuw+Rt xYFpegdcTZEnmVDHNbub7p7d50e5m44WgWEWgzarpz5EOZVppiaGjJIx7Sx5J/ZkM1g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387499; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=iyEwy7yBupNS7EzRWewPOCxYHs1ATxqKwjFJymKVV5U=; b=J+9ifsz55x1uCP72dmo8aM8OpG4l59tafaPZGvCwQ1THes6zO42IE5oaaiNfKWGd5yq5 7YS6ffbbCRQ5cVVbEfcTRtry5vXLLo0R7+JlFl+PkCZainJa85h/+FHudyFXycOmYcXwC Oi5N6XNiCeydt5tNd9Y7imK0LUI6V1KRnZ2c+5Jcr59rzyr2Ct3LEJEtoCOns4gSeBE0X sI+7qBvw59OuswMVr9ho+3khEY4Cur+MiwIiEyNqk3WyFllW91qUQKG3H/RrIeHV5aYC6 BDdPVnftjrVGTWO/5aQHO/4wPMigt9UKlrgME+yEGPm0AlX/u7C2jJf9nfZeUWczK2Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b="zsF/Pbrj"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98E05606A32C; Fri, 4 Dec 2026 12:31:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=zsF/Pbrj Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12A3C1F000C2; Fri, 4 Dec 2026 12:31:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387499; bh=iyEwy7yBupNS7EzRWewPOCxYHs1ATxqKwjFJymKVV5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=zsF/PbrjHoHPPvyf12uuyCG5Fdaup5rkWgUNy1/dAufPTRP7D4w/O6Arl0OGX5n7p iLgXOepS7/xBsZOUlcRhegX71/Dhw9ULMYgvQTWwYZbkm5CEIdnwcNSGRP9XD8tP8f ln18FbQ7h3S/SIpRAcu9u2dgNxzrLxc33f714RWM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 6.1 0269/1059] ACPI: glue: Carry out companion lookup under bus_type_sem Date: Fri, 4 Dec 2026 18:56:40 +0900 Message-ID: <20261204100651.243142254@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Rafael J. Wysocki [ Upstream commit c94619c8a5b5d3b980433d247ac87a2d1c827cb6 ] When acpi_device_notify() looks up an ACPI companion for the given device, it invokes callbacks from struct acpi_bus_type() without synchronization which may lead to a use-after-free if the driver module containing those callbacks is unloaded at the same time. Address this by holding bus_type_sem throughout the entire ACPI companion lookup and the execution of the .setup() callback in struct acpi_bus_type (if present) instead of dropping the semaphore (prematurely) after finding a matching struct acpi_bus_type. For this purpose, rename acpi_get_bus_type() to acpi_companion_lookup(), make it return a struct acpi_device pointer, and move the relevant code from acpi_device_notify() to it. Also notice that the only case in which the .bind() callback from an ACPI scan handler may need to be invoked is when the given device is a platform one, so adjust acpi_device_notify() accordingly and drop the "done" label that is not used any more from it. Fixes: 2ef5236660b6 ("ACPI: glue: Look for ACPI bus type only if ACPI companion is not known") Signed-off-by: Rafael J. Wysocki Link: https://patch.msgid.link/3089807.e9J7NaK4W3@rafael.j.wysocki Signed-off-by: Sasha Levin --- drivers/acpi/glue.c | 61 +++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c index c01ebf20a9318..e2a40847d24b6 100644 --- a/drivers/acpi/glue.c +++ b/drivers/acpi/glue.c @@ -59,19 +59,34 @@ int unregister_acpi_bus_type(struct acpi_bus_type *type) } EXPORT_SYMBOL_GPL(unregister_acpi_bus_type); -static struct acpi_bus_type *acpi_get_bus_type(struct device *dev) +static struct acpi_device *acpi_companion_lookup(struct device *dev) { - struct acpi_bus_type *tmp, *ret = NULL; + struct acpi_bus_type *type; - down_read(&bus_type_sem); - list_for_each_entry(tmp, &bus_type_list, list) { - if (tmp->match(dev)) { - ret = tmp; - break; + guard(rwsem_read)(&bus_type_sem); + + list_for_each_entry(type, &bus_type_list, list) { + struct acpi_device *adev; + + if (!type->match(dev)) + continue; + + adev = type->find_companion(dev); + if (!adev) { + dev_dbg(dev, "ACPI companion not found\n"); + return NULL; } + if (acpi_bind_one(dev, adev)) { + dev_dbg(dev, "Binding to ACPI companion failed\n"); + return NULL; + } + if (type->setup) + type->setup(dev); + + return adev; } - up_read(&bus_type_sem); - return ret; + + return NULL; } #define FIND_CHILD_MIN_SCORE 1 @@ -362,40 +377,22 @@ void acpi_device_notify(struct device *dev) ret = acpi_bind_one(dev, NULL); if (ret) { - struct acpi_bus_type *type = acpi_get_bus_type(dev); - - if (!type) + adev = acpi_companion_lookup(dev); + if (!adev) return; - - adev = type->find_companion(dev); - if (!adev) { - dev_dbg(dev, "ACPI companion not found\n"); - return; - } - ret = acpi_bind_one(dev, adev); - if (ret) { - dev_dbg(dev, "Binding to ACPI companion failed\n"); - return; - } - if (type->setup) { - type->setup(dev); - goto done; - } } else { adev = ACPI_COMPANION(dev); if (dev_is_pci(dev)) { pci_acpi_setup(dev, adev); - goto done; } else if (dev_is_platform(dev)) { acpi_configure_pmsi_domain(dev); + + if (adev->handler && adev->handler->bind) + adev->handler->bind(dev); } } - if (adev->handler && adev->handler->bind) - adev->handler->bind(dev); - -done: dev_dbg(dev, "Bound to ACPI device %s\n", acpi_dev_name(adev)); } -- 2.53.0