From nobody Sun Apr 12 22:37:38 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1775314977; cv=none; d=zohomail.com; s=zohoarc; b=EbGU1y/I/Yt6Urvi/Luec94f+/Ypr6X/SCqrHxdtnZkAF/kzJaPgImdOx4NGf/ffSY+fjTLI53Ik/jgOxoUCyOEhKid5DGO0SxBZ3MaOdoeGkgZmGptZngj+JxKmTkC4GjpqOsVd+V5oSQc55ni65D3cZJrDld/PvloVNd0QN3g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775314977; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=r1E7P/qeKjQotaRFo8AQvfvxC6vyLeAFvkBNArwq0dk=; b=CB/0tXMSMEQR5z8ZJiaVtjNMqVH6shiljXv0fttOSmAsp74tUJFj+FhgSdQu/yY38M4d4Ub3mC4f6YIAJ0YELMzvfd60C7SP3CpAJ8sJEqzPY4Oa3GDgD3ovYV6qlQhMw6ddynShWO8hr2Dy9VgpnSmM7ivV2GNxApPG+09M3CA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1775314977019958.6505173250002; Sat, 4 Apr 2026 08:02:57 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1273752.1560274 (Exim 4.92) (envelope-from ) id 1w92Vw-0001DZ-B3; Sat, 04 Apr 2026 15:02:20 +0000 Received: by outflank-mailman (output) from mailman id 1273752.1560274; Sat, 04 Apr 2026 15:02:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w92Vw-0001DR-7h; Sat, 04 Apr 2026 15:02:20 +0000 Received: by outflank-mailman (input) for mailman id 1273752; Sat, 04 Apr 2026 15:02:19 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w92Vv-0001DL-1d for xen-devel@lists.xenproject.org; Sat, 04 Apr 2026 15:02:19 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1w92Vu-007yaP-AA for xen-devel@lists.xenproject.org; Sat, 04 Apr 2026 17:02:18 +0200 Received: from [10.42.69.11] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69d127e8-e002-0a2a0a5209dd-0a2a450b9104-24 for ; Sat, 04 Apr 2026 17:02:18 +0200 Received: from [172.105.4.254] (helo=tor.source.kernel.org) by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.0) (envelope-from ) id 69d127f9-bca8-0a2a450b0019-ac6904fe9486-3 for ; Sat, 04 Apr 2026 17:02:17 +0200 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 32414600CB; Sat, 4 Apr 2026 15:02:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9BB2C19421; Sat, 4 Apr 2026 15:02:06 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=k20201202 header.d=kernel.org header.i="@kernel.org" header.h="From:To:Cc:Subject:Date:In-Reply-To:References" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775314935; bh=yS1a8GmMxhd+gaXjsrUMOyEcZUcN2vLf71oRyrhAVkk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fcd1WH1uMPDFcW95A5bP6twrmSlGywxDbhV9K4GUdxmnw9OhLho72J9OlIZREDDfv Evf5eg+FhGKnEBZMEi0xrGzL0W0wBBPFC5ZbOalQpNWyhGwDm3HuLGvy/jgjYAq60X Jsa257f9xIzRC/LnmHpxdh9mv/JRHNm7utYMn96WoZP6ZRATrlwe1+3BmjlR9bxRPR tiA87cPHB5ojtZQJ2zSKPbtecnXGON24oyWbrZcP9XuN+XivvmLrVCQGu5orrMZe/a +xDtWMIwREbTcGNYdTKbgyxE7aDCuXqmHaashK055GEOETa+XQlaspyrGVn7GrwOhI UHZOaAkc+kiUA== From: Danilo Krummrich To: Russell King , Greg Kroah-Hartman , "Rafael J. Wysocki" , Ioana Ciornei , Nipun Gupta , Nikhil Agarwal , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Bjorn Helgaas , Armin Wolf , Bjorn Andersson , Mathieu Poirier , Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Harald Freudenberger , Holger Dengler , Mark Brown , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Alex Williamson , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , "Christophe Leroy (CS GROUP)" Cc: linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, linuxppc-dev@lists.ozlabs.org, linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, linux-spi@vger.kernel.org, virtualization@lists.linux.dev, kvm@vger.kernel.org, xen-devel@lists.xenproject.org, linux-arm-kernel@lists.infradead.org, Danilo Krummrich , Michael Kelley , Gui-Dong Han Subject: [PATCH v2] Drivers: hv: vmbus: use generic driver_override infrastructure Date: Sat, 4 Apr 2026 17:01:49 +0200 Message-ID: <20260404150155.3473682-1-dakr@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-42698a/1775314938-EC3642A1-FAE8CD37/0/0 X-purgate-type: clean X-purgate-size: 4285 X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1775314978512154100 Content-Type: text/plain; charset="utf-8" When a driver is probed through __driver_attach(), the bus' match() callback is called without the device lock held, thus accessing the driver_override field without a lock, which can cause a UAF. Fix this by using the driver-core driver_override infrastructure taking care of proper locking internally. Note that calling match() from __driver_attach() without the device lock held is intentional. [1] Tested-by: Michael Kelley Reviewed-by: Michael Kelley Link: https://lore.kernel.org/driver-core/DGRGTIRHA62X.3RY09D9SOK77P@kernel= .org/ [1] Reported-by: Gui-Dong Han Closes: https://bugzilla.kernel.org/show_bug.cgi?id=3D220789 Fixes: d765edbb301c ("vmbus: add driver_override support") Signed-off-by: Danilo Krummrich --- Changes in v2: - Change patch subject and comments according to Michael's suggestion. --- drivers/hv/vmbus_drv.c | 43 ++++++++++-------------------------------- include/linux/hyperv.h | 5 ----- 2 files changed, 10 insertions(+), 38 deletions(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index bc4fc1951ae1..ba7326ec6add 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -541,34 +541,6 @@ static ssize_t device_show(struct device *dev, } static DEVICE_ATTR_RO(device); =20 -static ssize_t driver_override_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct hv_device *hv_dev =3D device_to_hv_device(dev); - int ret; - - ret =3D driver_set_override(dev, &hv_dev->driver_override, buf, count); - if (ret) - return ret; - - return count; -} - -static ssize_t driver_override_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct hv_device *hv_dev =3D device_to_hv_device(dev); - ssize_t len; - - device_lock(dev); - len =3D sysfs_emit(buf, "%s\n", hv_dev->driver_override); - device_unlock(dev); - - return len; -} -static DEVICE_ATTR_RW(driver_override); - /* Set up per device attributes in /sys/bus/vmbus/devices/ */ static struct attribute *vmbus_dev_attrs[] =3D { &dev_attr_id.attr, @@ -599,7 +571,6 @@ static struct attribute *vmbus_dev_attrs[] =3D { &dev_attr_channel_vp_mapping.attr, &dev_attr_vendor.attr, &dev_attr_device.attr, - &dev_attr_driver_override.attr, NULL, }; =20 @@ -711,9 +682,11 @@ static const struct hv_vmbus_device_id *hv_vmbus_get_i= d(const struct hv_driver * { const guid_t *guid =3D &dev->dev_type; const struct hv_vmbus_device_id *id; + int ret; =20 - /* When driver_override is set, only bind to the matching driver */ - if (dev->driver_override && strcmp(dev->driver_override, drv->name)) + /* If a driver override is set, only bind to the matching driver */ + ret =3D device_match_driver_override(&dev->device, &drv->driver); + if (ret =3D=3D 0) return NULL; =20 /* Look at the dynamic ids first, before the static ones */ @@ -721,8 +694,11 @@ static const struct hv_vmbus_device_id *hv_vmbus_get_i= d(const struct hv_driver * if (!id) id =3D hv_vmbus_dev_match(drv->id_table, guid); =20 - /* driver_override will always match, send a dummy id */ - if (!id && dev->driver_override) + /* + * If there's a matching driver override, this function should succeed, + * thus return a dummy device ID if no matching ID is found. + */ + if (!id && ret > 0) id =3D &vmbus_device_null; =20 return id; @@ -1024,6 +1000,7 @@ static const struct dev_pm_ops vmbus_pm =3D { /* The one and only one */ static const struct bus_type hv_bus =3D { .name =3D "vmbus", + .driver_override =3D true, .match =3D vmbus_match, .shutdown =3D vmbus_shutdown, .remove =3D vmbus_remove, diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index dfc516c1c719..bf689d07d750 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -1272,11 +1272,6 @@ struct hv_device { u16 device_id; =20 struct device device; - /* - * Driver name to force a match. Do not set directly, because core - * frees it. Use driver_set_override() to set or clear it. - */ - const char *driver_override; =20 struct vmbus_channel *channel; struct kset *channels_kset; --=20 2.53.0