qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] net: mipsnet: check transmit buffer size before sending
@ 2016-06-08 10:37 P J P
  2016-06-13  3:01 ` Jason Wang
  0 siblings, 1 reply; 5+ messages in thread
From: P J P @ 2016-06-08 10:37 UTC (permalink / raw)
  To: Jason Wang
  Cc: Qemu Developers, Peter Maydell, Leon Alrae, Li Qiang,
	Aurelien Jarno, Prasad J Pandit

From: Prasad J Pandit <pjp@fedoraproject.org>

When processing MIPSnet I/O port write operation, it uses a
transmit buffer tx_buffer[MAX_ETH_FRAME_SIZE=1514]. Two indices
's->tx_written' and 's->tx_count' are used to control data written
to this buffer. If the two were to be equal before writing, it'd
lead to an OOB write access beyond tx_buffer. Add check to avoid it.

Reported-by: Li Qiang <qiang6-s@360.cn>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
---
 hw/net/mipsnet.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Update as per:
  -> https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg02089.html

diff --git a/hw/net/mipsnet.c b/hw/net/mipsnet.c
index 740cd98..450e42d 100644
--- a/hw/net/mipsnet.c
+++ b/hw/net/mipsnet.c
@@ -180,10 +180,12 @@ static void mipsnet_ioport_write(void *opaque, hwaddr addr,
         break;
     case MIPSNET_TX_DATA_BUFFER:
         s->tx_buffer[s->tx_written++] = val;
-        if (s->tx_written == s->tx_count) {
+        if ((s->tx_written >= MAX_ETH_FRAME_SIZE)
+            || (s->tx_written == s->tx_count)) {
             /* Send buffer. */
-            trace_mipsnet_send(s->tx_count);
-            qemu_send_packet(qemu_get_queue(s->nic), s->tx_buffer, s->tx_count);
+            trace_mipsnet_send(s->tx_written);
+            qemu_send_packet(qemu_get_queue(s->nic),
+                                s->tx_buffer, s->tx_written);
             s->tx_count = s->tx_written = 0;
             s->intctl |= MIPSNET_INTCTL_TXDONE;
             s->busy = 1;
-- 
2.5.5

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

* Re: [Qemu-devel] [PATCH v2] net: mipsnet: check transmit buffer size before sending
  2016-06-08 10:37 [Qemu-devel] [PATCH v2] net: mipsnet: check transmit buffer size before sending P J P
@ 2016-06-13  3:01 ` Jason Wang
  2016-06-13  7:17   ` P J P
  0 siblings, 1 reply; 5+ messages in thread
From: Jason Wang @ 2016-06-13  3:01 UTC (permalink / raw)
  To: P J P
  Cc: Peter Maydell, Li Qiang, Prasad J Pandit, Qemu Developers,
	Leon Alrae, Aurelien Jarno



On 2016年06月08日 18:37, P J P wrote:
> From: Prasad J Pandit <pjp@fedoraproject.org>
>
> When processing MIPSnet I/O port write operation, it uses a
> transmit buffer tx_buffer[MAX_ETH_FRAME_SIZE=1514]. Two indices
> 's->tx_written' and 's->tx_count' are used to control data written
> to this buffer. If the two were to be equal before writing, it'd
> lead to an OOB write access beyond tx_buffer. Add check to avoid it.
>
> Reported-by: Li Qiang <qiang6-s@360.cn>
> Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
> ---
>   hw/net/mipsnet.c | 8 +++++---
>   1 file changed, 5 insertions(+), 3 deletions(-)
>
> Update as per:
>    -> https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg02089.html
>
> diff --git a/hw/net/mipsnet.c b/hw/net/mipsnet.c
> index 740cd98..450e42d 100644
> --- a/hw/net/mipsnet.c
> +++ b/hw/net/mipsnet.c
> @@ -180,10 +180,12 @@ static void mipsnet_ioport_write(void *opaque, hwaddr addr,
>           break;
>       case MIPSNET_TX_DATA_BUFFER:
>           s->tx_buffer[s->tx_written++] = val;

I believe we may still have a buffer overflow here, no?

> -        if (s->tx_written == s->tx_count) {
> +        if ((s->tx_written >= MAX_ETH_FRAME_SIZE)
> +            || (s->tx_written == s->tx_count)) {
>               /* Send buffer. */
> -            trace_mipsnet_send(s->tx_count);
> -            qemu_send_packet(qemu_get_queue(s->nic), s->tx_buffer, s->tx_count);
> +            trace_mipsnet_send(s->tx_written);
> +            qemu_send_packet(qemu_get_queue(s->nic),
> +                                s->tx_buffer, s->tx_written);
>               s->tx_count = s->tx_written = 0;
>               s->intctl |= MIPSNET_INTCTL_TXDONE;
>               s->busy = 1;

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

* Re: [Qemu-devel] [PATCH v2] net: mipsnet: check transmit buffer size before sending
  2016-06-13  3:01 ` Jason Wang
@ 2016-06-13  7:17   ` P J P
  2016-06-15  8:48     ` Jason Wang
  0 siblings, 1 reply; 5+ messages in thread
From: P J P @ 2016-06-13  7:17 UTC (permalink / raw)
  To: Jason Wang
  Cc: Peter Maydell, Li Qiang, Qemu Developers, Leon Alrae,
	Aurelien Jarno

  Hello Jason,

+-- On Mon, 13 Jun 2016, Jason Wang wrote --+
| >       case MIPSNET_TX_DATA_BUFFER:
| >           s->tx_buffer[s->tx_written++] = val;
| 
| I believe we may still have a buffer overflow here, no?

  No, this is the overflow that the patch is meant to fix.
 
| > -        if (s->tx_written == s->tx_count) {
| > +        if ((s->tx_written >= MAX_ETH_FRAME_SIZE)
| > +            || (s->tx_written == s->tx_count)) {
| >               /* Send buffer. */

  Earlier, send buffer would occur when if 'tx_written' reached 'tx_count'. 
With this patch, it'll also occur when 'tx_written' reaches maximum frame 
size.

Thank you.
--
Prasad J Pandit / Red Hat Product Security Team
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F

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

* Re: [Qemu-devel] [PATCH v2] net: mipsnet: check transmit buffer size before sending
  2016-06-13  7:17   ` P J P
@ 2016-06-15  8:48     ` Jason Wang
  2016-06-15 17:06       ` Peter Maydell
  0 siblings, 1 reply; 5+ messages in thread
From: Jason Wang @ 2016-06-15  8:48 UTC (permalink / raw)
  To: P J P; +Cc: Peter Maydell, Leon Alrae, Li Qiang, Qemu Developers,
	Aurelien Jarno



On 2016年06月13日 15:17, P J P wrote:
>    Hello Jason,
>
> +-- On Mon, 13 Jun 2016, Jason Wang wrote --+
> | >       case MIPSNET_TX_DATA_BUFFER:
> | >           s->tx_buffer[s->tx_written++] = val;
> |
> | I believe we may still have a buffer overflow here, no?
>
>    No, this is the overflow that the patch is meant to fix.
>   
> | > -        if (s->tx_written == s->tx_count) {
> | > +        if ((s->tx_written >= MAX_ETH_FRAME_SIZE)
> | > +            || (s->tx_written == s->tx_count)) {
> | >               /* Send buffer. */
>
>    Earlier, send buffer would occur when if 'tx_written' reached 'tx_count'.
> With this patch, it'll also occur when 'tx_written' reaches maximum frame
> size.
>
> Thank you.

Ok, applied.

I tend to remove mipsnet in the future (maybe 2.8).

Thanks

> --
> Prasad J Pandit / Red Hat Product Security Team
> 47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F
>

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

* Re: [Qemu-devel] [PATCH v2] net: mipsnet: check transmit buffer size before sending
  2016-06-15  8:48     ` Jason Wang
@ 2016-06-15 17:06       ` Peter Maydell
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Maydell @ 2016-06-15 17:06 UTC (permalink / raw)
  To: Jason Wang; +Cc: P J P, Leon Alrae, Li Qiang, Qemu Developers, Aurelien Jarno

On 15 June 2016 at 09:48, Jason Wang <jasowang@redhat.com> wrote:
> I tend to remove mipsnet in the future (maybe 2.8).

If we're going to do this then I think:
 (1) we should remove the whole mipssim machine model,
 not just its ethernet device
 (2) we should announce in the 2.7 release notes that
 we plan to remove it in 2.8

thanks
-- PMM

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

end of thread, other threads:[~2016-06-15 17:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-08 10:37 [Qemu-devel] [PATCH v2] net: mipsnet: check transmit buffer size before sending P J P
2016-06-13  3:01 ` Jason Wang
2016-06-13  7:17   ` P J P
2016-06-15  8:48     ` Jason Wang
2016-06-15 17:06       ` Peter Maydell

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