Skip to content

Commit 12b9d52

Browse files
committed
Check command lengths are in range
Reported by Ned Williamson, Google. Signed-off-by: Justin Cormack <justin.cormack@docker.com>
1 parent 705f332 commit 12b9d52

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/lib/pci_virtio_9p.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,19 @@ pci_vt9p_thread(void *vsc)
348348
command = buf[4];
349349
tag = (uint16_t)((uint16_t)buf[5] | ((uint16_t)buf[6] << 8));
350350
DPRINTF(("[thread]Got response for tag %d command %d len %d\r\n", (int)tag, (int)command, (int)len));
351+
if (len > BUFSIZE) {
352+
fprintf(stderr, "virtio-9p: command too long, maximum is %d\n", BUFSIZE);
353+
/* Fatal error, crash VM, let us be restarted */
354+
_exit(1);
355+
}
356+
if (len < minlen) {
357+
fprintf(stderr, "virtio-9p: command too short, must be over 7 bytes\n");
358+
/* Fatal error, crash VM, let us be restarted */
359+
_exit(1);
360+
}
351361
n = (size_t)(len - minlen);
352362
ptr = buf + minlen;
353363
while (n) {
354-
assert(len <= BUFSIZE);
355364
ret = read(sc->v9sc_sock, ptr, n);
356365
if (ret <= 0) {
357366
fprintf(stderr, "virtio-9p: unexpected EOF reading-- did the 9P server crash?\n");

0 commit comments

Comments
 (0)