[PATCH] net: mark struct ip6_header as QEMU_PACKED

Peter Maydell posted 1 patch 3 weeks, 3 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260505201324.932323-1-peter.maydell@linaro.org
Maintainers: Dmitry Fleytman <dmitry.fleytman@gmail.com>, Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>, Jason Wang <jasowang@redhat.com>
include/net/eth.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] net: mark struct ip6_header as QEMU_PACKED
Posted by Peter Maydell 3 weeks, 3 days ago
The ip6_header is often used by network devices to examine structures in
packet data, and it's not guaranteed to be aligned. This manifests as
errors from the clang sanitizer like this one:

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../../hw/net/rocker/rocker_of_dpa.c:321:37
../../hw/net/rocker/rocker_of_dpa.c:730:33: runtime error: member access within misaligned address 0x742970fe7ecd for type 'struct ip6_header', which requires 4 byte alignment
0x742970fe7ecd: note: pointer points here
 00 00 02 81 00 60 00  00 00 00 38 3a ff fe 80  00 00 00 00 00 00 00 00  00 00 00 00 00 02 ff 02  00
             ^

Fix this by marking the ip6_header struct as QEMU_PACKED, the way we
have done to handle similar problems involving tcp_header, ip_header,
etc.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
Found this one while I was working on a rocker bug.

 include/net/eth.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/net/eth.h b/include/net/eth.h
index efe270dbfe..46dc9ed5ac 100644
--- a/include/net/eth.h
+++ b/include/net/eth.h
@@ -119,7 +119,7 @@ struct ip6_header {
     } ip6_ctlun;
     struct in6_address ip6_src;    /* source address */
     struct in6_address ip6_dst;    /* destination address */
-};
+} QEMU_PACKED;
 
 typedef struct ip6_pseudo_header {
     struct in6_address ip6_src;
-- 
2.43.0
Re: [PATCH] net: mark struct ip6_header as QEMU_PACKED
Posted by Philippe Mathieu-Daudé 3 weeks, 2 days ago
On 5/5/26 22:13, Peter Maydell wrote:
> The ip6_header is often used by network devices to examine structures in
> packet data, and it's not guaranteed to be aligned. This manifests as
> errors from the clang sanitizer like this one:
> 
> SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../../hw/net/rocker/rocker_of_dpa.c:321:37
> ../../hw/net/rocker/rocker_of_dpa.c:730:33: runtime error: member access within misaligned address 0x742970fe7ecd for type 'struct ip6_header', which requires 4 byte alignment
> 0x742970fe7ecd: note: pointer points here
>   00 00 02 81 00 60 00  00 00 00 38 3a ff fe 80  00 00 00 00 00 00 00 00  00 00 00 00 00 02 ff 02  00
>               ^
> 
> Fix this by marking the ip6_header struct as QEMU_PACKED, the way we
> have done to handle similar problems involving tcp_header, ip_header,
> etc.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---

Queued via hw-misc, thanks.
Re: [PATCH] net: mark struct ip6_header as QEMU_PACKED
Posted by Philippe Mathieu-Daudé 3 weeks, 3 days ago
On 5/5/26 22:13, Peter Maydell wrote:
> The ip6_header is often used by network devices to examine structures in
> packet data, and it's not guaranteed to be aligned. This manifests as
> errors from the clang sanitizer like this one:
> 
> SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../../hw/net/rocker/rocker_of_dpa.c:321:37
> ../../hw/net/rocker/rocker_of_dpa.c:730:33: runtime error: member access within misaligned address 0x742970fe7ecd for type 'struct ip6_header', which requires 4 byte alignment
> 0x742970fe7ecd: note: pointer points here
>   00 00 02 81 00 60 00  00 00 00 38 3a ff fe 80  00 00 00 00 00 00 00 00  00 00 00 00 00 02 ff 02  00
>               ^
> 
> Fix this by marking the ip6_header struct as QEMU_PACKED, the way we
> have done to handle similar problems involving tcp_header, ip_header,
> etc.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> Found this one while I was working on a rocker bug.
> 
>   include/net/eth.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

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

Re: [PATCH] net: mark struct ip6_header as QEMU_PACKED
Posted by Pierrick Bouvier 3 weeks, 3 days ago
On 5/5/2026 1:13 PM, Peter Maydell wrote:
> The ip6_header is often used by network devices to examine structures in
> packet data, and it's not guaranteed to be aligned. This manifests as
> errors from the clang sanitizer like this one:
> 
> SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../../hw/net/rocker/rocker_of_dpa.c:321:37
> ../../hw/net/rocker/rocker_of_dpa.c:730:33: runtime error: member access within misaligned address 0x742970fe7ecd for type 'struct ip6_header', which requires 4 byte alignment
> 0x742970fe7ecd: note: pointer points here
>  00 00 02 81 00 60 00  00 00 00 38 3a ff fe 80  00 00 00 00 00 00 00 00  00 00 00 00 00 02 ff 02  00
>              ^
> 
> Fix this by marking the ip6_header struct as QEMU_PACKED, the way we
> have done to handle similar problems involving tcp_header, ip_header,
> etc.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> Found this one while I was working on a rocker bug.
> 
>  include/net/eth.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>