qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hw/net/virtio-net.c: fix crash in iov_copy()
@ 2024-05-27 13:31 Dmitry Frolov
  2024-06-11 12:33 ` Дмитрий Фролов
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Frolov @ 2024-05-27 13:31 UTC (permalink / raw)
  To: mst; +Cc: sdl.qemu, qemu-devel, Dmitry Frolov

A crash found while fuzzing device virtio-net-socket-check-used.
Assertion "offset == 0" in iov_copy() fails if less than guest_hdr_len bytes
were transmited.

Signed-off-by: Dmitry Frolov <frolov@swemel.ru>
---
 hw/net/virtio-net.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 24e5e7d347..603b80a50a 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -2783,6 +2783,12 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)
          */
         assert(n->host_hdr_len <= n->guest_hdr_len);
         if (n->host_hdr_len != n->guest_hdr_len) {
+            if (iov_size(out_sg, out_num) < n->guest_hdr_len) {
+                virtio_error(vdev, "virtio-net header is invalid");
+                virtqueue_detach_element(q->tx_vq, elem, 0);
+                g_free(elem);
+                return -EINVAL;
+            }
             unsigned sg_num = iov_copy(sg, ARRAY_SIZE(sg),
                                        out_sg, out_num,
                                        0, n->host_hdr_len);
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] hw/net/virtio-net.c: fix crash in iov_copy()
  2024-05-27 13:31 [PATCH] hw/net/virtio-net.c: fix crash in iov_copy() Dmitry Frolov
@ 2024-06-11 12:33 ` Дмитрий Фролов
  2024-06-11 14:08   ` Alex Bennée
  0 siblings, 1 reply; 3+ messages in thread
From: Дмитрий Фролов @ 2024-06-11 12:33 UTC (permalink / raw)
  To: mst; +Cc: sdl.qemu, qemu-devel

ping

https://patchew.org/QEMU/20240527133140.218300-2-frolov@swemel.ru/

On 27.05.2024 16:31, Dmitry Frolov wrote:
> A crash found while fuzzing device virtio-net-socket-check-used.
> Assertion "offset == 0" in iov_copy() fails if less than guest_hdr_len bytes
> were transmited.
>
> Signed-off-by: Dmitry Frolov <frolov@swemel.ru>
> ---
>   hw/net/virtio-net.c | 6 ++++++
>   1 file changed, 6 insertions(+)
>
> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> index 24e5e7d347..603b80a50a 100644
> --- a/hw/net/virtio-net.c
> +++ b/hw/net/virtio-net.c
> @@ -2783,6 +2783,12 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)
>            */
>           assert(n->host_hdr_len <= n->guest_hdr_len);
>           if (n->host_hdr_len != n->guest_hdr_len) {
> +            if (iov_size(out_sg, out_num) < n->guest_hdr_len) {
> +                virtio_error(vdev, "virtio-net header is invalid");
> +                virtqueue_detach_element(q->tx_vq, elem, 0);
> +                g_free(elem);
> +                return -EINVAL;
> +            }
>               unsigned sg_num = iov_copy(sg, ARRAY_SIZE(sg),
>                                          out_sg, out_num,
>                                          0, n->host_hdr_len);



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] hw/net/virtio-net.c: fix crash in iov_copy()
  2024-06-11 12:33 ` Дмитрий Фролов
@ 2024-06-11 14:08   ` Alex Bennée
  0 siblings, 0 replies; 3+ messages in thread
From: Alex Bennée @ 2024-06-11 14:08 UTC (permalink / raw)
  To: Дмитрий Фролов
  Cc: mst, sdl.qemu, qemu-devel

Дмитрий Фролов <frolov@swemel.ru> writes:

> ping
>
> https://patchew.org/QEMU/20240527133140.218300-2-frolov@swemel.ru/
>
> On 27.05.2024 16:31, Dmitry Frolov wrote:
>> A crash found while fuzzing device virtio-net-socket-check-used.
>> Assertion "offset == 0" in iov_copy() fails if less than guest_hdr_len bytes
>> were transmited.
>>
>> Signed-off-by: Dmitry Frolov <frolov@swemel.ru>
>> ---
>>   hw/net/virtio-net.c | 6 ++++++
>>   1 file changed, 6 insertions(+)
>>
>> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
>> index 24e5e7d347..603b80a50a 100644
>> --- a/hw/net/virtio-net.c
>> +++ b/hw/net/virtio-net.c
>> @@ -2783,6 +2783,12 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)
>>            */
>>           assert(n->host_hdr_len <= n->guest_hdr_len);
>>           if (n->host_hdr_len != n->guest_hdr_len) {
>> +            if (iov_size(out_sg, out_num) < n->guest_hdr_len) {
>> +                virtio_error(vdev, "virtio-net header is invalid");
>> +                virtqueue_detach_element(q->tx_vq, elem, 0);
>> +                g_free(elem);
>> +                return -EINVAL;
>> +            }

Isn't this basically another case for goto detach?

Although the use of goto's here is a bit of a code smell. I wonder if
there is any way to better structure this function and take care of the
auto-freeing of elements?

>>               unsigned sg_num = iov_copy(sg, ARRAY_SIZE(sg),
>>                                          out_sg, out_num,
>>                                          0, n->host_hdr_len);

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-06-11 14:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-27 13:31 [PATCH] hw/net/virtio-net.c: fix crash in iov_copy() Dmitry Frolov
2024-06-11 12:33 ` Дмитрий Фролов
2024-06-11 14:08   ` Alex Bennée

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).