virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Amos Kong <akong@redhat.com>
To: Stefan Hajnoczi <stefanha@gmail.com>
Cc: kvm@vger.kernel.org, mst@redhat.com, qemu-devel@nongnu.org,
	virtualization@lists.linux-foundation.org, stefanha@redhat.com
Subject: Re: [QEMU PATCH v4 2/3] virtio-net: introduce a new macaddr control
Date: Tue, 22 Jan 2013 19:37:22 +0800	[thread overview]
Message-ID: <20130122113722.GA4066@t430s.nay.redhat.com> (raw)
In-Reply-To: <20130121160826.GD24473@stefanha-thinkpad.redhat.com>

On Mon, Jan 21, 2013 at 05:08:26PM +0100, Stefan Hajnoczi wrote:
> On Sat, Jan 19, 2013 at 09:54:27AM +0800, akong@redhat.com wrote:
> > @@ -350,6 +351,18 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd,
> >      struct virtio_net_ctrl_mac mac_data;
> >      size_t s;
> >  
> > +    if (cmd == VIRTIO_NET_CTRL_MAC_ADDR_SET) {
> > +        if (iov_size(iov, iov_cnt) != ETH_ALEN) {
> > +            return VIRTIO_NET_ERR;
> > +        }
> > +        s = iov_to_buf(iov, iov_cnt, 0, &n->mac, sizeof(n->mac));
> > +        if (s != sizeof(n->mac)) {
> > +            return VIRTIO_NET_ERR;
> > +        }

     
> Since iov_size() was checked before iov_to_buf(), we never hit this
> error.  And if we did n->mac would be trashed (i.e. error handling is
> not complete).

You are right.
iov_size() computes the size by accounting iov[].iov_lens, the first
check is enough.
 
> I think assert(s == sizeof(n->mac)) is more appropriate appropriate.
> Also, please change ETH_ALEN to sizeof(n->mac) to make the relationship
> between the check and the copy clear.
> 

Will update this patch.

         if (cmd == VIRTIO_NET_CTRL_MAC_ADDR_SET) {
             if (iov_size(iov, iov_cnt) != sizeof(n->mac)) {
                 return VIRTIO_NET_ERR;
             }
             s = iov_to_buf(iov, iov_cnt, 0, &n->mac, sizeof(n->mac));
             assert(s == sizeof(n->mac));
             qemu_format_nic_info_str(&n->nic->nc, n->mac);
             return VIRTIO_NET_OK;
         }

> Stefan

      reply	other threads:[~2013-01-22 11:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-19  1:54 [QEMU PATCH v4 0/3] virtio-net: fix of ctrl commands akong
2013-01-19  1:54 ` [QEMU PATCH v4 1/3] virtio-net: remove layout assumptions for ctrl vq akong
2013-01-19  2:08   ` [Qemu-devel] " Amos Kong
2013-01-21 16:03   ` Stefan Hajnoczi
2013-01-22 14:38     ` Amos Kong
     [not found]     ` <20130122143814.GB4066@t430s.nay.redhat.com>
2013-01-22 14:49       ` Stefan Hajnoczi
2013-01-19  1:54 ` [QEMU PATCH v4 2/3] virtio-net: introduce a new macaddr control akong
2013-01-19  1:54 ` [QEMU PATCH v4 3/3] virtio-net: rename ctrl rx commands akong
     [not found] ` <1358560468-10865-3-git-send-email-akong@redhat.com>
2013-01-21 16:08   ` [QEMU PATCH v4 2/3] virtio-net: introduce a new macaddr control Stefan Hajnoczi
2013-01-22 11:37     ` Amos Kong [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=20130122113722.GA4066@t430s.nay.redhat.com \
    --to=akong@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.com \
    --cc=stefanha@redhat.com \
    --cc=virtualization@lists.linux-foundation.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).