Skip to content

Commit 78432d8

Browse files
jgross1gregkh
authored andcommitted
xen/privcmd: restrict usage in unprivileged domU
commit 453b8fb upstream. The Xen privcmd driver allows to issue arbitrary hypercalls from user space processes. This is normally no problem, as access is usually limited to root and the hypervisor will deny any hypercalls affecting other domains. In case the guest is booted using secure boot, however, the privcmd driver would be enabling a root user process to modify e.g. kernel memory contents, thus breaking the secure boot feature. The only known case where an unprivileged domU is really needing to use the privcmd driver is the case when it is acting as the device model for another guest. In this case all hypercalls issued via the privcmd driver will target that other guest. Fortunately the privcmd driver can already be locked down to allow only hypercalls targeting a specific domain, but this mode can be activated from user land only today. The target domain can be obtained from Xenstore, so when not running in dom0 restrict the privcmd driver to that target domain from the beginning, resolving the potential problem of breaking secure boot. This is XSA-482 Reported-by: Teddy Astie <teddy.astie@vates.tech> Fixes: 1c5de19 ("xen: add privcmd driver") Signed-off-by: Juergen Gross <jgross@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 80b02e9 commit 78432d8

1 file changed

Lines changed: 57 additions & 3 deletions

File tree

drivers/xen/privcmd.c

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/eventfd.h>
1313
#include <linux/file.h>
1414
#include <linux/kernel.h>
15+
#include <linux/kstrtox.h>
1516
#include <linux/module.h>
1617
#include <linux/mutex.h>
1718
#include <linux/poll.h>
@@ -30,7 +31,9 @@
3031
#include <linux/seq_file.h>
3132
#include <linux/miscdevice.h>
3233
#include <linux/moduleparam.h>
34+
#include <linux/notifier.h>
3335
#include <linux/virtio_mmio.h>
36+
#include <linux/wait.h>
3437

3538
#include <asm/xen/hypervisor.h>
3639
#include <asm/xen/hypercall.h>
@@ -46,6 +49,7 @@
4649
#include <xen/page.h>
4750
#include <xen/xen-ops.h>
4851
#include <xen/balloon.h>
52+
#include <xen/xenbus.h>
4953
#ifdef CONFIG_XEN_ACPI
5054
#include <xen/acpi.h>
5155
#endif
@@ -72,6 +76,11 @@ struct privcmd_data {
7276
domid_t domid;
7377
};
7478

79+
/* DOMID_INVALID implies no restriction */
80+
static domid_t target_domain = DOMID_INVALID;
81+
static bool restrict_wait;
82+
static DECLARE_WAIT_QUEUE_HEAD(restrict_wait_wq);
83+
7584
static int privcmd_vma_range_is_mapped(
7685
struct vm_area_struct *vma,
7786
unsigned long addr,
@@ -1582,13 +1591,16 @@ static long privcmd_ioctl(struct file *file,
15821591

15831592
static int privcmd_open(struct inode *ino, struct file *file)
15841593
{
1585-
struct privcmd_data *data = kzalloc(sizeof(*data), GFP_KERNEL);
1594+
struct privcmd_data *data;
1595+
1596+
if (wait_event_interruptible(restrict_wait_wq, !restrict_wait) < 0)
1597+
return -EINTR;
15861598

1599+
data = kzalloc(sizeof(*data), GFP_KERNEL);
15871600
if (!data)
15881601
return -ENOMEM;
15891602

1590-
/* DOMID_INVALID implies no restriction */
1591-
data->domid = DOMID_INVALID;
1603+
data->domid = target_domain;
15921604

15931605
file->private_data = data;
15941606
return 0;
@@ -1681,13 +1693,55 @@ static struct miscdevice privcmd_dev = {
16811693
.fops = &xen_privcmd_fops,
16821694
};
16831695

1696+
static int init_restrict(struct notifier_block *notifier,
1697+
unsigned long event,
1698+
void *data)
1699+
{
1700+
char *target;
1701+
unsigned int domid;
1702+
1703+
/* Default to an guaranteed unused domain-id. */
1704+
target_domain = DOMID_IDLE;
1705+
1706+
target = xenbus_read(XBT_NIL, "target", "", NULL);
1707+
if (IS_ERR(target) || kstrtouint(target, 10, &domid)) {
1708+
pr_err("No target domain found, blocking all hypercalls\n");
1709+
goto out;
1710+
}
1711+
1712+
target_domain = domid;
1713+
1714+
out:
1715+
if (!IS_ERR(target))
1716+
kfree(target);
1717+
1718+
restrict_wait = false;
1719+
wake_up_all(&restrict_wait_wq);
1720+
1721+
return NOTIFY_DONE;
1722+
}
1723+
1724+
static struct notifier_block xenstore_notifier = {
1725+
.notifier_call = init_restrict,
1726+
};
1727+
1728+
static void __init restrict_driver(void)
1729+
{
1730+
restrict_wait = true;
1731+
1732+
register_xenstore_notifier(&xenstore_notifier);
1733+
}
1734+
16841735
static int __init privcmd_init(void)
16851736
{
16861737
int err;
16871738

16881739
if (!xen_domain())
16891740
return -ENODEV;
16901741

1742+
if (!xen_initial_domain())
1743+
restrict_driver();
1744+
16911745
err = misc_register(&privcmd_dev);
16921746
if (err != 0) {
16931747
pr_err("Could not register Xen privcmd device\n");

0 commit comments

Comments
 (0)