aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Petter Selasky <hselasky@FreeBSD.org>2022-11-28 22:56:16 +0000
committerHans Petter Selasky <hselasky@FreeBSD.org>2023-01-13 10:18:19 +0000
commite0d8add4af0be1d37ede9a16f46424dc08f0d95e (patch)
tree3b74698587a11f5ea816f6e080ef7827372d0f0d
parent8685d7b5cb759b4f688dea93dbe1c38f9e833e4e (diff)
downloadsrc-e0d8add4af0be1d37ede9a16f46424dc08f0d95e.tar.gz
src-e0d8add4af0be1d37ede9a16f46424dc08f0d95e.zip
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
-rw-r--r--sys/netinet/tcp_lro.h14
1 files 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 <sys/time.h>
+#include <sys/param.h>
+
#include <netinet/in.h>
#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: */