* [PATCH] xen/privcmd: unregister xenstore notifier on init failure
@ 2026-11-29 0:41 Yuho Choi
0 siblings, 0 replies; only message in thread
From: Yuho Choi @ 2026-11-29 0:41 UTC (permalink / raw)
To: Juergen Gross, Stefano Stabellini
Cc: Oleksandr Tyshchenko, xen-devel, linux-kernel, Yuho Choi
In an unprivileged domU, privcmd_init() calls restrict_driver(), which
registers xenstore_notifier when Xenstore is not ready yet. If one of
the device registrations after it fails, privcmd_init() returns without
unregistering the notifier. With XEN_PRIVCMD=m, the module is then
freed while its notifier block is still on the xenstore chain: the next
register_xenstore_notifier() walks into freed module memory, and
init_restrict() would be called from it once Xenstore becomes ready.
Unregister the notifier on the error path, as privcmd_exit() does since
commit cd7e1fef5a1c ("xen/privcmd: unregister xenstore notifier on
module exit").
Fixes: 453b8fb68f36 ("xen/privcmd: restrict usage in unprivileged domU")
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
---
Tested on 8dac6df92a2e in a KASAN guest running as an HVM domU under
QEMU's KVM-based Xen emulation, with XEN_PRIVCMD=m. To keep Xenstore not
ready when the module loads (as when the guest waits for xenstored or a
Xenstore stub domain to start), the guest booted with
"xen_no_vector_callback initcall_blacklist=platform_driver_init", and a
test-only module parameter made the second misc_register() fail. Loading
the module with that failure and then loading it again gives, without
this patch:
notifier callback init_restrict [xen_privcmd] already registered
WARNING: kernel/notifier.c:24 at notifier_chain_register+0xd9/0x300, CPU#1: insmod/73
The module came back at the same address, so the chain walk found the
stale entry instead of reading freed memory. With this patch applied,
there is no warning.
drivers/xen/privcmd.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c
index 221b31611343..5983cf65b471 100644
--- a/drivers/xen/privcmd.c
+++ b/drivers/xen/privcmd.c
@@ -1750,7 +1750,7 @@ static int __init privcmd_init(void)
err = misc_register(&privcmd_dev);
if (err != 0) {
pr_err("Could not register Xen privcmd device\n");
- return err;
+ goto err_privcmd;
}
err = misc_register(&xen_privcmdbuf_dev);
@@ -1771,6 +1771,9 @@ static int __init privcmd_init(void)
misc_deregister(&xen_privcmdbuf_dev);
err_privcmdbuf:
misc_deregister(&privcmd_dev);
+err_privcmd:
+ if (!xen_initial_domain())
+ unregister_xenstore_notifier(&xenstore_notifier);
return err;
}
base-commit: 8dac6df92a2e66e2098bbc69061964cfe7e8375b
--
2.56.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-29 0:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 0:41 [PATCH] xen/privcmd: unregister xenstore notifier on init failure Yuho Choi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox