]> www.infradead.org Git - users/dwmw2/qemu.git/commit
hw/net/virtio-net.c: Don't assume IP length field is aligned
authorPeter Maydell <peter.maydell@linaro.org>
Thu, 14 Nov 2024 14:16:18 +0000 (14:16 +0000)
committerPhilippe Mathieu-Daudé <philmd@linaro.org>
Mon, 18 Nov 2024 12:45:45 +0000 (13:45 +0100)
commit5814c08467937154745c6cb2b3400800b98ff897
tree3d4f502a2df032aaa37cc97742aae32cd606789d
parent626b39006d2f9b1378a04cb88a2187bb852cb055
hw/net/virtio-net.c: Don't assume IP length field is aligned

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>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20241114141619.806652-2-peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
hw/net/virtio-net.c
include/hw/virtio/virtio-net.h