qemu-trivial
[Top][All Lists]
Advanced

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

Re: [PATCH 1/1] linux-user/syscall: Fix do_ioctl_ifconf() for 64 bit tar


From: Laurent Vivier
Subject: Re: [PATCH 1/1] linux-user/syscall: Fix do_ioctl_ifconf() for 64 bit targets.
Date: Mon, 18 Jan 2021 15:03:24 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0

Le 09/01/2021 à 19:59, Stefan a écrit :
> The sizeof(struct ifreq) is 40 for 64 bit and 32 for 32 bit architectures.
> This structure contains a union of other structures, of which struct ifmap
> is the biggest for 64 bit architectures. Calling ioclt(…, SIOCGIFCONF, …)
> fills a struct sockaddr of that union, and do_ioctl_ifconf() only considered
> that struct sockaddr for the size of the union, which has the same size as
> struct ifmap on 32 bit architectures. So do_ioctl_ifconf() assumed a wrong
> size of 32 for struct ifreq instead of the correct size of 40 on 64 bit
> architectures.
> 
> The fix makes do_ioctl_ifconf() handle struct ifmap as the biggest part of
> the union, treating struct ifreq with the correct size.
> 
> Signed-off-by: Stefan <stefan-guix@vodafonemail.de>
> ---
>   linux-user/syscall.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index d182890ff0..15a6abadc1 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -4902,6 +4902,7 @@ static abi_long do_ioctl_ifconf(const IOCTLEntry *ie, 
> uint8_t *buf_temp,
>       struct ifconf *host_ifconf;
>       uint32_t outbufsz;
>       const argtype ifreq_arg_type[] = { MK_STRUCT(STRUCT_sockaddr_ifreq) };
> +    const argtype ifreq_max_type[] = { MK_STRUCT(STRUCT_ifmap_ifreq) };

Why don't you simply replace STRUCT_sockaddr_ifreq by STRUCT_ifmap_ifreq rather 
than introducing a
new constant?

>       int target_ifreq_size;
>       int nb_ifreq;
>       int free_buf = 0;
> @@ -4925,7 +4926,7 @@ static abi_long do_ioctl_ifconf(const IOCTLEntry *ie, 
> uint8_t *buf_temp,
>   
>       host_ifconf = (struct ifconf *)(unsigned long)buf_temp;
>       target_ifc_buf = (abi_long)(unsigned long)host_ifconf->ifc_buf;
> -    target_ifreq_size = thunk_type_size(ifreq_arg_type, 0);
> +    target_ifreq_size = thunk_type_size(ifreq_max_type, 0);
>   
>       if (target_ifc_buf != 0) {
>           target_ifc_len = host_ifconf->ifc_len;
> 

In the "if (!is_error(ret))", why don't you use the same size with the part 
that copies back the
values to the user?

Thanks,
Laurent




reply via email to

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