提交 fe3c546c 编写于 作者: P Prasad J Pandit 提交者: Gerd Hoffmann

usb: check RNDIS buffer offsets & length

When processing remote NDIS control message packets,
the USB Net device emulator uses a fixed length(4096) data buffer.
The incoming informationBufferOffset & Length combination could
overflow and cross that range. Check control message buffer
offsets and length to avoid it.
Reported-by: NQinghao Tang <luodalongde@gmail.com>
Signed-off-by: NPrasad J Pandit <pjp@fedoraproject.org>
Message-id: 1455648821-17340-3-git-send-email-ppandit@redhat.com
Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
上级 64c9bc18
...@@ -916,8 +916,9 @@ static int rndis_query_response(USBNetState *s, ...@@ -916,8 +916,9 @@ static int rndis_query_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8; bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength); buflen = le32_to_cpu(buf->InformationBufferLength);
if (bufoffs + buflen > length) if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL; return USB_RET_STALL;
}
infobuflen = ndis_query(s, le32_to_cpu(buf->OID), infobuflen = ndis_query(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen, infobuf, bufoffs + (uint8_t *) buf, buflen, infobuf,
...@@ -962,8 +963,9 @@ static int rndis_set_response(USBNetState *s, ...@@ -962,8 +963,9 @@ static int rndis_set_response(USBNetState *s,
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8; bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
buflen = le32_to_cpu(buf->InformationBufferLength); buflen = le32_to_cpu(buf->InformationBufferLength);
if (bufoffs + buflen > length) if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
return USB_RET_STALL; return USB_RET_STALL;
}
ret = ndis_set(s, le32_to_cpu(buf->OID), ret = ndis_set(s, le32_to_cpu(buf->OID),
bufoffs + (uint8_t *) buf, buflen); bufoffs + (uint8_t *) buf, buflen);
...@@ -1213,8 +1215,9 @@ static void usb_net_handle_dataout(USBNetState *s, USBPacket *p) ...@@ -1213,8 +1215,9 @@ static void usb_net_handle_dataout(USBNetState *s, USBPacket *p)
if (le32_to_cpu(msg->MessageType) == RNDIS_PACKET_MSG) { if (le32_to_cpu(msg->MessageType) == RNDIS_PACKET_MSG) {
uint32_t offs = 8 + le32_to_cpu(msg->DataOffset); uint32_t offs = 8 + le32_to_cpu(msg->DataOffset);
uint32_t size = le32_to_cpu(msg->DataLength); uint32_t size = le32_to_cpu(msg->DataLength);
if (offs + size <= len) if (offs < len && size < len && offs + size <= len) {
qemu_send_packet(qemu_get_queue(s->nic), s->out_buf + offs, size); qemu_send_packet(qemu_get_queue(s->nic), s->out_buf + offs, size);
}
} }
s->out_ptr -= len; s->out_ptr -= len;
memmove(s->out_buf, &s->out_buf[len], s->out_ptr); memmove(s->out_buf, &s->out_buf[len], s->out_ptr);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册