2023-10-16 07:12:08

by Viresh Kumar

[permalink] [raw]
Subject: [PATCH V4 1/4] xen: Make struct privcmd_irqfd's layout architecture independent

Using indirect pointers in an ioctl command argument means that the
layout is architecture specific, in particular we can't use the same one
from 32-bit compat tasks. The general recommendation is to have __u64
members and use u64_to_user_ptr() to access it from the kernel if we are
unable to avoid the pointers altogether.

Fixes: f8941e6c4c71 ("xen: privcmd: Add support for irqfd")
Reported-by: Arnd Bergmann <[email protected]>
Closes: https://lore.kernel.org/all/[email protected]/
Signed-off-by: Viresh Kumar <[email protected]>
---
drivers/xen/privcmd.c | 2 +-
include/uapi/xen/privcmd.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c
index 120af57999fc..5095bd1abea5 100644
--- a/drivers/xen/privcmd.c
+++ b/drivers/xen/privcmd.c
@@ -935,7 +935,7 @@ static int privcmd_irqfd_assign(struct privcmd_irqfd *irqfd)
return -ENOMEM;
dm_op = kirqfd + 1;

- if (copy_from_user(dm_op, irqfd->dm_op, irqfd->size)) {
+ if (copy_from_user(dm_op, u64_to_user_ptr(irqfd->dm_op), irqfd->size)) {
ret = -EFAULT;
goto error_kfree;
}
diff --git a/include/uapi/xen/privcmd.h b/include/uapi/xen/privcmd.h
index 375718ba4ab6..b143fafce84d 100644
--- a/include/uapi/xen/privcmd.h
+++ b/include/uapi/xen/privcmd.h
@@ -102,7 +102,7 @@ struct privcmd_mmap_resource {
#define PRIVCMD_IRQFD_FLAG_DEASSIGN (1 << 0)

struct privcmd_irqfd {
- void __user *dm_op;
+ __u64 dm_op;
__u32 size; /* Size of structure pointed by dm_op */
__u32 fd;
__u32 flags;
--
2.31.1.272.g89b43f80a514


2023-10-16 07:13:39

by Juergen Gross

[permalink] [raw]
Subject: Re: [PATCH V4 1/4] xen: Make struct privcmd_irqfd's layout architecture independent

On 16.10.23 09:11, Viresh Kumar wrote:
> Using indirect pointers in an ioctl command argument means that the
> layout is architecture specific, in particular we can't use the same one
> from 32-bit compat tasks. The general recommendation is to have __u64
> members and use u64_to_user_ptr() to access it from the kernel if we are
> unable to avoid the pointers altogether.
>
> Fixes: f8941e6c4c71 ("xen: privcmd: Add support for irqfd")
> Reported-by: Arnd Bergmann <[email protected]>
> Closes: https://lore.kernel.org/all/[email protected]/
> Signed-off-by: Viresh Kumar <[email protected]>

Reviewed-by: Juergen Gross <[email protected]>


Juergen


Attachments:
OpenPGP_0xB0DE9DD628BF132F.asc (3.08 kB)
OpenPGP public key
OpenPGP_signature.asc (505.00 B)
OpenPGP digital signature
Download all attachments