qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Vivier <laurent@vivier.eu>
To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>, qemu-devel@nongnu.org
Cc: Helge Deller <deller@gmx.de>,
	Richard Henderson <richard.henderson@linaro.org>,
	Conrad Meyer <cem@FreeBSD.org>
Subject: Re: [PATCH v2] linux-user: Correct host errno for IP[V6]_RECVERR socket options
Date: Mon, 13 Sep 2021 21:17:43 +0200	[thread overview]
Message-ID: <9d26f735-cf85-f64e-d2ce-eebba964f99e@vivier.eu> (raw)
In-Reply-To: <20210911170814.537351-1-f4bug@amsat.org>

Le 11/09/2021 à 19:08, Philippe Mathieu-Daudé a écrit :
> Host errno must be converted to target errno in IP_RECVERR
> and IPV6_RECVERR socket options.
> 
> Fixes: ee1ac3a1822 ("linux-user: Add sockopts for IPv6")
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/602
> Reported-by: Conrad Meyer <cem@FreeBSD.org>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> v2: Corrected patch description
> ---
>  linux-user/syscall.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index ccd3892b2df..edc9d6b5ba2 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -1967,7 +1967,8 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
>                      tgt_len != sizeof(struct errhdr_t)) {
>                      goto unimplemented;
>                  }
> -                __put_user(errh->ee.ee_errno, &target_errh->ee.ee_errno);
> +                __put_user(get_errno(errh->ee.ee_errno),
> +                           &target_errh->ee.ee_errno);
>                  __put_user(errh->ee.ee_origin, &target_errh->ee.ee_origin);
>                  __put_user(errh->ee.ee_type,  &target_errh->ee.ee_type);
>                  __put_user(errh->ee.ee_code, &target_errh->ee.ee_code);
> @@ -2011,7 +2012,8 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
>                      tgt_len != sizeof(struct errhdr6_t)) {
>                      goto unimplemented;
>                  }
> -                __put_user(errh->ee.ee_errno, &target_errh->ee.ee_errno);
> +                __put_user(get_errno(errh->ee.ee_errno),
> +                           &target_errh->ee.ee_errno);
>                  __put_user(errh->ee.ee_origin, &target_errh->ee.ee_origin);
>                  __put_user(errh->ee.ee_type,  &target_errh->ee.ee_type);
>                  __put_user(errh->ee.ee_code, &target_errh->ee.ee_code);
> 


I don't think it's the correct use of get_errno() here.

get_errno() is:

static inline abi_long get_errno(abi_long ret)
{
    if (ret == -1)
        return -host_to_target_errno(errno);
    else
        return ret;
}

and ee_errno is:

struct sock_extended_err {
        __u32   ee_errno;
        __u8    ee_origin;
        __u8    ee_type;
        __u8    ee_code;
        __u8    ee_pad;
        __u32   ee_info;
        union   {
                __u32   ee_data;
                struct sock_ee_data_rfc4884 ee_rfc4884;
        };
};

https://man7.org/linux/man-pages/man7/ip.7.html

     ee_errno contains the errno number of the queued error.

so ee_errno is never negative.

You should use "host_to_target_errno(errh->ee.ee_errno)"

Thanks,
Laurent


      reply	other threads:[~2021-09-13 19:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-11 17:08 [PATCH v2] linux-user: Correct host errno for IP[V6]_RECVERR socket options Philippe Mathieu-Daudé
2021-09-13 19:17 ` Laurent Vivier [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9d26f735-cf85-f64e-d2ce-eebba964f99e@vivier.eu \
    --to=laurent@vivier.eu \
    --cc=cem@FreeBSD.org \
    --cc=deller@gmx.de \
    --cc=f4bug@amsat.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).