qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: Mauro Matteo Cascella <mcascell@redhat.com>, qemu-devel@nongnu.org
Cc: jasowang@redhat.com, pgn@zju.edu.cn,
	Laurent Vivier <laurent@vivier.eu>,
	Finn Thain <fthain@telegraphics.com.au>
Subject: Re: [PATCH] hw/net/dp8393x: fix integer underflow in dp8393x_do_transmit_packets()
Date: Mon, 30 Nov 2020 11:44:16 +0100	[thread overview]
Message-ID: <48d8ae85-3292-921a-f249-3b88a1141cc9@amsat.org> (raw)
In-Reply-To: <20201124092445.658647-1-mcascell@redhat.com>

+Laurent/Finn

On 11/24/20 10:24 AM, Mauro Matteo Cascella wrote:
> An integer underflow could occur during packet transmission due to 'tx_len' not
> being updated if SONIC_TFC register is set to zero. Check for negative 'tx_len'
> when removing existing FCS.
> 
> RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1899722
> Signed-off-by: Mauro Matteo Cascella <mcascell@redhat.com>
> Reported-by: Gaoning Pan <pgn@zju.edu.cn>
> ---
>  hw/net/dp8393x.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c
> index 674b04b354..205c0decc5 100644
> --- a/hw/net/dp8393x.c
> +++ b/hw/net/dp8393x.c
> @@ -495,6 +495,10 @@ static void dp8393x_do_transmit_packets(dp8393xState *s)
>          } else {
>              /* Remove existing FCS */
>              tx_len -= 4;
> +            if (tx_len < 0) {
> +                SONIC_ERROR("tx_len is %d\n", tx_len);
> +                break;
> +            }
>          }
>  
>          if (s->regs[SONIC_RCR] & (SONIC_RCR_LB1 | SONIC_RCR_LB0)) {
> 

Doesn't it make more sense to check 'tx_len >= 4'
and skip tx/rx when 'tx_len == 0'?

-- >8 --
@@ -488,25 +488,29 @@ static void
dp8393x_do_transmit_packets(dp8393xState *s)
             }
         }

-        /* Handle Ethernet checksum */
-        if (!(s->regs[SONIC_TCR] & SONIC_TCR_CRCI)) {
-            /* Don't append FCS there, to look like slirp packets
-             * which don't have one */
-        } else {
-            /* Remove existing FCS */
-            tx_len -= 4;
+        if (tx_len >= 4) {
+            /* Handle Ethernet checksum */
+            if (!(s->regs[SONIC_TCR] & SONIC_TCR_CRCI)) {
+                /* Don't append FCS there, to look like slirp packets
+                 * which don't have one */
+            } else {
+                /* Remove existing FCS */
+                tx_len -= 4;
+            }
         }

-        if (s->regs[SONIC_RCR] & (SONIC_RCR_LB1 | SONIC_RCR_LB0)) {
-            /* Loopback */
-            s->regs[SONIC_TCR] |= SONIC_TCR_CRSL;
-            if (nc->info->can_receive(nc)) {
-                s->loopback_packet = 1;
-                nc->info->receive(nc, s->tx_buffer, tx_len);
+        if (tx_len > 0) {
+            if (s->regs[SONIC_RCR] & (SONIC_RCR_LB1 | SONIC_RCR_LB0)) {
+                /* Loopback */
+                s->regs[SONIC_TCR] |= SONIC_TCR_CRSL;
+                if (nc->info->can_receive(nc)) {
+                    s->loopback_packet = 1;
+                    nc->info->receive(nc, s->tx_buffer, tx_len);
+                }
+            } else {
+                /* Transmit packet */
+                qemu_send_packet(nc, s->tx_buffer, tx_len);
             }
-        } else {
-            /* Transmit packet */
-            qemu_send_packet(nc, s->tx_buffer, tx_len);
         }
         s->regs[SONIC_TCR] |= SONIC_TCR_PTX;

---


  reply	other threads:[~2020-11-30 10:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-24  9:24 [PATCH] hw/net/dp8393x: fix integer underflow in dp8393x_do_transmit_packets() Mauro Matteo Cascella
2020-11-30 10:44 ` Philippe Mathieu-Daudé [this message]
2020-11-30 12:11   ` Mauro Matteo Cascella
2020-12-01  5:46     ` Jason Wang
2020-12-01 12:09       ` 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=48d8ae85-3292-921a-f249-3b88a1141cc9@amsat.org \
    --to=f4bug@amsat.org \
    --cc=fthain@telegraphics.com.au \
    --cc=jasowang@redhat.com \
    --cc=laurent@vivier.eu \
    --cc=mcascell@redhat.com \
    --cc=pgn@zju.edu.cn \
    --cc=qemu-devel@nongnu.org \
    /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).