From 50d7d967bbfdcaf38bfac1c3bcc985a31fed26ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Date: Wed, 17 Nov 2021 11:48:35 +0100 Subject: [PATCH] xen/privcmd: fix MMAP_RESOURCE ioctl to copy out results The current definition for the MMAP_RESOURCE ioctl was wrong as it didn't copy back the result to the caller. Fix the definition and also remove the bogus attempt to copy the result in the implementation. Note such copy back is only needed when querying the size of a resource. Sponsored by: Citrix Systems R&D --- sys/dev/xen/privcmd/privcmd.c | 8 +++----- sys/xen/privcmd.h | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/sys/dev/xen/privcmd/privcmd.c b/sys/dev/xen/privcmd/privcmd.c index 0ef6737df64f..763c2f471c4f 100644 --- a/sys/dev/xen/privcmd/privcmd.c +++ b/sys/dev/xen/privcmd/privcmd.c @@ -426,12 +426,10 @@ privcmd_ioctl(struct cdev *dev, unsigned long cmd, caddr_t arg, if (mmap->addr == 0 && mmap->num == 0) { error = HYPERVISOR_memory_op(XENMEM_acquire_resource, &adq); - if (error != 0) { + if (error != 0) error = xen_translate_error(error); - break; - } - error = copyout(&adq.nr_frames, &mmap->num, - sizeof(mmap->num)); + else + mmap->num = adq.nr_frames; break; } diff --git a/sys/xen/privcmd.h b/sys/xen/privcmd.h index 55a1cdc86471..605ba018ac34 100644 --- a/sys/xen/privcmd.h +++ b/sys/xen/privcmd.h @@ -79,7 +79,7 @@ struct ioctl_privcmd_dmop { #define IOCTL_PRIVCMD_MMAPBATCH \ _IOWR('E', 1, struct ioctl_privcmd_mmapbatch) #define IOCTL_PRIVCMD_MMAP_RESOURCE \ - _IOW('E', 2, struct ioctl_privcmd_mmapresource) + _IOWR('E', 2, struct ioctl_privcmd_mmapresource) #define IOCTL_PRIVCMD_DM_OP \ _IOW('E', 3, struct ioctl_privcmd_dmop) #define IOCTL_PRIVCMD_RESTRICT \