[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] xen/privcmd: unregister xenstore notifier on init failure



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@xxxxxxxxx>
---
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




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.