qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Joakim Tjernlund <Joakim.Tjernlund@transmode.se>
Cc: QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH 1/2 v2] qemu-user: Impl. setsockopt(SO_BINDTODEVICE)
Date: Sat, 12 Jul 2014 11:53:21 +0100	[thread overview]
Message-ID: <CAFEAcA9Fq6e6ahHzvzWmBKNyHrhpWkgmpiPDSBu+Z7qvJrxkVg@mail.gmail.com> (raw)
In-Reply-To: <1405158390-27397-1-git-send-email-Joakim.Tjernlund@transmode.se>

On 12 July 2014 10:46, Joakim Tjernlund <Joakim.Tjernlund@transmode.se> wrote:
> ---
>  linux-user/syscall.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 57c1664..5a07d9c 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -1497,6 +1497,25 @@ set_timeout:
>                  unlock_user_struct(tfprog, optval_addr, 1);
>                  return ret;
>          }
> +       case TARGET_SO_BINDTODEVICE:
> +       {
> +               char *dev_ifname, *addr_ifname;
> +
> +               dev_ifname = lock_user(VERIFY_READ, optval_addr, optlen, 1);
> +               if (!dev_ifname) {
> +                       return -TARGET_EFAULT;
> +               }
> +               if (optlen > IFNAMSIZ - 1) {
> +                       optlen = IFNAMSIZ - 1;
> +               }

This needs to go before the lock_user, not after.

> +               optname = SO_BINDTODEVICE;
> +               addr_ifname = alloca(IFNAMSIZ);
> +               memcpy(addr_ifname, dev_ifname, IFNAMSIZ);

You can't memcpy IFNAMSIZ bytes here because your source
might be shorter than that. memcpy() optlen bytes and set
addr_ifname[optlen] to 0.

> +               addr_ifname[IFNAMSIZ - 1] = 0;
> +               ret = get_errno(setsockopt(sockfd, level, optname, addr_ifname, optlen));
> +               unlock_user (dev_ifname, optval_addr, 0);
> +               return ret;
> +       }
>              /* Options with 'int' argument.  */
>          case TARGET_SO_DEBUG:
>                 optname = SO_DEBUG;
> --
> 1.8.5.5

Otherwise looks good; thanks.

thanks
-- PMM

      parent reply	other threads:[~2014-07-12 10:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-12  9:46 [Qemu-devel] [PATCH 1/2 v2] qemu-user: Impl. setsockopt(SO_BINDTODEVICE) Joakim Tjernlund
2014-07-12  9:46 ` [Qemu-devel] [PATCH 2/2 v2] linux-user: impl. sockaddr_ll Joakim Tjernlund
2014-07-12 10:56   ` Peter Maydell
2014-07-12 10:53 ` Peter Maydell [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=CAFEAcA9Fq6e6ahHzvzWmBKNyHrhpWkgmpiPDSBu+Z7qvJrxkVg@mail.gmail.com \
    --to=peter.maydell@linaro.org \
    --cc=Joakim.Tjernlund@transmode.se \
    --cc=qemu-devel@nongnu.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).