From e0d8add4af0be1d37ede9a16f46424dc08f0d95e Mon Sep 17 00:00:00 2001 From: Hans Petter Selasky Date: Mon, 28 Nov 2022 23:56:16 +0100 Subject: tcp_lro: Fix for undefined behaviour. Make sure the size of the raw[] array in the lro_address union is correctly set at compile time, so that static code analysis tools do not report undefined behaviour. MFC after: 1 week Sponsored by: NVIDIA Networking --- sys/netinet/tcp_lro.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sys/netinet/tcp_lro.h b/sys/netinet/tcp_lro.h index 427657df47e7..e01e451c1e77 100644 --- a/sys/netinet/tcp_lro.h +++ b/sys/netinet/tcp_lro.h @@ -34,6 +34,8 @@ #define _TCP_LRO_H_ #include +#include + #include #ifndef TCP_LRO_ENTRIES @@ -65,8 +67,12 @@ struct inpcb; +/* Precompute the LRO_RAW_ADDRESS_MAX value: */ +#define LRO_RAW_ADDRESS_MAX \ + howmany(12 + 2 * sizeof(struct in6_addr), sizeof(u_long)) + union lro_address { - u_long raw[1]; + u_long raw[LRO_RAW_ADDRESS_MAX]; struct { uint8_t lro_type; /* internal */ #define LRO_TYPE_NONE 0 @@ -89,10 +95,10 @@ union lro_address { struct in6_addr v6; } d_addr; /* destination IPv4/IPv6 address */ }; -} __aligned(sizeof(u_long)); +}; -#define LRO_RAW_ADDRESS_MAX \ - (sizeof(union lro_address) / sizeof(u_long)) +_Static_assert(sizeof(union lro_address) == sizeof(u_long) * LRO_RAW_ADDRESS_MAX, + "The raw field in the lro_address union does not cover the whole structure."); /* Optimize address comparison by comparing one unsigned long at a time: */ -- cgit v1.2.3