net: mipsnet: check packet length against buffer
authorPrasad J Pandit <pjp@fedoraproject.org>
Thu, 7 Apr 2016 10:26:02 +0000 (15:56 +0530)
committerJason Wang <jasowang@redhat.com>
Wed, 25 May 2016 07:46:07 +0000 (15:46 +0800)
When receiving packets over MIPSnet network device, it uses
receive buffer of size 1514 bytes. In case the controller
accepts large(MTU) packets, it could lead to memory corruption.
Add check to avoid it.

Reported by: Oleksandr Bazhaniuk <oleksandr.bazhaniuk@intel.com>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
Signed-off-by: Jason Wang <jasowang@redhat.com>
hw/net/mipsnet.c

index 740cd98ff1fdc357e4565aa5bd5321a695ebe0d0..cf8b8236df8045023ed1d475b5ea05c2c22508e6 100644 (file)
@@ -83,6 +83,9 @@ static ssize_t mipsnet_receive(NetClientState *nc, const uint8_t *buf, size_t si
     if (!mipsnet_can_receive(nc))
         return 0;
 
+    if (size >= sizeof(s->rx_buffer)) {
+        return 0;
+    }
     s->busy = 1;
 
     /* Just accept everything. */