Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3629600pxb; Mon, 24 Jan 2022 13:56:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJzHbW6Kg9U1cICvU+/ydzeQT8bXmGyc7aF8P2GlWdcTCuqSA518nbdrHu/tM+oUBNY4XxUu X-Received: by 2002:a05:6a00:10d5:b0:4bc:a0eb:c6a0 with SMTP id d21-20020a056a0010d500b004bca0ebc6a0mr15740767pfu.70.1643061275810; Mon, 24 Jan 2022 13:54:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643061275; cv=none; d=google.com; s=arc-20160816; b=x4bxOVFvvH2qhXKKrlHcbReXVTPEVImvNG/mxiHtrbXRfhfbmB4Cd3hMFrle26xio7 jtUv/7I9pE85I30G7UJv8bC0y3cEkSQ8Em9vn07mSlAGD/BxEUtW5xr1yJCBhuGeLoHO 2Qwiz+BKPLbAXtAn9i5//X+y6L8u3beKQQyh7uWDVrNFdE4NLzZPGD2ojSNbPOxwLv6M TwI/X6v/UPzVc8usbdpzMBOb9tnO8iih1AJ3vwjGioH6nLLtsK+LktFnOMEK1sVoPWVt Izny/Vjdvo23757EaxnK8uE2pVK8Ez8Bc4lx3ehiZw+5jwf0H6a6yGYCKGaEVLslg7Y1 VKUA== 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=LbtVWJwKe5xGQMgQzI9ER0BzW0ke1HOe3tRS7O0S8t0=; b=M4epTvFa4D+G/lX8XMEiSpP21/Q4yYszkbCz7Ig3nUGJq9LHKTJe//mmRnDuJf6UZa 0A4tFM0GiM3Ssospj3xsTiR9iuIuES3qdSO5C7RDdETXVumGULpM7hvCXWnY0Q1xvRUY Oyqp4z3SpqXduDDMlkjuUdEvFMvuPVlnlc6vhTKCXXIARq/XU6xpESLiF4SgsPhm2YYz CLIOcgOpfRSz4oHamgcLijEYSsHsFTQKY5SWcHbSZO4kYrfuDal7mZ1vl03aKZURwSkl +J/ZK19EtGYOa92rStClhm0eXmaU6jUNu+w4NvtDhU5RZABd1GHiJtEonDRl/WHmDpgs ousg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TlV+OK3A; 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 u11si16520413pgp.652.2022.01.24.13.54.19; Mon, 24 Jan 2022 13:54:35 -0800 (PST) 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=TlV+OK3A; 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 S1457518AbiAXVlp (ORCPT + 99 others); Mon, 24 Jan 2022 16:41:45 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:57456 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445711AbiAXVEs (ORCPT ); Mon, 24 Jan 2022 16:04:48 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 21F5AB8123D; Mon, 24 Jan 2022 21:04:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20E8DC340EA; Mon, 24 Jan 2022 21:04:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058284; bh=B2XzkCbD1hJiPE4C447BD00cSG+WKckSPUTUv11flOc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TlV+OK3AQtKuEjxHrjSkMzA/cvGhFvpVh626t0eOIK7rAikFAQueTt5m//8b11MQ4 hyRaZ5c2cpZSc7cBrgSaLubsVAYIIA9bDEi4TLzmvKGoRQfGE+J4MmDEKd34CNVeSX YY50MTIfpOUfrsOaublkzQaUy98wAlFyY4eRMGTA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Shevchenko , Hans de Goede , Sasha Levin Subject: [PATCH 5.16 0240/1039] platform/x86: wmi: Fix driver->notify() vs ->probe() race Date: Mon, 24 Jan 2022 19:33:49 +0100 Message-Id: <20220124184133.392081454@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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: Hans de Goede [ Upstream commit 9918878676a5f9e99b98679f04b9e6c0f5426b0a ] The driver core sets struct device->driver before calling out to the bus' probe() method, this leaves a window where an ACPI notify may happen on the WMI object before the driver's probe() method has completed running, causing e.g. the driver's notify() callback to get called with drvdata not yet being set leading to a NULL pointer deref. At a check for this to the WMI core, ensuring that the notify() callback is not called before the driver is ready. Fixes: 1686f5444546 ("platform/x86: wmi: Incorporate acpi_install_notify_handler") Reviewed-by: Andy Shevchenko Signed-off-by: Hans de Goede Link: https://lore.kernel.org/r/20211128190031.405620-2-hdegoede@redhat.com Signed-off-by: Sasha Levin --- drivers/platform/x86/wmi.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index 46178e03aecad..02aba274c4bc2 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -59,6 +59,7 @@ static_assert(__alignof__(struct guid_block) == 1); enum { /* wmi_block flags */ WMI_READ_TAKES_NO_ARGS, + WMI_PROBED, }; struct wmi_block { @@ -1008,6 +1009,7 @@ static int wmi_dev_probe(struct device *dev) } } + set_bit(WMI_PROBED, &wblock->flags); return 0; probe_misc_failure: @@ -1025,6 +1027,8 @@ static void wmi_dev_remove(struct device *dev) struct wmi_block *wblock = dev_to_wblock(dev); struct wmi_driver *wdriver = drv_to_wdrv(dev->driver); + clear_bit(WMI_PROBED, &wblock->flags); + if (wdriver->filter_callback) { misc_deregister(&wblock->char_dev); kfree(wblock->char_dev.name); @@ -1322,7 +1326,7 @@ static void acpi_wmi_notify_handler(acpi_handle handle, u32 event, return; /* If a driver is bound, then notify the driver. */ - if (wblock->dev.dev.driver) { + if (test_bit(WMI_PROBED, &wblock->flags) && wblock->dev.dev.driver) { struct wmi_driver *driver = drv_to_wdrv(wblock->dev.dev.driver); struct acpi_buffer evdata = { ACPI_ALLOCATE_BUFFER, NULL }; acpi_status status; -- 2.34.1