Skip to content

Commit cbede2e

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 6f11461 commit cbede2e

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,
@@ -1562,13 +1571,16 @@ static long privcmd_ioctl(struct file *file,
15621571

15631572
static int privcmd_open(struct inode *ino, struct file *file)
15641573
{
1565-
struct privcmd_data *data = kzalloc(sizeof(*data), GFP_KERNEL);
1574+
struct privcmd_data *data;
1575+
1576+
if (wait_event_interruptible(restrict_wait_wq, !restrict_wait) < 0)
1577+
return -EINTR;
15661578

1579+
data = kzalloc(sizeof(*data), GFP_KERNEL);
15671580
if (!data)
15681581
return -ENOMEM;
15691582

1570-
/* DOMID_INVALID implies no restriction */
1571-
data->domid = DOMID_INVALID;
1583+
data->domid = target_domain;
15721584

15731585
file->private_data = data;
15741586
return 0;
@@ -1661,13 +1673,55 @@ static struct miscdevice privcmd_dev = {
16611673
.fops = &xen_privcmd_fops,
16621674
};
16631675

1676+
static int init_restrict(struct notifier_block *notifier,
1677+
unsigned long event,
1678+
void *data)
1679+
{
1680+
char *target;
1681+
unsigned int domid;
1682+
1683+
/* Default to an guaranteed unused domain-id. */
1684+
target_domain = DOMID_IDLE;
1685+
1686+
target = xenbus_read(XBT_NIL, "target", "", NULL);
1687+
if (IS_ERR(target) || kstrtouint(target, 10, &domid)) {
1688+
pr_err("No target domain found, blocking all hypercalls\n");
1689+
goto out;
1690+
}
1691+
1692+
target_domain = domid;
1693+
1694+
out:
1695+
if (!IS_ERR(target))
1696+
kfree(target);
1697+
1698+
restrict_wait = false;
1699+
wake_up_all(&restrict_wait_wq);
1700+
1701+
return NOTIFY_DONE;
1702+
}
1703+
1704+
static struct notifier_block xenstore_notifier = {
1705+
.notifier_call = init_restrict,
1706+
};
1707+
1708+
static void __init restrict_driver(void)
1709+
{
1710+
restrict_wait = true;
1711+
1712+
register_xenstore_notifier(&xenstore_notifier);
1713+
}
1714+
16641715
static int __init privcmd_init(void)
16651716
{
16661717
int err;
16671718

16681719
if (!xen_domain())
16691720
return -ENODEV;
16701721

1722+
if (!xen_initial_domain())
1723+
restrict_driver();
1724+
16711725
err = misc_register(&privcmd_dev);
16721726
if (err != 0) {
16731727
pr_err("Could not register Xen privcmd device\n");

0 commit comments

Comments
 (0)