RE: [PATCH v12 2/3] eal: add workaround for UBSAN alignment false positive

Morten Brørup
2026-01-10T15:02:05Z

> From: Scott <scott_mitchell@apple.com>
>
> The optimized __rte_raw_cksum() uses unaligned_uint16_t pointer access
> which triggers UBSAN alignment warnings even though the access is safe
> due to the unaligned type definition.
>
> Add __rte_no_ubsan_alignment attribute to suppress these false positive
> warnings while preserving other UBSAN checks.

I think root cause of the false positive warnings is a faulty type definition of unaligned_uint16_t in rte_common.h [1].

For architectures with strict alignment requirements, the type is correctly defined as:
typedef uint16_t unaligned_uint16_t __rte_aligned(1);

But for architectures with relaxed alignment requirements, the type definition is incomplete:
typedef uint16_t unaligned_uint16_t;

When UBSAN runs with the latter definition (which doesn't remove the type's alignment requirement), UBSAN is correctly warning about the misalignment.

Either UBSAN should run with the first definition (i.e. with __rte_aligned(1)), or the type definitions with __rte_aligned(1) should be used for all architectures.

[1]: https://elixir.bootlin.com/dpdk/v25.11/source/lib/eal/include/rte_common.h#L124

Stephen, WDYT?

>
> Signed-off-by: Scott Mitchell <scott.k.mitch1@gmail.com>
> ---
> lib/eal/include/rte_common.h | 9 +++++++++
> lib/net/rte_cksum.h | 1 +
> 2 files changed, 10 insertions(+)
>
> diff --git a/lib/eal/include/rte_common.h
> b/lib/eal/include/rte_common.h
> index 9e7d84f929..00d428e295 100644
> --- a/lib/eal/include/rte_common.h
> +++ b/lib/eal/include/rte_common.h
> @@ -546,6 +546,15 @@ static void
> __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
> #define __rte_no_asan
> #endif
>
> +/**
> + * Disable UndefinedBehaviorSanitizer alignment check on some code
> + */
> +#if defined(RTE_CC_CLANG) || defined(RTE_CC_GCC)
> +#define __rte_no_ubsan_alignment
> __attribute__((no_sanitize("alignment")))
> +#else
> +#define __rte_no_ubsan_alignment
> +#endif
> +
> /*********** Macros for pointer arithmetic ********/
>
> /**
> diff --git a/lib/net/rte_cksum.h b/lib/net/rte_cksum.h
> index 8dbe1179e8..9a7fda563d 100644
> --- a/lib/net/rte_cksum.h
> +++ b/lib/net/rte_cksum.h
> @@ -39,6 +39,7 @@ extern "C" {
> * @return
> * sum += Sum of all words in the buffer.
> */
> +__rte_no_ubsan_alignment
> static inline uint32_t
> __rte_raw_cksum(const void *buf, size_t len, uint32_t sum)
> {
> --
> 2.39.5 (Apple Git-154)