qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 1/2] hw/net/virtio-net.c: Don't assume IP length field is


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH v2 1/2] hw/net/virtio-net.c: Don't assume IP length field is aligned
Date: Thu, 14 Nov 2024 17:04:12 +0100
User-agent: Mozilla Thunderbird

On 14/11/24 14:16, Peter Maydell wrote:
In virtio-net.c we assume that the IP length field in the packet is
aligned, and we copy its address into a uint16_t* in the
VirtioNetRscUnit struct which we then dereference later.  This isn't
a safe assumption; it will also result in compilation failures if we
mark the ip_header struct as QEMU_PACKED because the compiler will
not let you take the address of an unaligned struct field.

Make the ip_plen field in VirtioNetRscUnit a void*, and make all the
places where we read or write through that pointer instead use some
new accessor functions read_unit_ip_len() and write_unit_ip_len()
which account for the pointer being potentially unaligned and also do
the network-byte-order conversion we were previously using htons() to
perform.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
  include/hw/virtio/virtio-net.h |  2 +-
  hw/net/virtio-net.c            | 23 +++++++++++++++++++----
  2 files changed, 20 insertions(+), 5 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]