[Top][All Lists]

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

Re: [Qemu-devel] [PATCH] linux-user: ioctl() command type is int

From: Peter Maydell
Subject: Re: [Qemu-devel] [PATCH] linux-user: ioctl() command type is int
Date: Fri, 22 May 2015 13:49:53 +0100

On 21 May 2015 at 23:18, Laurent Vivier <address@hidden> wrote:
> When executing a 64bit target chroot on 64bit host,
> the ioctl() command can mismatch.
> It seems the previous commit doesn't solve the problem in
> my case:
>         9c6bf9c7 linux-user: Fix ioctl cmd type mismatch on 64-bit targets
> For example, a ppc64 chroot on an x86_64 host:
> bash-4.3# ls
> Unsupported ioctl: cmd=0x80087467
> Unsupported ioctl: cmd=0x802c7415
> The origin of the problem is in syscall.c:do_ioctl().
>         static abi_long do_ioctl(int fd, abi_long cmd, abi_long arg)
> In this case (ppc64) abi_long is long (on the x86_64), and
>     cmd = 0x0000000080087467
> then
>         if (ie->target_cmd == cmd)
> target_cmd is int, so target_cmd = 0x80087467
> and to compare an int with a long, the sign is extended to 64bit,
> so the comparison is:
>         if (0xffffffff80087467 == 0x0000000080087467)
> which doesn't match whereas it should.
> This patch uses abi_int in the case of the target command type
> instead of abi_long (and for consistency, update IOCTLEntry).

abi_int is really only needed in guest-layout structure
declarations, since it has alignment attributes but is
otherwise guaranteed to be an int32_t (and we assume all
over the place that int is 32 bits, so int is ok too).
So it's unnecessary in the function prototypes, and
I think actively harmful in the IOCTLEntry struct (since
that struct is not a shared-with-guest one).

I think also the do_ioctl_fn() prototype and all the
do_ioctl_* functions which are of that type need to have
the cmd parameter switched from abi_long. This avoids
potentially running into the same problem inside a
do_ioctl function if it does comparisons on the cmd.

-- PMM

reply via email to

[Prev in Thread] Current Thread [Next in Thread]