mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-06 01:03:55 -06:00
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>
This commit is contained in:
parent
626b39006d
commit
5814c08467
2 changed files with 20 additions and 5 deletions
|
@ -102,7 +102,7 @@ typedef struct VirtioNetRscStat {
|
|||
/* Rsc unit general info used to checking if can coalescing */
|
||||
typedef struct VirtioNetRscUnit {
|
||||
void *ip; /* ip header */
|
||||
uint16_t *ip_plen; /* data len pointer in ip header field */
|
||||
void *ip_plen; /* pointer to unaligned uint16_t data len in ip header */
|
||||
struct tcp_header *tcp; /* tcp header */
|
||||
uint16_t tcp_hdrlen; /* tcp header len */
|
||||
uint16_t payload; /* pure payload without virtio/eth/ip/tcp */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue