diff options
author | Kees Cook <kees@kernel.org> | 2024-08-05 14:43:44 -0700 |
---|---|---|
committer | Kees Cook <kees@kernel.org> | 2024-08-22 17:04:43 -0700 |
commit | 559048d156ff3391c4b793779a824c9193e20442 (patch) | |
tree | a05e8cf71ae1b3814c1c59f8f316beb1e9b58ebf /include/linux/compiler_types.h | |
parent | 32ef4b710cbe1a8901534033872a5bc6b1618bbc (diff) | |
download | linux-559048d156ff3391c4b793779a824c9193e20442.tar.gz linux-559048d156ff3391c4b793779a824c9193e20442.tar.bz2 linux-559048d156ff3391c4b793779a824c9193e20442.zip |
string: Check for "nonstring" attribute on strscpy() arguments
GCC already checks for arguments that are marked with the "nonstring"[1]
attribute when used on standard C String API functions (e.g. strcpy). Gain
this compile-time checking also for the kernel's primary string copying
function, strscpy().
Note that Clang has neither "nonstring" nor __builtin_has_attribute().
Link: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-nonstring-variable-attribute [1]
Reviewed-by: Miguel Ojeda <ojeda@kernel.org>
Tested-by: Miguel Ojeda <ojeda@kernel.org>
Link: https://lore.kernel.org/r/20240805214340.work.339-kees@kernel.org
Signed-off-by: Kees Cook <kees@kernel.org>
Diffstat (limited to 'include/linux/compiler_types.h')
-rw-r--r-- | include/linux/compiler_types.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index f14c275950b5..1a957ea2f4fe 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -421,6 +421,13 @@ struct ftrace_likely_data { #define __member_size(p) __builtin_object_size(p, 1) #endif +/* Determine if an attribute has been applied to a variable. */ +#if __has_builtin(__builtin_has_attribute) +#define __annotated(var, attr) __builtin_has_attribute(var, attr) +#else +#define __annotated(var, attr) (false) +#endif + /* * Some versions of gcc do not mark 'asm goto' volatile: * |