summaryrefslogtreecommitdiffstats
path: root/hw/net
diff options
context:
space:
mode:
authorVladislav Yasevich <vyasevic@redhat.com>2015-09-01 11:26:45 -0400
committerStefan Hajnoczi <stefanha@redhat.com>2015-09-02 13:42:31 +0100
commitfabdcd3392f16fc666b1d04fc1bbe5f1dbbf10a4 (patch)
tree77b53dd72e56d9df2a23be9b76144683a332a26a /hw/net
parent26c0114d3f69c3accaf83d56ff1d850bd0213b58 (diff)
downloadhqemu-fabdcd3392f16fc666b1d04fc1bbe5f1dbbf10a4.zip
hqemu-fabdcd3392f16fc666b1d04fc1bbe5f1dbbf10a4.tar.gz
rtl8139: Fix receive buffer overflow check
rtl8139_do_receive() tries to check for the overflow condition by making sure that packet_size + 8 does not exceed the available buffer space. The issue here is that RxBuffAddr, used to calculate available buffer space, is aligned to a a 4 byte boundry after every update. So it is possible that every packet ends up being slightly padded when written to the receive buffer. This padding is not taken into account when checking for overflow and we may end up missing the overflow condition can causing buffer overwrite. This patch takes alignment into consideration when checking for overflow condition. Signed-off-by: Vladislav Yasevich <vyasevic@redhat.com> Reviewed-by: Jason Wang <jasowang@redhat.com> Message-id: 1441121206-6997-2-git-send-email-vyasevic@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'hw/net')
-rw-r--r--hw/net/rtl8139.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c
index 366d1b5..960580b 100644
--- a/hw/net/rtl8139.c
+++ b/hw/net/rtl8139.c
@@ -1146,7 +1146,9 @@ static ssize_t rtl8139_do_receive(NetClientState *nc, const uint8_t *buf, size_t
/* if receiver buffer is empty then avail == 0 */
- if (avail != 0 && size + 8 >= avail)
+#define RX_ALIGN(x) (((x) + 3) & ~0x3)
+
+ if (avail != 0 && RX_ALIGN(size + 8) >= avail)
{
DPRINTF("rx overflow: rx buffer length %d head 0x%04x "
"read 0x%04x === available 0x%04x need 0x%04x\n",
@@ -1174,7 +1176,7 @@ static ssize_t rtl8139_do_receive(NetClientState *nc, const uint8_t *buf, size_t
rtl8139_write_buffer(s, (uint8_t *)&val, 4);
/* correct buffer write pointer */
- s->RxBufAddr = MOD2((s->RxBufAddr + 3) & ~0x3, s->RxBufferSize);
+ s->RxBufAddr = MOD2(RX_ALIGN(s->RxBufAddr), s->RxBufferSize);
/* now we can signal we have received something */
OpenPOWER on IntegriCloud