qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] net: mipsnet: check transmit buffer size before sending
@ 2016-06-02  6:44 P J P
  2016-06-02  9:28 ` Peter Maydell
  0 siblings, 1 reply; 8+ messages in thread
From: P J P @ 2016-06-02  6:44 UTC (permalink / raw)
  To: Qemu Developers; +Cc: Jason Wang, Li Qiang, 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 <liqiang6-s@360.cn>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
---
 hw/net/mipsnet.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/hw/net/mipsnet.c b/hw/net/mipsnet.c
index 740cd98..8d5e5bf 100644
--- a/hw/net/mipsnet.c
+++ b/hw/net/mipsnet.c
@@ -158,7 +158,7 @@ static void mipsnet_ioport_write(void *opaque, hwaddr addr,
     trace_mipsnet_write(addr, val);
     switch (addr) {
     case MIPSNET_TX_DATA_COUNT:
-	s->tx_count = (val <= MAX_ETH_FRAME_SIZE) ? val : 0;
+        s->tx_count = (val < MAX_ETH_FRAME_SIZE) ? val : MAX_ETH_FRAME_SIZE;
         s->tx_written = 0;
         break;
     case MIPSNET_INT_CTL:
@@ -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] 8+ messages in thread

end of thread, other threads:[~2016-06-14  3:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-02  6:44 [Qemu-devel] [PATCH] net: mipsnet: check transmit buffer size before sending P J P
2016-06-02  9:28 ` Peter Maydell
2016-06-02 19:45   ` P J P
2016-06-07  5:02     ` P J P
2016-06-08  6:38       ` Jason Wang
2016-06-08  7:47         ` P J P
2016-06-13  8:35   ` Aurelien Jarno
2016-06-14  3:48     ` Jason Wang

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