2013-06-05 21:10:35

by Luiz Capitulino

[permalink] [raw]
Subject: [PATCH] virtio_balloon: leak_balloon(): only tell host if we got pages deflated

The balloon_page_dequeue() function can return NULL. If it does for
the first page being freed, then leak_balloon() will create a
scatter list with len=0. Which in turn seems to generate an invalid
virtio request.

Signed-off-by: Luiz Capitulino <[email protected]>
---

PS: I didn't get this in practice. I found it by code review. On the other
hand, automatic-ballooning was able to put such invalid requests in
the virtqueue and QEMU would explode...

PPS: Very lightly tested

drivers/virtio/virtio_balloon.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index bd3ae32..71af7b5 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -191,7 +191,8 @@ static void leak_balloon(struct virtio_balloon *vb, size_t num)
* virtio_has_feature(vdev, VIRTIO_BALLOON_F_MUST_TELL_HOST);
* is true, we *have* to do it in this order
*/
- tell_host(vb, vb->deflate_vq);
+ if (vb->num_pfns != 0)
+ tell_host(vb, vb->deflate_vq);
mutex_unlock(&vb->balloon_lock);
release_pages_by_pfn(vb->pfns, vb->num_pfns);
}
--
1.8.1.4


2013-06-05 21:24:58

by Rafael Aquini

[permalink] [raw]
Subject: Re: [PATCH] virtio_balloon: leak_balloon(): only tell host if we got pages deflated

On Wed, Jun 05, 2013 at 05:10:31PM -0400, Luiz Capitulino wrote:
> The balloon_page_dequeue() function can return NULL. If it does for
> the first page being freed, then leak_balloon() will create a
> scatter list with len=0. Which in turn seems to generate an invalid
> virtio request.
>
> Signed-off-by: Luiz Capitulino <[email protected]>
> ---
>
> PS: I didn't get this in practice. I found it by code review. On the other
> hand, automatic-ballooning was able to put such invalid requests in
> the virtqueue and QEMU would explode...
>

Nice catch! The patch looks sane and replicates the check done at
fill_balloon(). I think we also could use this P.S. as a commentary
to let others aware of this scenario. Thanks Luiz!

Acked-by: Rafael Aquini <[email protected]>


> PPS: Very lightly tested
>
> drivers/virtio/virtio_balloon.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
> index bd3ae32..71af7b5 100644
> --- a/drivers/virtio/virtio_balloon.c
> +++ b/drivers/virtio/virtio_balloon.c
> @@ -191,7 +191,8 @@ static void leak_balloon(struct virtio_balloon *vb, size_t num)
> * virtio_has_feature(vdev, VIRTIO_BALLOON_F_MUST_TELL_HOST);
> * is true, we *have* to do it in this order
> */
> - tell_host(vb, vb->deflate_vq);
> + if (vb->num_pfns != 0)
> + tell_host(vb, vb->deflate_vq);
> mutex_unlock(&vb->balloon_lock);
> release_pages_by_pfn(vb->pfns, vb->num_pfns);
> }
> --
> 1.8.1.4
>

2013-06-05 23:08:49

by Luiz Capitulino

[permalink] [raw]
Subject: Re: [PATCH] virtio_balloon: leak_balloon(): only tell host if we got pages deflated

On Wed, 5 Jun 2013 18:24:49 -0300
Rafael Aquini <[email protected]> wrote:

> On Wed, Jun 05, 2013 at 05:10:31PM -0400, Luiz Capitulino wrote:
> > The balloon_page_dequeue() function can return NULL. If it does for
> > the first page being freed, then leak_balloon() will create a
> > scatter list with len=0. Which in turn seems to generate an invalid
> > virtio request.
> >
> > Signed-off-by: Luiz Capitulino <[email protected]>
> > ---
> >
> > PS: I didn't get this in practice. I found it by code review. On the other
> > hand, automatic-ballooning was able to put such invalid requests in
> > the virtqueue and QEMU would explode...
> >
>
> Nice catch! The patch looks sane and replicates the check done at
> fill_balloon(). I think we also could use this P.S. as a commentary
> to let others aware of this scenario. Thanks Luiz!

Want me to respin?

> Acked-by: Rafael Aquini <[email protected]>

Thanks for your review!

>
>
> > PPS: Very lightly tested
> >
> > drivers/virtio/virtio_balloon.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
> > index bd3ae32..71af7b5 100644
> > --- a/drivers/virtio/virtio_balloon.c
> > +++ b/drivers/virtio/virtio_balloon.c
> > @@ -191,7 +191,8 @@ static void leak_balloon(struct virtio_balloon *vb, size_t num)
> > * virtio_has_feature(vdev, VIRTIO_BALLOON_F_MUST_TELL_HOST);
> > * is true, we *have* to do it in this order
> > */
> > - tell_host(vb, vb->deflate_vq);
> > + if (vb->num_pfns != 0)
> > + tell_host(vb, vb->deflate_vq);
> > mutex_unlock(&vb->balloon_lock);
> > release_pages_by_pfn(vb->pfns, vb->num_pfns);
> > }
> > --
> > 1.8.1.4
> >
>

2013-06-05 23:29:41

by Rafael Aquini

[permalink] [raw]
Subject: Re: [PATCH] virtio_balloon: leak_balloon(): only tell host if we got pages deflated

On Wed, Jun 05, 2013 at 07:08:44PM -0400, Luiz Capitulino wrote:
> On Wed, 5 Jun 2013 18:24:49 -0300
> Rafael Aquini <[email protected]> wrote:
>
> > On Wed, Jun 05, 2013 at 05:10:31PM -0400, Luiz Capitulino wrote:
> > > The balloon_page_dequeue() function can return NULL. If it does for
> > > the first page being freed, then leak_balloon() will create a
> > > scatter list with len=0. Which in turn seems to generate an invalid
> > > virtio request.
> > >
> > > Signed-off-by: Luiz Capitulino <[email protected]>
> > > ---
> > >
> > > PS: I didn't get this in practice. I found it by code review. On the other
> > > hand, automatic-ballooning was able to put such invalid requests in
> > > the virtqueue and QEMU would explode...
> > >
> >
> > Nice catch! The patch looks sane and replicates the check done at
> > fill_balloon(). I think we also could use this P.S. as a commentary
> > to let others aware of this scenario. Thanks Luiz!
>
> Want me to respin?
>

That would be great, indeed. I guess the commentary could also go for the same
if case at fill_balloon(), assuming the tests are placed to prevent the same
scenario you described at changelog. You can stick my Ack on it, if reposting.

Cheers!
-- Rafael