qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] e1000: Avoid infinite loop in processing transmit descriptor
@ 2015-09-04 16:21 Stefan Hajnoczi
  2015-09-07  9:04 ` Thomas Huth
  2015-09-09  9:10 ` Stefan Hajnoczi
  0 siblings, 2 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2015-09-04 16:21 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S. Tsirkin, P J P, Jason Wang, qemu-stable, P J P,
	Stefan Hajnoczi, Huzaifa Sidhpurwala

From: P J P <pjp@fedoraproject.org>

While processing transmit descriptors, it could lead to an infinite
loop if 'bytes' was to become zero; Add a check to avoid it.

[The guest can force 'bytes' to 0 by setting the hdr_len and mss
descriptor fields to 0.
--Stefan]

Signed-off-by: P J P <pjp@fedoraproject.org>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 hw/net/e1000.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/net/e1000.c b/hw/net/e1000.c
index 5c6bcd0..09c9e9d 100644
--- a/hw/net/e1000.c
+++ b/hw/net/e1000.c
@@ -740,7 +740,8 @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp)
                 memmove(tp->data, tp->header, tp->hdr_len);
                 tp->size = tp->hdr_len;
             }
-        } while (split_size -= bytes);
+            split_size -= bytes;
+        } while (bytes && split_size);
     } else if (!tp->tse && tp->cptse) {
         // context descriptor TSE is not set, while data descriptor TSE is set
         DBGOUT(TXERR, "TCP segmentation error\n");
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] e1000: Avoid infinite loop in processing transmit descriptor
  2015-09-04 16:21 [Qemu-devel] [PATCH] e1000: Avoid infinite loop in processing transmit descriptor Stefan Hajnoczi
@ 2015-09-07  9:04 ` Thomas Huth
  2015-09-09  9:10   ` Stefan Hajnoczi
  2015-09-09  9:10 ` Stefan Hajnoczi
  1 sibling, 1 reply; 5+ messages in thread
From: Thomas Huth @ 2015-09-07  9:04 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel
  Cc: Michael S. Tsirkin, P J P, Jason Wang, qemu-stable, P J P,
	Huzaifa Sidhpurwala

On 04/09/15 18:21, Stefan Hajnoczi wrote:
> From: P J P <pjp@fedoraproject.org>
> 
> While processing transmit descriptors, it could lead to an infinite
> loop if 'bytes' was to become zero; Add a check to avoid it.
> 
> [The guest can force 'bytes' to 0 by setting the hdr_len and mss
> descriptor fields to 0.
> --Stefan]

I wonder whether we should log an LOG_GUEST_ERROR in that case since
this sounds like a problem in the guest ... ?

> diff --git a/hw/net/e1000.c b/hw/net/e1000.c
> index 5c6bcd0..09c9e9d 100644
> --- a/hw/net/e1000.c
> +++ b/hw/net/e1000.c
> @@ -740,7 +740,8 @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp)
>                  memmove(tp->data, tp->header, tp->hdr_len);
>                  tp->size = tp->hdr_len;
>              }
> -        } while (split_size -= bytes);
> +            split_size -= bytes;
> +        } while (bytes && split_size);
>      } else if (!tp->tse && tp->cptse) {
>          // context descriptor TSE is not set, while data descriptor TSE is set
>          DBGOUT(TXERR, "TCP segmentation error\n");

Looks sane ... (but IMHO code would be more readable though if it would
break out of the loop already earlier, as soon as it is clear that
bytes == 0, so that e.g. the pci_dma_read(..., 0) is not called at all).

Reviewed-by: Thomas Huth <thuth@redhat.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] e1000: Avoid infinite loop in processing transmit descriptor
  2015-09-07  9:04 ` Thomas Huth
@ 2015-09-09  9:10   ` Stefan Hajnoczi
  0 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2015-09-09  9:10 UTC (permalink / raw)
  To: Thomas Huth
  Cc: Michael S. Tsirkin, Huzaifa Sidhpurwala, P J P, Jason Wang,
	qemu-stable, qemu-devel, Stefan Hajnoczi, P J P

On Mon, Sep 07, 2015 at 11:04:47AM +0200, Thomas Huth wrote:
> On 04/09/15 18:21, Stefan Hajnoczi wrote:
> > From: P J P <pjp@fedoraproject.org>
> > 
> > While processing transmit descriptors, it could lead to an infinite
> > loop if 'bytes' was to become zero; Add a check to avoid it.
> > 
> > [The guest can force 'bytes' to 0 by setting the hdr_len and mss
> > descriptor fields to 0.
> > --Stefan]
> 
> I wonder whether we should log an LOG_GUEST_ERROR in that case since
> this sounds like a problem in the guest ... ?

e1000.c seems to use DBGOUT(TXERR, ...) but doesn't do any
rate-limiting, which can pose a problem if a malicious guest keeps
triggering a warning message to fill up the disk on the host :(.

> > diff --git a/hw/net/e1000.c b/hw/net/e1000.c
> > index 5c6bcd0..09c9e9d 100644
> > --- a/hw/net/e1000.c
> > +++ b/hw/net/e1000.c
> > @@ -740,7 +740,8 @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp)
> >                  memmove(tp->data, tp->header, tp->hdr_len);
> >                  tp->size = tp->hdr_len;
> >              }
> > -        } while (split_size -= bytes);
> > +            split_size -= bytes;
> > +        } while (bytes && split_size);
> >      } else if (!tp->tse && tp->cptse) {
> >          // context descriptor TSE is not set, while data descriptor TSE is set
> >          DBGOUT(TXERR, "TCP segmentation error\n");
> 
> Looks sane ... (but IMHO code would be more readable though if it would
> break out of the loop already earlier, as soon as it is clear that
> bytes == 0, so that e.g. the pci_dma_read(..., 0) is not called at all).

I agree.  P J P probably chose this approach because it is the smallest
change.  I'm happy enough as-is and you've posted your Reviewed-by too
so let's leave it.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] e1000: Avoid infinite loop in processing transmit descriptor
  2015-09-04 16:21 [Qemu-devel] [PATCH] e1000: Avoid infinite loop in processing transmit descriptor Stefan Hajnoczi
  2015-09-07  9:04 ` Thomas Huth
@ 2015-09-09  9:10 ` Stefan Hajnoczi
  2015-09-09  9:49   ` pjp
  1 sibling, 1 reply; 5+ messages in thread
From: Stefan Hajnoczi @ 2015-09-09  9:10 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: Michael S. Tsirkin, Huzaifa Sidhpurwala, P J P, Jason Wang,
	qemu-devel, P J P, qemu-stable

On Fri, Sep 04, 2015 at 05:21:06PM +0100, Stefan Hajnoczi wrote:
> From: P J P <pjp@fedoraproject.org>
> 
> While processing transmit descriptors, it could lead to an infinite
> loop if 'bytes' was to become zero; Add a check to avoid it.
> 
> [The guest can force 'bytes' to 0 by setting the hdr_len and mss
> descriptor fields to 0.
> --Stefan]
> 
> Signed-off-by: P J P <pjp@fedoraproject.org>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  hw/net/e1000.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Thanks, applied to my net tree:
https://github.com/stefanha/qemu/commits/net

Stefan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] e1000: Avoid infinite loop in processing transmit descriptor
  2015-09-09  9:10 ` Stefan Hajnoczi
@ 2015-09-09  9:49   ` pjp
  0 siblings, 0 replies; 5+ messages in thread
From: pjp @ 2015-09-09  9:49 UTC (permalink / raw)
  To: Stefan Hajnoczi, Stefan Hajnoczi
  Cc: Jason Wang, Michael S. Tsirkin, Huzaifa Sidhpurwala,
	qemu-devel@nongnu.org, qemu-stable@nongnu.org

  Hello Stefan,

> On Wednesday, 9 September 2015 2:40 PM, Stefan Hajnoczi wrote:
> P J P probably chose this approach because it is the smallest
> change.

  True.

> On Wednesday, 9 September 2015 2:40 PM, Stefan Hajnoczi wrote:
>>   hw/net/e1000.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>
> Thanks, applied to my net tree:
> https://github.com/stefanha/qemu/commits/net


  Thank you so much, I appreciate it.


Thank you.

---Regards
   -P J P
http://feedmug.com 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-09-09  9:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-04 16:21 [Qemu-devel] [PATCH] e1000: Avoid infinite loop in processing transmit descriptor Stefan Hajnoczi
2015-09-07  9:04 ` Thomas Huth
2015-09-09  9:10   ` Stefan Hajnoczi
2015-09-09  9:10 ` Stefan Hajnoczi
2015-09-09  9:49   ` pjp

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).