qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: P J P <ppandit@redhat.com>
To: Jason Wang <jasowang@redhat.com>
Cc: "Prasad J Pandit" <pjp@fedoraproject.org>,
	"Stefan Hajnoczi" <stefanha@gmail.com>,
	"Sven Schnelle" <svens@stackframe.org>,
	"Qemu Developers" <qemu-devel@nongnu.org>,
	"Li Qiang" <pangpei.lq@antfin.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Ziming Zhang" <ezrakiez@gmail.com>
Subject: [PATCH v6 2/2] net: tulip: add .can_receive routine
Date: Mon, 23 Mar 2020 17:51:00 +0530	[thread overview]
Message-ID: <20200323122100.893417-3-ppandit@redhat.com> (raw)
In-Reply-To: <20200323122100.893417-1-ppandit@redhat.com>

From: Prasad J Pandit <pjp@fedoraproject.org>

Define .can_receive routine to do sanity checks before receiving
packet data. And call qemu_flush_queued_packets to flush queued
packets once they are read in tulip_receive().

Suggested-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
---
 hw/net/tulip.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

Update v6: merge earlier patch 2 & 3 into one
  -> https://lists.gnu.org/archive/html/qemu-devel/2020-03/msg06868.html

diff --git a/hw/net/tulip.c b/hw/net/tulip.c
index fbe40095da..8d8c9519e7 100644
--- a/hw/net/tulip.c
+++ b/hw/net/tulip.c
@@ -229,6 +229,18 @@ static bool tulip_filter_address(TULIPState *s, const uint8_t *addr)
     return ret;
 }
 
+static int
+tulip_can_receive(NetClientState *nc)
+{
+    TULIPState *s = qemu_get_nic_opaque(nc);
+
+    if (s->rx_frame_len || tulip_rx_stopped(s)) {
+        return false;
+    }
+
+    return true;
+}
+
 static ssize_t tulip_receive(TULIPState *s, const uint8_t *buf, size_t size)
 {
     struct tulip_descriptor desc;
@@ -236,7 +248,7 @@ static ssize_t tulip_receive(TULIPState *s, const uint8_t *buf, size_t size)
     trace_tulip_receive(buf, size);
 
     if (size < 14 || size > sizeof(s->rx_frame) - 4
-        || s->rx_frame_len || tulip_rx_stopped(s)) {
+        || !tulip_can_receive(s->nic->ncs)) {
         return 0;
     }
 
@@ -275,6 +287,8 @@ static ssize_t tulip_receive(TULIPState *s, const uint8_t *buf, size_t size)
         tulip_desc_write(s, s->current_rx_desc, &desc);
         tulip_next_rx_descriptor(s, &desc);
     } while (s->rx_frame_len);
+
+    qemu_flush_queued_packets(qemu_get_queue(s->nic));
     return size;
 }
 
@@ -288,6 +302,7 @@ static NetClientInfo net_tulip_info = {
     .type = NET_CLIENT_DRIVER_NIC,
     .size = sizeof(NICState),
     .receive = tulip_receive_nc,
+    .can_receive = tulip_can_receive,
 };
 
 static const char *tulip_reg_name(const hwaddr addr)
-- 
2.25.1



  parent reply	other threads:[~2020-03-23 12:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-23 12:20 [PATCH v6 0/2] net: tulip: add checks to avoid OOB access P J P
2020-03-23 12:20 ` [PATCH v6 1/2] net: tulip: check frame size and r/w data length P J P
2020-03-24  1:29   ` Li Qiang
2020-03-24  5:45     ` Jason Wang
2020-03-24 13:19       ` P J P
2020-03-24 14:54       ` Li Qiang
2020-03-27  2:09         ` Jason Wang
2020-03-27  2:35           ` Li Qiang
2020-03-27  2:53             ` Jason Wang
2020-03-27  3:43               ` Li Qiang
2020-03-26  4:34       ` P J P
2020-03-23 12:21 ` P J P [this message]
2020-03-24  2:04   ` [PATCH v6 2/2] net: tulip: add .can_receive routine Li Qiang
2020-03-24  5:44     ` Jason Wang

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=20200323122100.893417-3-ppandit@redhat.com \
    --to=ppandit@redhat.com \
    --cc=ezrakiez@gmail.com \
    --cc=jasowang@redhat.com \
    --cc=pangpei.lq@antfin.com \
    --cc=philmd@redhat.com \
    --cc=pjp@fedoraproject.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.com \
    --cc=svens@stackframe.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).