From: Jason Wang <jasowang@redhat.com>
To: Vladislav Yasevich <vyasevic@redhat.com>, qemu-devel@nongnu.org
Cc: stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH v4 1/2] rtl8139: Fix receive buffer overflow check
Date: Wed, 2 Sep 2015 11:09:22 +0800 [thread overview]
Message-ID: <55E66862.7050201@redhat.com> (raw)
In-Reply-To: <1441121206-6997-2-git-send-email-vyasevic@redhat.com>
On 09/01/2015 11:26 PM, Vladislav Yasevich wrote:
> 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>
> ---
> 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 edbb61c..8a33466 100644
> --- a/hw/net/rtl8139.c
> +++ b/hw/net/rtl8139.c
> @@ -1148,7 +1148,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",
> @@ -1176,7 +1178,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 */
>
Reviewed-by: Jason Wang <jasowang@redhat.com>
next prev parent reply other threads:[~2015-09-02 3:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-01 15:26 [Qemu-devel] [PATCH v4 0/2] rtl8139: Fix buffer overflow in standard mode Vladislav Yasevich
2015-09-01 15:26 ` [Qemu-devel] [PATCH v4 1/2] rtl8139: Fix receive buffer overflow check Vladislav Yasevich
2015-09-02 3:09 ` Jason Wang [this message]
2015-09-01 15:26 ` [Qemu-devel] [PATCH v4 2/2] rtl8139: Do not consume the packet during overflow in standard mode Vladislav Yasevich
2015-09-02 3:09 ` Jason Wang
2015-09-02 12:42 ` [Qemu-devel] [PATCH v4 0/2] rtl8139: Fix buffer " Stefan Hajnoczi
2015-09-02 12:53 ` Stefan Hajnoczi
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=55E66862.7050201@redhat.com \
--to=jasowang@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--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).