From: Akihiko Odaki <akihiko.odaki@daynix.com>
To: Jason Wang <jasowang@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>
Cc: qemu-devel@nongnu.org, devel@daynix.com,
Akihiko Odaki <akihiko.odaki@daynix.com>,
qemu-stable@nongnu.org
Subject: [PATCH v3 2/6] virtio-net: Fix size check in dhclient workaround
Date: Fri, 22 Nov 2024 14:03:08 +0900 [thread overview]
Message-ID: <20241122-queue-v3-2-f2ff03b8dbfd@daynix.com> (raw)
In-Reply-To: <20241122-queue-v3-0-f2ff03b8dbfd@daynix.com>
work_around_broken_dhclient() accesses IP and UDP headers to detect
relevant packets and to calculate checksums, but it didn't check if
the packet has size sufficient to accommodate them, causing out-of-bound
access hazards. Fix this by correcting the size requirement.
Fixes: 1d41b0c1ec66 ("Work around dhclient brokenness")
Cc: qemu-stable@nongnu.org
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
hw/net/virtio-net.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 75b4a28fb3ae..a2a8d6b07bcc 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -1697,8 +1697,11 @@ static void virtio_net_hdr_swap(VirtIODevice *vdev, struct virtio_net_hdr *hdr)
static void work_around_broken_dhclient(struct virtio_net_hdr *hdr,
uint8_t *buf, size_t size)
{
+ size_t csum_size = ETH_HLEN + sizeof(struct ip_header) +
+ sizeof(struct udp_header);
+
if ((hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) && /* missing csum */
- (size > 27 && size < 1500) && /* normal sized MTU */
+ (size >= csum_size && size < 1500) && /* normal sized MTU */
(buf[12] == 0x08 && buf[13] == 0x00) && /* ethertype == IPv4 */
(buf[23] == 17) && /* ip.protocol == UDP */
(buf[34] == 0 && buf[35] == 67)) { /* udp.srcport == bootps */
--
2.47.0
next prev parent reply other threads:[~2024-11-22 5:03 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-22 5:03 [PATCH v3 0/6] virtio-net fixes Akihiko Odaki
2024-11-22 5:03 ` [PATCH v3 1/6] net: checksum: Convert data to void * Akihiko Odaki
2024-11-22 7:09 ` Philippe Mathieu-Daudé
2024-11-22 5:03 ` Akihiko Odaki [this message]
2024-11-22 5:03 ` [PATCH v3 3/6] virtio-net: Do not check for the queue before RSS Akihiko Odaki
2024-11-22 5:03 ` [PATCH v3 4/6] virtio-net: Fix hash reporting when the queue changes Akihiko Odaki
2024-11-22 5:03 ` [PATCH v3 5/6] virtio-net: Initialize hash reporting values Akihiko Odaki
2024-11-22 7:15 ` Philippe Mathieu-Daudé
2024-11-22 5:03 ` [PATCH v3 6/6] virtio-net: Copy received header to buffer Akihiko Odaki
2024-11-26 3:02 ` [PATCH v3 0/6] virtio-net fixes Lei Yang
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=20241122-queue-v3-2-f2ff03b8dbfd@daynix.com \
--to=akihiko.odaki@daynix.com \
--cc=devel@daynix.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@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).