diff options
author | Alexander Lobakin <aleksander.lobakin@intel.com> | 2024-03-27 15:22:39 +0100 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2024-03-28 18:50:47 -0700 |
commit | ca7e324e8ad385a2da15049953c04ea7310687f7 (patch) | |
tree | cebfe830c0eabe5ac3d900dba2e78149be16cfe7 /include | |
parent | 6e9b01909a811555ff3326cf80a5847169c57806 (diff) | |
download | linux-stable-ca7e324e8ad385a2da15049953c04ea7310687f7.tar.gz linux-stable-ca7e324e8ad385a2da15049953c04ea7310687f7.tar.bz2 linux-stable-ca7e324e8ad385a2da15049953c04ea7310687f7.zip |
compiler_types: add Endianness-dependent __counted_by_{le,be}
Some structures contain flexible arrays at the end and the counter for
them, but the counter has explicit Endianness and thus __counted_by()
can't be used directly.
To increase test coverage for potential problems without breaking
anything, introduce __counted_by_{le,be}() defined depending on
platform's Endianness to either __counted_by() when applicable or noop
otherwise.
Maybe it would be a good idea to introduce such attributes on compiler
level if possible, but for now let's stop on what we have.
Acked-by: Kees Cook <keescook@chromium.org>
Acked-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Link: https://lore.kernel.org/r/20240327142241.1745989-2-aleksander.lobakin@intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/compiler_types.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index 2abaa3a825a9..a29ba6ef1e27 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -282,6 +282,17 @@ struct ftrace_likely_data { #define __no_sanitize_or_inline __always_inline #endif +/* + * Apply __counted_by() when the Endianness matches to increase test coverage. + */ +#ifdef __LITTLE_ENDIAN +#define __counted_by_le(member) __counted_by(member) +#define __counted_by_be(member) +#else +#define __counted_by_le(member) +#define __counted_by_be(member) __counted_by(member) +#endif + /* Do not trap wrapping arithmetic within an annotated function. */ #ifdef CONFIG_UBSAN_SIGNED_WRAP # define __signed_wrap __attribute__((no_sanitize("signed-integer-overflow"))) |