From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Jason Wang <jasowang@redhat.com>, qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Mauro Matteo Cascella" <mcascell@redhat.com>,
"Daniel P . Berrange" <berrange@redhat.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
"P J P" <ppandit@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: [RFC PATCH-for-5.2 1/2] net: Do not accept packets bigger then NET_BUFSIZE
Date: Fri, 27 Nov 2020 16:45:23 +0100 [thread overview]
Message-ID: <20201127154524.1902024-2-philmd@redhat.com> (raw)
In-Reply-To: <20201127154524.1902024-1-philmd@redhat.com>
Do not allow qemu_send_packet*() and qemu_net_queue_send()
functions to accept packets bigger then NET_BUFSIZE.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
We have to put a limit somewhere. NET_BUFSIZE is defined as:
/* Maximum GSO packet size (64k) plus plenty of room for
* the ethernet and virtio_net headers
*/
#define NET_BUFSIZE (4096 + 65536)
If we do want to accept bigger packets (i.e. multiple GSO packets
in a IOV), we could use INT32_MAX as limit...
---
net/net.c | 4 ++++
net/queue.c | 4 ++++
2 files changed, 8 insertions(+)
diff --git a/net/net.c b/net/net.c
index 6a2c3d95670..f29bfac2b11 100644
--- a/net/net.c
+++ b/net/net.c
@@ -644,6 +644,10 @@ static ssize_t qemu_send_packet_async_with_flags(NetClientState *sender,
qemu_hexdump(stdout, "net", buf, size);
#endif
+ if (size > NET_BUFSIZE) {
+ return -1;
+ }
+
if (sender->link_down || !sender->peer) {
return size;
}
diff --git a/net/queue.c b/net/queue.c
index 19e32c80fda..221a1c87961 100644
--- a/net/queue.c
+++ b/net/queue.c
@@ -191,6 +191,10 @@ ssize_t qemu_net_queue_send(NetQueue *queue,
{
ssize_t ret;
+ if (size > NET_BUFSIZE) {
+ return -1;
+ }
+
if (queue->delivering || !qemu_can_send_packet(sender)) {
qemu_net_queue_append(queue, sender, flags, data, size, sent_cb);
return 0;
--
2.26.2
next prev parent reply other threads:[~2020-11-27 15:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-27 15:45 [RFC PATCH-for-5.2 0/2] net: Do not accept packets with invalid huge size Philippe Mathieu-Daudé
2020-11-27 15:45 ` Philippe Mathieu-Daudé [this message]
2020-11-30 2:36 ` [RFC PATCH-for-5.2 1/2] net: Do not accept packets bigger then NET_BUFSIZE Jason Wang
2020-11-30 9:20 ` Mauro Matteo Cascella
2020-11-30 9:59 ` Philippe Mathieu-Daudé
2020-12-04 10:03 ` P J P
2020-12-04 14:01 ` Philippe Mathieu-Daudé
2020-11-27 15:45 ` [RFC PATCH-for-5.2 2/2] net: Assert no packet bigger than NET_BUFSIZE is queued Philippe Mathieu-Daudé
2020-11-30 2:50 ` Jason Wang
2020-11-27 15:47 ` [RFC PATCH-for-5.2 0/2] net: Do not accept packets with invalid huge size Philippe Mathieu-Daudé
2020-11-28 20:59 ` Peter Maydell
2020-11-30 10:02 ` Philippe Mathieu-Daudé
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=20201127154524.1902024-2-philmd@redhat.com \
--to=philmd@redhat.com \
--cc=berrange@redhat.com \
--cc=jasowang@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mcascell@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=ppandit@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@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).