From: Jiale Yao <yaojiale02@163.com>
To: Haiyang Zhang <haiyangz@microsoft.com>,
Wei Liu <wei.liu@kernel.org>, Dexuan Cui <decui@microsoft.com>,
Stephen Hemminger <stephen@networkplumber.org>,
"K. Y. Srinivasan" <kys@microsoft.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH v2 1/2] Drivers: hv: vmbus: prevent duplicate dynamic IDs
Date: Wed, 21 Oct 2026 22:33:22 +0800 [thread overview]
Message-ID: <20261021143323.338146-2-yaojiale02@163.com> (raw)
In-Reply-To: <20261021143323.338146-1-yaojiale02@163.com>
new_id_store() checks for an existing dynamic ID before calling
vmbus_add_dynid(), but the check and insertion use separate critical
sections. Two concurrent writers can therefore both observe that a GUID is
absent and add duplicate entries. Removing the GUID once then leaves the
duplicate active.
Move the duplicate check into vmbus_add_dynid() so it is performed under
the same lock as the list insertion.
Fixes: fc76936d3ea5 ("vmbus: add support for dynamic device id's")
Cc: stable@vger.kernel.org
Signed-off-by: Jiale Yao <yaojiale02@163.com>
---
drivers/hv/vmbus_drv.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 4692687cdbf3..1037117e2d81 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -737,7 +737,7 @@ static const struct hv_vmbus_device_id *hv_vmbus_get_id(const struct hv_driver *
*/
static int vmbus_add_dynid(struct hv_driver *drv, guid_t *guid)
{
- struct vmbus_dynid *dynid;
+ struct vmbus_dynid *dynid, *existing;
dynid = kzalloc_obj(*dynid);
if (!dynid)
@@ -745,9 +745,16 @@ static int vmbus_add_dynid(struct hv_driver *drv, guid_t *guid)
dynid->id.guid = *guid;
- spin_lock(&drv->dynids.lock);
- list_add_tail(&dynid->node, &drv->dynids.list);
- spin_unlock(&drv->dynids.lock);
+ scoped_guard(spinlock, &drv->dynids.lock) {
+ list_for_each_entry(existing, &drv->dynids.list, node) {
+ if (guid_equal(&existing->id.guid, guid)) {
+ kfree(dynid);
+ return -EEXIST;
+ }
+ }
+
+ list_add_tail(&dynid->node, &drv->dynids.list);
+ }
return driver_attach(&drv->driver);
}
@@ -780,9 +787,6 @@ static ssize_t new_id_store(struct device_driver *driver, const char *buf,
if (retval)
return retval;
- if (hv_vmbus_dynid_match(drv, &guid))
- return -EEXIST;
-
retval = vmbus_add_dynid(drv, &guid);
if (retval)
return retval;
--
2.34.1
next prev parent reply other threads:[~2026-10-21 14:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 14:33 [PATCH v2 0/2] Drivers: hv: vmbus: fix dynamic ID races Jiale Yao
2026-10-21 14:33 ` Jiale Yao [this message]
2026-10-21 14:33 ` [PATCH v2 2/2] Drivers: hv: vmbus: copy dynamic IDs before dropping the lock Jiale Yao
2026-10-24 0:41 ` Kameron Carr
2026-10-24 0:42 ` [PATCH v2 0/2] Drivers: hv: vmbus: fix dynamic ID races Kameron Carr
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261021143323.338146-2-yaojiale02@163.com \
--to=yaojiale02@163.com \
--cc=decui@microsoft.com \
--cc=gregkh@linuxfoundation.org \
--cc=haiyangz@microsoft.com \
--cc=kys@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=stephen@networkplumber.org \
--cc=wei.liu@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®