1 From 6314c83ae14ee32835668e38bb55f4b93b800736 Mon Sep 17 00:00:00 2001
2 From: Prasad J Pandit <pjp@fedoraproject.org>
3 Date: Mon, 30 Nov 2015 15:38:22 +0800
4 Subject: [PATCH 1/2] net: pcnet: add check to validate receive data
7 In loopback mode, pcnet_receive routine appends CRC code to the
8 receive buffer. If the data size given is same as the buffer size,
9 the appended CRC code overwrites 4 bytes after s->buffer. Added a
12 Reported by: Qinghao Tang <luodalongde@gmail.com>
13 Cc: qemu-stable@nongnu.org
14 Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
15 Signed-off-by: Jason Wang <jasowang@redhat.com>
17 hw/net/pcnet.c | 8 +++++---
18 1 file changed, 5 insertions(+), 3 deletions(-)
20 diff --git a/hw/net/pcnet.c b/hw/net/pcnet.c
21 index 0eb3cc4..309c40b 100644
24 @@ -1084,7 +1084,7 @@ ssize_t pcnet_receive(NetClientState *nc, const uint8_t *buf, size_t size_)
28 - while (p != &src[size-4])
29 + while (p != &src[size])
31 crc_err = (*(uint32_t *)p != htonl(fcs));
33 @@ -1233,8 +1233,10 @@ static void pcnet_transmit(PCNetState *s)
34 bcnt = 4096 - GET_FIELD(tmd.length, TMDL, BCNT);
36 /* if multi-tmd packet outsizes s->buffer then skip it silently.
37 - Note: this is not what real hw does */
38 - if (s->xmit_pos + bcnt > sizeof(s->buffer)) {
39 + * Note: this is not what real hw does.
40 + * Last four bytes of s->buffer are used to store CRC FCS code.
42 + if (s->xmit_pos + bcnt > sizeof(s->buffer) - 4) {