From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Vladislav Yasevich <vyasevic@redhat.com>,
Peter Maydell <peter.maydell@linaro.org>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PULL 4/7] rtl8139: Fix receive buffer overflow check
Date: Wed, 2 Sep 2015 17:14:50 +0100 [thread overview]
Message-ID: <1441210493-19591-5-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1441210493-19591-1-git-send-email-stefanha@redhat.com>
From: Vladislav Yasevich <vyasevic@redhat.com>
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>
---
hw/net/rtl8139.c | 6 ++++--
1 file 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 */
--
2.4.3
next prev parent reply other threads:[~2015-09-02 16:15 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-02 16:14 [Qemu-devel] [PULL 0/7] Net patches Stefan Hajnoczi
2015-09-02 16:14 ` [Qemu-devel] [PULL 1/7] rtl8139: remove duplicate net/eth.h definitions Stefan Hajnoczi
2015-09-02 16:14 ` [Qemu-devel] [PULL 2/7] rtl8139: use net/eth.h macros instead of custom macros Stefan Hajnoczi
2015-09-02 16:14 ` [Qemu-devel] [PULL 3/7] rtl8139: use ldl/stl wrapper for unaligned 32-bit access Stefan Hajnoczi
2015-09-02 16:14 ` Stefan Hajnoczi [this message]
2015-09-02 16:14 ` [Qemu-devel] [PULL 5/7] rtl8139: Do not consume the packet during overflow in standard mode Stefan Hajnoczi
2015-09-02 16:14 ` [Qemu-devel] [PULL 6/7] vmxnet3: Drop net_vmxnet3_info.can_receive Stefan Hajnoczi
2015-09-03 7:19 ` Shmulik Ladkani
2015-09-24 11:19 ` Shmulik Ladkani
2015-09-25 5:28 ` Jason Wang
2015-09-02 16:14 ` [Qemu-devel] [PULL 7/7] ne2000: Drop ne2000_can_receive Stefan Hajnoczi
2015-09-03 11:09 ` [Qemu-devel] [PULL 0/7] Net patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1441210493-19591-5-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=vyasevic@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).