Skip to contentSkip to conversation

net socket verify packet size

PATCH Applied Dustin Kirkland 2 participants 2 messages Feb 24, 2009 – Feb 27, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net socket verify packet size

net socket oversized packet

This is a patch being carried by Ubuntu against kvm/qemu.

Verify packet size before performing memcpy().

qemu/net.c +13 -4
diff -urpN kvm_84+dfsg.new/qemu/net.c kvm_84+dfsg.new.new/qemu/net.c
@@ -1246,8 +1246,8 @@ typedef struct NetSocketState {
     VLANClientState *vc;
     int fd;
     int state; /* 0 = getting length, 1 = getting data */
-    int index;
-    int packet_len;
+    unsigned int index;
+    unsigned int packet_len;
     uint8_t buf[4096];
     struct sockaddr_in dgram_dst; /* contains inet host and port destination iff connectionless (SOCK_DGRAM) */
 } NetSocketState;
@@ -1280,7 +1280,8 @@ static void net_socket_receive_dgram(voi
 static void net_socket_send(void *opaque)
 {
     NetSocketState *s = opaque;
-    int l, size, err;
+    int size, err;
+    unsigned l;
     uint8_t buf1[4096];
     const uint8_t *buf;
 
@@ -1319,7 +1320,15 @@ static void net_socket_send(void *opaque
             l = s->packet_len - s->index;
             if (l > size)
                 l = size;
-            memcpy(s->buf + s->index, buf, l);
+            if (s->index + l <= sizeof(s->buf)) {
+                memcpy(s->buf + s->index, buf, l);
+            } else {
+                fprintf(stderr, "serious error: oversized packet received,"
+                    "connection terminated.\n");
+                s->state = 0;
+                goto eoc;
+            }
+
             s->index += l;
             buf += l;
             size -= l;
#1 lore raw
Quoted 8 lines · Dustin Kirkland

net socket oversized packet

This is a patch being carried by Ubuntu against kvm/qemu.

Verify packet size before performing memcpy().

Applied. Thanks.

Regards,

Anthony Liguori