All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] cadence_gem: fix buffer overflow
@ 2016-01-14  9:43 Michael S. Tsirkin
  2016-01-14 10:03 ` [Qemu-devel] [Qemu-arm] " Peter Maydell
                   ` (3 more replies)
  0 siblings, 4 replies; 20+ messages in thread
From: Michael S. Tsirkin @ 2016-01-14  9:43 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Crosthwaite, Jason Wang, Prasad Pandit, qemu-arm,
	=?UTF-8?q?=E5=88=98=E4=BB=A4?=,
	Alistair Francis

gem_receive copies a packet received from network into an rxbuf[2048]
array on stack, with size limited by descriptor length set by guest.  If
guest is malicious and specifies a descriptor length that is too large,
and should packet size exceed array size, this results in a buffer
overflow.

Reported-by: 刘令 <liuling-it@360.cn>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/net/cadence_gem.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
index 3639fc1..15a0786 100644
--- a/hw/net/cadence_gem.c
+++ b/hw/net/cadence_gem.c
@@ -862,6 +862,14 @@ static void gem_transmit(CadenceGEMState *s)
             break;
         }
 
+        if (tx_desc_get_length(desc) > sizeof(tx_packet) - (p - tx_packet)) {
+            DB_PRINT("TX descriptor @ 0x%x too large: size 0x%x space 0x%x\n",
+                     (unsigned)packet_desc_addr,
+                     (unsigned)tx_desc_get_length(desc),
+                     sizeof(tx_packet) - (p - tx_packet));
+            break;
+        }
+
         /* Gather this fragment of the packet from "dma memory" to our contig.
          * buffer.
          */
-- 
MST

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

* Re: [Qemu-devel] [Qemu-arm] [PATCH] cadence_gem: fix buffer overflow
  2016-01-14  9:43 [Qemu-devel] [PATCH] cadence_gem: fix buffer overflow Michael S. Tsirkin
@ 2016-01-14 10:03 ` Peter Maydell
  2016-01-14 10:11   ` Michael S. Tsirkin
  2016-01-15  6:19   ` Peter Crosthwaite
  2016-01-14 10:23 ` [Qemu-devel] " P J P
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 20+ messages in thread
From: Peter Maydell @ 2016-01-14 10:03 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Jason Wang, QEMU Developers, Alistair Francis, Prasad Pandit,
	qemu-arm, 刘令

On 14 January 2016 at 09:43, Michael S. Tsirkin <mst@redhat.com> wrote:
> gem_receive copies a packet received from network into an rxbuf[2048]
> array on stack, with size limited by descriptor length set by guest.  If
> guest is malicious and specifies a descriptor length that is too large,
> and should packet size exceed array size, this results in a buffer
> overflow.
>
> Reported-by: 刘令 <liuling-it@360.cn>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  hw/net/cadence_gem.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
> index 3639fc1..15a0786 100644
> --- a/hw/net/cadence_gem.c
> +++ b/hw/net/cadence_gem.c
> @@ -862,6 +862,14 @@ static void gem_transmit(CadenceGEMState *s)
>              break;
>          }
>
> +        if (tx_desc_get_length(desc) > sizeof(tx_packet) - (p - tx_packet)) {
> +            DB_PRINT("TX descriptor @ 0x%x too large: size 0x%x space 0x%x\n",
> +                     (unsigned)packet_desc_addr,
> +                     (unsigned)tx_desc_get_length(desc),
> +                     sizeof(tx_packet) - (p - tx_packet));
> +            break;
> +        }

Is this what the real hardware does in this situation?
Should we log this as a guest error?

> +
>          /* Gather this fragment of the packet from "dma memory" to our contig.
>           * buffer.
>           */
> --
> MST
>

thanks
-- PMM

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

* Re: [Qemu-devel] [Qemu-arm] [PATCH] cadence_gem: fix buffer overflow
  2016-01-14 10:03 ` [Qemu-devel] [Qemu-arm] " Peter Maydell
@ 2016-01-14 10:11   ` Michael S. Tsirkin
  2016-01-15  6:19   ` Peter Crosthwaite
  1 sibling, 0 replies; 20+ messages in thread
From: Michael S. Tsirkin @ 2016-01-14 10:11 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Jason Wang, QEMU Developers, Alistair Francis, Prasad Pandit,
	qemu-arm, 刘令

On Thu, Jan 14, 2016 at 10:03:15AM +0000, Peter Maydell wrote:
> On 14 January 2016 at 09:43, Michael S. Tsirkin <mst@redhat.com> wrote:
> > gem_receive copies a packet received from network into an rxbuf[2048]
> > array on stack, with size limited by descriptor length set by guest.  If
> > guest is malicious and specifies a descriptor length that is too large,
> > and should packet size exceed array size, this results in a buffer
> > overflow.
> >
> > Reported-by: 刘令 <liuling-it@360.cn>
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >  hw/net/cadence_gem.c | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> >
> > diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
> > index 3639fc1..15a0786 100644
> > --- a/hw/net/cadence_gem.c
> > +++ b/hw/net/cadence_gem.c
> > @@ -862,6 +862,14 @@ static void gem_transmit(CadenceGEMState *s)
> >              break;
> >          }
> >
> > +        if (tx_desc_get_length(desc) > sizeof(tx_packet) - (p - tx_packet)) {
> > +            DB_PRINT("TX descriptor @ 0x%x too large: size 0x%x space 0x%x\n",
> > +                     (unsigned)packet_desc_addr,
> > +                     (unsigned)tx_desc_get_length(desc),
> > +                     sizeof(tx_packet) - (p - tx_packet));
> > +            break;
> > +        }
> 
> Is this what the real hardware does in this situation?
> Should we log this as a guest error?

I don't really know.  This is just consistent with what this device does
for other descriptor errors.

> > +
> >          /* Gather this fragment of the packet from "dma memory" to our contig.
> >           * buffer.
> >           */
> > --
> > MST
> >
> 
> thanks
> -- PMM

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

* Re: [Qemu-devel] [PATCH] cadence_gem: fix buffer overflow
  2016-01-14  9:43 [Qemu-devel] [PATCH] cadence_gem: fix buffer overflow Michael S. Tsirkin
  2016-01-14 10:03 ` [Qemu-devel] [Qemu-arm] " Peter Maydell
@ 2016-01-14 10:23 ` P J P
  2016-01-15  3:16 ` Jason Wang
  2016-01-18  6:50 ` Jason Wang
  3 siblings, 0 replies; 20+ messages in thread
From: P J P @ 2016-01-14 10:23 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Peter Crosthwaite, Jason Wang, qemu-devel, Alistair Francis,
	qemu-arm, 刘令

+-- On Thu, 14 Jan 2016, Michael S. Tsirkin wrote --+
| gem_receive copies a packet received from network into an rxbuf[2048]
| array on stack, with size limited by descriptor length set by guest.  If
| guest is malicious and specifies a descriptor length that is too large,
| and should packet size exceed array size, this results in a buffer
| overflow.
| 
| diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
| index 3639fc1..15a0786 100644
| --- a/hw/net/cadence_gem.c
| +++ b/hw/net/cadence_gem.c
| @@ -862,6 +862,14 @@ static void gem_transmit(CadenceGEMState *s)
|              break;
|          }
|  
| +        if (tx_desc_get_length(desc) > sizeof(tx_packet) - (p - tx_packet)) {
| +            DB_PRINT("TX descriptor @ 0x%x too large: size 0x%x space 0x%x\n",
| +                     (unsigned)packet_desc_addr,
| +                     (unsigned)tx_desc_get_length(desc),
| +                     sizeof(tx_packet) - (p - tx_packet));
| +            break;
| +        }
| +

  Commit message says gem_receive, but the patch fixes gem_transmit() routine.

--
 - P J P
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F

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

* Re: [Qemu-devel] [PATCH] cadence_gem: fix buffer overflow
  2016-01-14  9:43 [Qemu-devel] [PATCH] cadence_gem: fix buffer overflow Michael S. Tsirkin
  2016-01-14 10:03 ` [Qemu-devel] [Qemu-arm] " Peter Maydell
  2016-01-14 10:23 ` [Qemu-devel] " P J P
@ 2016-01-15  3:16 ` Jason Wang
  2016-01-15  5:39   ` P J P
  2016-01-18  6:50 ` Jason Wang
  3 siblings, 1 reply; 20+ messages in thread
From: Jason Wang @ 2016-01-15  3:16 UTC (permalink / raw)
  To: Michael S. Tsirkin, qemu-devel
  Cc: Alistair Francis, Prasad Pandit, 刘令,
	qemu-arm, Peter Crosthwaite



On 01/14/2016 05:43 PM, Michael S. Tsirkin wrote:
> gem_receive copies a packet received from network into an rxbuf[2048]
> array on stack, with size limited by descriptor length set by guest.  If
> guest is malicious and specifies a descriptor length that is too large,
> and should packet size exceed array size, this results in a buffer
> overflow.
>
> Reported-by: 刘令 <liuling-it@360.cn>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  hw/net/cadence_gem.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
> index 3639fc1..15a0786 100644
> --- a/hw/net/cadence_gem.c
> +++ b/hw/net/cadence_gem.c
> @@ -862,6 +862,14 @@ static void gem_transmit(CadenceGEMState *s)
>              break;
>          }
>  
> +        if (tx_desc_get_length(desc) > sizeof(tx_packet) - (p - tx_packet)) {
> +            DB_PRINT("TX descriptor @ 0x%x too large: size 0x%x space 0x%x\n",
> +                     (unsigned)packet_desc_addr,
> +                     (unsigned)tx_desc_get_length(desc),
> +                     sizeof(tx_packet) - (p - tx_packet));
> +            break;
> +        }
> +
>          /* Gather this fragment of the packet from "dma memory" to our contig.
>           * buffer.
>           */

Looks like we need similar issue in gen_receive(), need to fix that?

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

* Re: [Qemu-devel] [PATCH] cadence_gem: fix buffer overflow
  2016-01-15  3:16 ` Jason Wang
@ 2016-01-15  5:39   ` P J P
  0 siblings, 0 replies; 20+ messages in thread
From: P J P @ 2016-01-15  5:39 UTC (permalink / raw)
  To: Jason Wang
  Cc: Peter Crosthwaite, Michael S. Tsirkin, qemu-devel,
	Alistair Francis, qemu-arm, 刘令

+-- On Fri, 15 Jan 2016, Jason Wang wrote --+
| Looks like we need similar issue in gen_receive(), need to fix that?

Yes, I'm preparing a patch.
--
Prasad J Pandit / Red Hat Product Security Team
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F

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

* Re: [Qemu-devel] [Qemu-arm] [PATCH] cadence_gem: fix buffer overflow
  2016-01-14 10:03 ` [Qemu-devel] [Qemu-arm] " Peter Maydell
  2016-01-14 10:11   ` Michael S. Tsirkin
@ 2016-01-15  6:19   ` Peter Crosthwaite
  2016-01-15  8:06     ` P J P
  2016-01-18  3:14     ` Jason Wang
  1 sibling, 2 replies; 20+ messages in thread
From: Peter Crosthwaite @ 2016-01-15  6:19 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Michael S. Tsirkin, Jason Wang, QEMU Developers, Prasad Pandit,
	qemu-arm, 刘令,
	Alistair Francis

On Thu, Jan 14, 2016 at 2:03 AM, Peter Maydell <peter.maydell@linaro.org> wrote:
> On 14 January 2016 at 09:43, Michael S. Tsirkin <mst@redhat.com> wrote:
>> gem_receive copies a packet received from network into an rxbuf[2048]
>> array on stack, with size limited by descriptor length set by guest.  If
>> guest is malicious and specifies a descriptor length that is too large,
>> and should packet size exceed array size, this results in a buffer
>> overflow.
>>
>> Reported-by: 刘令 <liuling-it@360.cn>
>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>> ---
>>  hw/net/cadence_gem.c | 8 ++++++++
>>  1 file changed, 8 insertions(+)
>>
>> diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
>> index 3639fc1..15a0786 100644
>> --- a/hw/net/cadence_gem.c
>> +++ b/hw/net/cadence_gem.c
>> @@ -862,6 +862,14 @@ static void gem_transmit(CadenceGEMState *s)
>>              break;
>>          }
>>
>> +        if (tx_desc_get_length(desc) > sizeof(tx_packet) - (p - tx_packet)) {
>> +            DB_PRINT("TX descriptor @ 0x%x too large: size 0x%x space 0x%x\n",
>> +                     (unsigned)packet_desc_addr,
>> +                     (unsigned)tx_desc_get_length(desc),
>> +                     sizeof(tx_packet) - (p - tx_packet));
>> +            break;
>> +        }
>
> Is this what the real hardware does in this situation?
> Should we log this as a guest error?
>

I'm not sure it is a guest error. I think its just a shortcut in the
original implementation. I guess QEMU needs the whole packet before
handing off to the net layer and the assumption is that the packet is
always within 2048. I think the hardware is just going to put the data
on the wire as it goes. The easiest solution is to realloc the buffer
as it goes with the increasing sizes. Otherwise you could refactor the
code to be two pass over the descriptor ring section (containing the
packet). If we want to fix the buffer overflow more urgently, the
correct error would be an assert().

Regards,
Peter

>> +
>>          /* Gather this fragment of the packet from "dma memory" to our contig.
>>           * buffer.
>>           */
>> --
>> MST
>>
>
> thanks
> -- PMM
>

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

* Re: [Qemu-devel] [Qemu-arm] [PATCH] cadence_gem: fix buffer overflow
  2016-01-15  6:19   ` Peter Crosthwaite
@ 2016-01-15  8:06     ` P J P
  2016-01-16  0:20       ` Alistair Francis
  2016-01-18  3:14     ` Jason Wang
  1 sibling, 1 reply; 20+ messages in thread
From: P J P @ 2016-01-15  8:06 UTC (permalink / raw)
  To: Peter Crosthwaite
  Cc: Peter Maydell, Michael S. Tsirkin, Jason Wang, QEMU Developers,
	Alistair Francis, qemu-arm, 刘令

+-- On Thu, 14 Jan 2016, Peter Crosthwaite wrote --+
| I guess QEMU needs the whole packet before handing off to the net layer and 
| the assumption is that the packet is always within 2048. The easiest 
| solution is to realloc the buffer as it goes with the increasing sizes.

  Yes, I was considering increasing buffer size with view of the jumbo 
packets. In gem_transmit(), 'tx_desc_get_length' returns length masked by 
DESC_1_LENGTH(=0x1FFF=8191) bytes. But thought dynamic allocation might lead 
to excessive buffer allocation, not sure how constrained the Xilinx platform 
is for memory.

--
 - P J P
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F

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

* Re: [Qemu-devel] [Qemu-arm] [PATCH] cadence_gem: fix buffer overflow
  2016-01-15  8:06     ` P J P
@ 2016-01-16  0:20       ` Alistair Francis
  2016-01-16  5:23         ` P J P
  0 siblings, 1 reply; 20+ messages in thread
From: Alistair Francis @ 2016-01-16  0:20 UTC (permalink / raw)
  To: P J P
  Cc: Peter Maydell, Michael S. Tsirkin, Jason Wang, QEMU Developers,
	Alistair Francis, Peter Crosthwaite, qemu-arm, 刘令

On Fri, Jan 15, 2016 at 12:06 AM, P J P <ppandit@redhat.com> wrote:
> +-- On Thu, 14 Jan 2016, Peter Crosthwaite wrote --+
> | I guess QEMU needs the whole packet before handing off to the net layer and
> | the assumption is that the packet is always within 2048. The easiest
> | solution is to realloc the buffer as it goes with the increasing sizes.
>
>   Yes, I was considering increasing buffer size with view of the jumbo
> packets. In gem_transmit(), 'tx_desc_get_length' returns length masked by
> DESC_1_LENGTH(=0x1FFF=8191) bytes. But thought dynamic allocation might lead
> to excessive buffer allocation, not sure how constrained the Xilinx platform
> is for memory.

Won't the allocation/reallocation happen on the host?

Thanks,

Alistair

>
> --
>  - P J P
> 47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F
>

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

* Re: [Qemu-devel] [Qemu-arm] [PATCH] cadence_gem: fix buffer overflow
  2016-01-16  0:20       ` Alistair Francis
@ 2016-01-16  5:23         ` P J P
  0 siblings, 0 replies; 20+ messages in thread
From: P J P @ 2016-01-16  5:23 UTC (permalink / raw)
  To: Alistair Francis
  Cc: Peter Maydell, Michael S. Tsirkin, Jason Wang, QEMU Developers,
	刘令,
	Peter Crosthwaite, qemu-arm

+-- On Fri, 15 Jan 2016, Alistair Francis wrote --+
| Won't the allocation/reallocation happen on the host?

  Ah yes, don't know what I was thinking.

--
 - P J P
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F

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

* Re: [Qemu-devel] [Qemu-arm] [PATCH] cadence_gem: fix buffer overflow
  2016-01-15  6:19   ` Peter Crosthwaite
  2016-01-15  8:06     ` P J P
@ 2016-01-18  3:14     ` Jason Wang
  1 sibling, 0 replies; 20+ messages in thread
From: Jason Wang @ 2016-01-18  3:14 UTC (permalink / raw)
  To: Peter Crosthwaite, Peter Maydell
  Cc: Michael S. Tsirkin, QEMU Developers, Prasad Pandit, qemu-arm,
	刘令,
	Alistair Francis



On 01/15/2016 02:19 PM, Peter Crosthwaite wrote:
> On Thu, Jan 14, 2016 at 2:03 AM, Peter Maydell <peter.maydell@linaro.org> wrote:
>> On 14 January 2016 at 09:43, Michael S. Tsirkin <mst@redhat.com> wrote:
>>> gem_receive copies a packet received from network into an rxbuf[2048]
>>> array on stack, with size limited by descriptor length set by guest.  If
>>> guest is malicious and specifies a descriptor length that is too large,
>>> and should packet size exceed array size, this results in a buffer
>>> overflow.
>>>
>>> Reported-by: 刘令 <liuling-it@360.cn>
>>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>>> ---
>>>  hw/net/cadence_gem.c | 8 ++++++++
>>>  1 file changed, 8 insertions(+)
>>>
>>> diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
>>> index 3639fc1..15a0786 100644
>>> --- a/hw/net/cadence_gem.c
>>> +++ b/hw/net/cadence_gem.c
>>> @@ -862,6 +862,14 @@ static void gem_transmit(CadenceGEMState *s)
>>>              break;
>>>          }
>>>
>>> +        if (tx_desc_get_length(desc) > sizeof(tx_packet) - (p - tx_packet)) {
>>> +            DB_PRINT("TX descriptor @ 0x%x too large: size 0x%x space 0x%x\n",
>>> +                     (unsigned)packet_desc_addr,
>>> +                     (unsigned)tx_desc_get_length(desc),
>>> +                     sizeof(tx_packet) - (p - tx_packet));
>>> +            break;
>>> +        }
>> Is this what the real hardware does in this situation?
>> Should we log this as a guest error?
>>
> I'm not sure it is a guest error. I think its just a shortcut in the
> original implementation. I guess QEMU needs the whole packet before
> handing off to the net layer and the assumption is that the packet is
> always within 2048. I think the hardware is just going to put the data
> on the wire as it goes.

If we are not sure this is what real hardware did, dropping looks more
safe than sending the truncated packets on the wire.

>  The easiest solution is to realloc the buffer
> as it goes with the increasing sizes.

This could allow possible DOS from guest (see
cde31a0e3dc0e4ac83e454d6096350cec584adf1).

> Otherwise you could refactor the
> code to be two pass over the descriptor ring section (containing the
> packet). If we want to fix the buffer overflow more urgently, the
> correct error would be an assert().
>
> Regards,
> Peter

Let's avoid putting guest trigger-able assert() here. The patch looks
good for fixing the issue. Refactoring could be done on top.

Thanks

>
>>> +
>>>          /* Gather this fragment of the packet from "dma memory" to our contig.
>>>           * buffer.
>>>           */
>>> --
>>> MST
>>>
>> thanks
>> -- PMM
>>

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

* Re: [Qemu-devel] [PATCH] cadence_gem: fix buffer overflow
  2016-01-14  9:43 [Qemu-devel] [PATCH] cadence_gem: fix buffer overflow Michael S. Tsirkin
                   ` (2 preceding siblings ...)
  2016-01-15  3:16 ` Jason Wang
@ 2016-01-18  6:50 ` Jason Wang
  2016-01-18  7:04   ` Peter Crosthwaite
  3 siblings, 1 reply; 20+ messages in thread
From: Jason Wang @ 2016-01-18  6:50 UTC (permalink / raw)
  To: Michael S. Tsirkin, qemu-devel
  Cc: Alistair Francis, Prasad Pandit, 刘令,
	qemu-arm, Peter Crosthwaite



On 01/14/2016 05:43 PM, Michael S. Tsirkin wrote:
> gem_receive copies a packet received from network into an rxbuf[2048]
> array on stack, with size limited by descriptor length set by guest.  If
> guest is malicious and specifies a descriptor length that is too large,
> and should packet size exceed array size, this results in a buffer
> overflow.
>
> Reported-by: 刘令 <liuling-it@360.cn>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  hw/net/cadence_gem.c | 8 ++++++++
>  1 file changed, 8 insertions(+)

Apply to my -net with tweak on commit log (changing receive to transmit
as noticed).

Thanks

>
> diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
> index 3639fc1..15a0786 100644
> --- a/hw/net/cadence_gem.c
> +++ b/hw/net/cadence_gem.c
> @@ -862,6 +862,14 @@ static void gem_transmit(CadenceGEMState *s)
>              break;
>          }
>  
> +        if (tx_desc_get_length(desc) > sizeof(tx_packet) - (p - tx_packet)) {
> +            DB_PRINT("TX descriptor @ 0x%x too large: size 0x%x space 0x%x\n",
> +                     (unsigned)packet_desc_addr,
> +                     (unsigned)tx_desc_get_length(desc),
> +                     sizeof(tx_packet) - (p - tx_packet));
> +            break;
> +        }
> +
>          /* Gather this fragment of the packet from "dma memory" to our contig.
>           * buffer.
>           */

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

* Re: [Qemu-devel] [PATCH] cadence_gem: fix buffer overflow
  2016-01-18  6:50 ` Jason Wang
@ 2016-01-18  7:04   ` Peter Crosthwaite
  2016-01-18  8:12     ` Jason Wang
  0 siblings, 1 reply; 20+ messages in thread
From: Peter Crosthwaite @ 2016-01-18  7:04 UTC (permalink / raw)
  To: Jason Wang
  Cc: Peter Crosthwaite, Alistair Francis, Michael S. Tsirkin,
	qemu-devel@nongnu.org Developers, Prasad Pandit, qemu-arm,
	刘令

On Sun, Jan 17, 2016 at 10:50 PM, Jason Wang <jasowang@redhat.com> wrote:
>
>
> On 01/14/2016 05:43 PM, Michael S. Tsirkin wrote:
>> gem_receive copies a packet received from network into an rxbuf[2048]
>> array on stack, with size limited by descriptor length set by guest.  If
>> guest is malicious and specifies a descriptor length that is too large,
>> and should packet size exceed array size, this results in a buffer
>> overflow.
>>
>> Reported-by: 刘令 <liuling-it@360.cn>
>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>> ---
>>  hw/net/cadence_gem.c | 8 ++++++++
>>  1 file changed, 8 insertions(+)
>
> Apply to my -net with tweak on commit log (changing receive to transmit
> as noticed).
>

As this is actually an unimplemented feature you should change the
message to a LOG_UNIMP rather than a debug printf.

Regards,
Peter

> Thanks
>
>>
>> diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
>> index 3639fc1..15a0786 100644
>> --- a/hw/net/cadence_gem.c
>> +++ b/hw/net/cadence_gem.c
>> @@ -862,6 +862,14 @@ static void gem_transmit(CadenceGEMState *s)
>>              break;
>>          }
>>
>> +        if (tx_desc_get_length(desc) > sizeof(tx_packet) - (p - tx_packet)) {
>> +            DB_PRINT("TX descriptor @ 0x%x too large: size 0x%x space 0x%x\n",
>> +                     (unsigned)packet_desc_addr,
>> +                     (unsigned)tx_desc_get_length(desc),
>> +                     sizeof(tx_packet) - (p - tx_packet));
>> +            break;
>> +        }
>> +
>>          /* Gather this fragment of the packet from "dma memory" to our contig.
>>           * buffer.
>>           */
>

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

* Re: [Qemu-devel] [PATCH] cadence_gem: fix buffer overflow
  2016-01-18  7:04   ` Peter Crosthwaite
@ 2016-01-18  8:12     ` Jason Wang
  2016-01-18  9:08       ` Peter Crosthwaite
  0 siblings, 1 reply; 20+ messages in thread
From: Jason Wang @ 2016-01-18  8:12 UTC (permalink / raw)
  To: Peter Crosthwaite
  Cc: Peter Crosthwaite, Alistair Francis, Michael S. Tsirkin,
	qemu-devel@nongnu.org Developers, Prasad Pandit, qemu-arm,
	刘令



On 01/18/2016 03:04 PM, Peter Crosthwaite wrote:
> On Sun, Jan 17, 2016 at 10:50 PM, Jason Wang <jasowang@redhat.com> wrote:
>>
>> On 01/14/2016 05:43 PM, Michael S. Tsirkin wrote:
>>> gem_receive copies a packet received from network into an rxbuf[2048]
>>> array on stack, with size limited by descriptor length set by guest.  If
>>> guest is malicious and specifies a descriptor length that is too large,
>>> and should packet size exceed array size, this results in a buffer
>>> overflow.
>>>
>>> Reported-by: 刘令 <liuling-it@360.cn>
>>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>>> ---
>>>  hw/net/cadence_gem.c | 8 ++++++++
>>>  1 file changed, 8 insertions(+)
>> Apply to my -net with tweak on commit log (changing receive to transmit
>> as noticed).
>>
> As this is actually an unimplemented feature you should change the
> message to a LOG_UNIMP rather than a debug printf.
>
> Regards,
> Peter

Thanks for the reminding. But we need know the whether real device could
send packet whose length is greater than 2048. Do you know the link to
the manual? (Haven't fond it in cadence page.) A hint is the linux
driver (drivers/net/ethernet/cadence/macb.c), use 1500 as its MTU.

>
>> Thanks
>>
>>> diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
>>> index 3639fc1..15a0786 100644
>>> --- a/hw/net/cadence_gem.c
>>> +++ b/hw/net/cadence_gem.c
>>> @@ -862,6 +862,14 @@ static void gem_transmit(CadenceGEMState *s)
>>>              break;
>>>          }
>>>
>>> +        if (tx_desc_get_length(desc) > sizeof(tx_packet) - (p - tx_packet)) {
>>> +            DB_PRINT("TX descriptor @ 0x%x too large: size 0x%x space 0x%x\n",
>>> +                     (unsigned)packet_desc_addr,
>>> +                     (unsigned)tx_desc_get_length(desc),
>>> +                     sizeof(tx_packet) - (p - tx_packet));
>>> +            break;
>>> +        }
>>> +
>>>          /* Gather this fragment of the packet from "dma memory" to our contig.
>>>           * buffer.
>>>           */

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

* Re: [Qemu-devel] [PATCH] cadence_gem: fix buffer overflow
  2016-01-18  8:12     ` Jason Wang
@ 2016-01-18  9:08       ` Peter Crosthwaite
  2016-01-18  9:57         ` Jason Wang
  0 siblings, 1 reply; 20+ messages in thread
From: Peter Crosthwaite @ 2016-01-18  9:08 UTC (permalink / raw)
  To: Jason Wang
  Cc: Peter Crosthwaite, Alistair Francis, Michael S. Tsirkin,
	qemu-devel@nongnu.org Developers, Prasad Pandit, qemu-arm,
	刘令

On Mon, Jan 18, 2016 at 12:12 AM, Jason Wang <jasowang@redhat.com> wrote:
>
>
> On 01/18/2016 03:04 PM, Peter Crosthwaite wrote:
>> On Sun, Jan 17, 2016 at 10:50 PM, Jason Wang <jasowang@redhat.com> wrote:
>>>
>>> On 01/14/2016 05:43 PM, Michael S. Tsirkin wrote:
>>>> gem_receive copies a packet received from network into an rxbuf[2048]
>>>> array on stack, with size limited by descriptor length set by guest.  If
>>>> guest is malicious and specifies a descriptor length that is too large,
>>>> and should packet size exceed array size, this results in a buffer
>>>> overflow.
>>>>
>>>> Reported-by: 刘令 <liuling-it@360.cn>
>>>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>>>> ---
>>>>  hw/net/cadence_gem.c | 8 ++++++++
>>>>  1 file changed, 8 insertions(+)
>>> Apply to my -net with tweak on commit log (changing receive to transmit
>>> as noticed).
>>>
>> As this is actually an unimplemented feature you should change the
>> message to a LOG_UNIMP rather than a debug printf.
>>
>> Regards,
>> Peter
>
> Thanks for the reminding. But we need know the whether real device could
> send packet whose length is greater than 2048. Do you know the link to
> the manual? (Haven't fond it in cadence page.) A hint is the linux

Xilinx UG585 has details:

http://www.xilinx.com/support/documentation/user_guides/ug585-Zynq-7000-TRM.pdf

Regards,
Peter

> driver (drivers/net/ethernet/cadence/macb.c), use 1500 as its MTU.
>
>>
>>> Thanks
>>>
>>>> diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
>>>> index 3639fc1..15a0786 100644
>>>> --- a/hw/net/cadence_gem.c
>>>> +++ b/hw/net/cadence_gem.c
>>>> @@ -862,6 +862,14 @@ static void gem_transmit(CadenceGEMState *s)
>>>>              break;
>>>>          }
>>>>
>>>> +        if (tx_desc_get_length(desc) > sizeof(tx_packet) - (p - tx_packet)) {
>>>> +            DB_PRINT("TX descriptor @ 0x%x too large: size 0x%x space 0x%x\n",
>>>> +                     (unsigned)packet_desc_addr,
>>>> +                     (unsigned)tx_desc_get_length(desc),
>>>> +                     sizeof(tx_packet) - (p - tx_packet));
>>>> +            break;
>>>> +        }
>>>> +
>>>>          /* Gather this fragment of the packet from "dma memory" to our contig.
>>>>           * buffer.
>>>>           */
>

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

* Re: [Qemu-devel] [PATCH] cadence_gem: fix buffer overflow
  2016-01-18  9:08       ` Peter Crosthwaite
@ 2016-01-18  9:57         ` Jason Wang
  2016-01-18 10:06           ` [Qemu-devel] [Qemu-arm] " Peter Maydell
  0 siblings, 1 reply; 20+ messages in thread
From: Jason Wang @ 2016-01-18  9:57 UTC (permalink / raw)
  To: Peter Crosthwaite
  Cc: Peter Crosthwaite, Alistair Francis, Michael S. Tsirkin,
	qemu-devel@nongnu.org Developers, Prasad Pandit, qemu-arm,
	刘令



On 01/18/2016 05:08 PM, Peter Crosthwaite wrote:
> On Mon, Jan 18, 2016 at 12:12 AM, Jason Wang <jasowang@redhat.com> wrote:
>>
>> On 01/18/2016 03:04 PM, Peter Crosthwaite wrote:
>>> On Sun, Jan 17, 2016 at 10:50 PM, Jason Wang <jasowang@redhat.com> wrote:
>>>> On 01/14/2016 05:43 PM, Michael S. Tsirkin wrote:
>>>>> gem_receive copies a packet received from network into an rxbuf[2048]
>>>>> array on stack, with size limited by descriptor length set by guest.  If
>>>>> guest is malicious and specifies a descriptor length that is too large,
>>>>> and should packet size exceed array size, this results in a buffer
>>>>> overflow.
>>>>>
>>>>> Reported-by: 刘令 <liuling-it@360.cn>
>>>>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>>>>> ---
>>>>>  hw/net/cadence_gem.c | 8 ++++++++
>>>>>  1 file changed, 8 insertions(+)
>>>> Apply to my -net with tweak on commit log (changing receive to transmit
>>>> as noticed).
>>>>
>>> As this is actually an unimplemented feature you should change the
>>> message to a LOG_UNIMP rather than a debug printf.
>>>
>>> Regards,
>>> Peter
>> Thanks for the reminding. But we need know the whether real device could
>> send packet whose length is greater than 2048. Do you know the link to
>> the manual? (Haven't fond it in cadence page.) A hint is the linux
> Xilinx UG585 has details:
>
> http://www.xilinx.com/support/documentation/user_guides/ug585-Zynq-7000-TRM.pdf
>
> Regards,
> Peter
>
>

Thanks for the pointer.

In section 16.1.5, it said

"Jumbo frames are not supported."

So it was in fact not an unimplemented feature?

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

* Re: [Qemu-devel] [Qemu-arm] [PATCH] cadence_gem: fix buffer overflow
  2016-01-18  9:57         ` Jason Wang
@ 2016-01-18 10:06           ` Peter Maydell
  2016-01-18 16:54             ` Alistair Francis
  2016-01-19  2:48             ` Jason Wang
  0 siblings, 2 replies; 20+ messages in thread
From: Peter Maydell @ 2016-01-18 10:06 UTC (permalink / raw)
  To: Jason Wang
  Cc: Michael S. Tsirkin, qemu-devel@nongnu.org Developers,
	Prasad Pandit, Peter Crosthwaite, qemu-arm, 刘令,
	Alistair Francis

On 18 January 2016 at 09:57, Jason Wang <jasowang@redhat.com> wrote:
> Thanks for the pointer.
>
> In section 16.1.5, it said
>
> "Jumbo frames are not supported."
>
> So it was in fact not an unimplemented feature?

I have a vague feeling from the last time I looked at something like
this that what often happens is the hardware happily goes on dumping
data out on the wire but this is a violation of the ethernet protocol,
ie a guest error. But I'm no ethernet expert...

thanks
-- PMM

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

* Re: [Qemu-devel] [Qemu-arm] [PATCH] cadence_gem: fix buffer overflow
  2016-01-18 10:06           ` [Qemu-devel] [Qemu-arm] " Peter Maydell
@ 2016-01-18 16:54             ` Alistair Francis
  2016-01-19  2:48               ` Jason Wang
  2016-01-19  2:48             ` Jason Wang
  1 sibling, 1 reply; 20+ messages in thread
From: Alistair Francis @ 2016-01-18 16:54 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Michael S. Tsirkin, Jason Wang, Alistair Francis,
	qemu-devel@nongnu.org Developers, Prasad Pandit,
	Peter Crosthwaite, qemu-arm, 刘令

On Mon, Jan 18, 2016 at 2:06 AM, Peter Maydell <peter.maydell@linaro.org> wrote:
> On 18 January 2016 at 09:57, Jason Wang <jasowang@redhat.com> wrote:
>> Thanks for the pointer.
>>
>> In section 16.1.5, it said
>>
>> "Jumbo frames are not supported."
>>
>> So it was in fact not an unimplemented feature?

I'd say this should be a guest error then. Unless anyone who knows
Ethernet well thinks otherwise?

Thanks,

Alistair

>
> I have a vague feeling from the last time I looked at something like
> this that what often happens is the hardware happily goes on dumping
> data out on the wire but this is a violation of the ethernet protocol,
> ie a guest error. But I'm no ethernet expert...
>
> thanks
> -- PMM
>

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

* Re: [Qemu-devel] [Qemu-arm] [PATCH] cadence_gem: fix buffer overflow
  2016-01-18 10:06           ` [Qemu-devel] [Qemu-arm] " Peter Maydell
  2016-01-18 16:54             ` Alistair Francis
@ 2016-01-19  2:48             ` Jason Wang
  1 sibling, 0 replies; 20+ messages in thread
From: Jason Wang @ 2016-01-19  2:48 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Michael S. Tsirkin, Alistair Francis,
	qemu-devel@nongnu.org Developers, Prasad Pandit,
	Peter Crosthwaite, qemu-arm, 刘令



On 01/18/2016 06:06 PM, Peter Maydell wrote:
> On 18 January 2016 at 09:57, Jason Wang <jasowang@redhat.com> wrote:
>> Thanks for the pointer.
>>
>> In section 16.1.5, it said
>>
>> "Jumbo frames are not supported."
>>
>> So it was in fact not an unimplemented feature?
> I have a vague feeling from the last time I looked at something like
> this that what often happens is the hardware happily goes on dumping
> data out on the wire but this is a violation of the ethernet protocol,
> ie a guest error. But I'm no ethernet expert...
>
> thanks
> -- PMM
>

I think it's a guest error (unless we find a guest/driver that depends
on this). Anyway, fixing the buffer overflow should be fine.

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

* Re: [Qemu-devel] [Qemu-arm] [PATCH] cadence_gem: fix buffer overflow
  2016-01-18 16:54             ` Alistair Francis
@ 2016-01-19  2:48               ` Jason Wang
  0 siblings, 0 replies; 20+ messages in thread
From: Jason Wang @ 2016-01-19  2:48 UTC (permalink / raw)
  To: Alistair Francis, Peter Maydell
  Cc: Michael S. Tsirkin, qemu-devel@nongnu.org Developers,
	Prasad Pandit, Peter Crosthwaite, qemu-arm, 刘令



On 01/19/2016 12:54 AM, Alistair Francis wrote:
> On Mon, Jan 18, 2016 at 2:06 AM, Peter Maydell <peter.maydell@linaro.org> wrote:
>> On 18 January 2016 at 09:57, Jason Wang <jasowang@redhat.com> wrote:
>>> Thanks for the pointer.
>>>
>>> In section 16.1.5, it said
>>>
>>> "Jumbo frames are not supported."
>>>
>>> So it was in fact not an unimplemented feature?
> I'd say this should be a guest error then. Unless anyone who knows
> Ethernet well thinks otherwise?
>
> Thanks,
>
> Alistair

Yes, agree.

>
>> I have a vague feeling from the last time I looked at something like
>> this that what often happens is the hardware happily goes on dumping
>> data out on the wire but this is a violation of the ethernet protocol,
>> ie a guest error. But I'm no ethernet expert...
>>
>> thanks
>> -- PMM
>>

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

end of thread, other threads:[~2016-01-19  2:49 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-14  9:43 [Qemu-devel] [PATCH] cadence_gem: fix buffer overflow Michael S. Tsirkin
2016-01-14 10:03 ` [Qemu-devel] [Qemu-arm] " Peter Maydell
2016-01-14 10:11   ` Michael S. Tsirkin
2016-01-15  6:19   ` Peter Crosthwaite
2016-01-15  8:06     ` P J P
2016-01-16  0:20       ` Alistair Francis
2016-01-16  5:23         ` P J P
2016-01-18  3:14     ` Jason Wang
2016-01-14 10:23 ` [Qemu-devel] " P J P
2016-01-15  3:16 ` Jason Wang
2016-01-15  5:39   ` P J P
2016-01-18  6:50 ` Jason Wang
2016-01-18  7:04   ` Peter Crosthwaite
2016-01-18  8:12     ` Jason Wang
2016-01-18  9:08       ` Peter Crosthwaite
2016-01-18  9:57         ` Jason Wang
2016-01-18 10:06           ` [Qemu-devel] [Qemu-arm] " Peter Maydell
2016-01-18 16:54             ` Alistair Francis
2016-01-19  2:48               ` Jason Wang
2016-01-19  2:48             ` Jason Wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.