]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
net/tap: drop too small packets
authorVladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Wed, 16 Jul 2025 07:28:53 +0000 (10:28 +0300)
committerJason Wang <jasowang@redhat.com>
Mon, 21 Jul 2025 02:21:28 +0000 (10:21 +0800)
Theoretically tap_read_packet() may return size less than
s->host_vnet_hdr_len, and next, we'll work with negative size
(in case of !s->using_vnet_hdr). Let's avoid it.

Don't proceed with size == s->host_vnet_hdr_len as well in case
of !s->using_vnet_hdr, it doesn't make sense.

Tested-by: Lei Yang <leiyang@redhat.com>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Signed-off-by: Jason Wang <jasowang@redhat.com>
net/tap.c

index 23536c09b4652f8e12380b937ae4601f0455be2d..2a8593601931b20a42eb9502300647ec51d0359d 100644 (file)
--- a/net/tap.c
+++ b/net/tap.c
@@ -190,6 +190,11 @@ static void tap_send(void *opaque)
             break;
         }
 
+        if (s->host_vnet_hdr_len && size <= s->host_vnet_hdr_len) {
+            /* Invalid packet */
+            break;
+        }
+
         if (s->host_vnet_hdr_len && !s->using_vnet_hdr) {
             buf  += s->host_vnet_hdr_len;
             size -= s->host_vnet_hdr_len;