[PATCH 07/10] uapi: stddef.h: Introduce __kernel_nonstring

From: Kees Cook
Date: Thu Feb 06 2025 - 20:02:11 EST


In order to annotate byte arrays in UAPI that are not C strings (i.e.
they may not be NUL terminated), the "nonstring" attribute is needed.
However, we can't expose this to userspace as it is compiler version
specific.

Signed-off-by: Kees Cook <kees@xxxxxxxxxx>
---
Cc: Alexey Dobriyan <adobriyan@xxxxxxxxx>
Cc: Sven Eckelmann <sven@xxxxxxxxxxxxx>
Cc: Tadeusz Struk <tadeusz.struk@xxxxxxxxxx>
Cc: Erick Archer <erick.archer@xxxxxxxxxxx>
Cc: Dmitry Antipov <dmantipov@xxxxxxxxx>
---
include/uapi/linux/stddef.h | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/include/uapi/linux/stddef.h b/include/uapi/linux/stddef.h
index 58154117d9b0..0e7d289b7c2e 100644
--- a/include/uapi/linux/stddef.h
+++ b/include/uapi/linux/stddef.h
@@ -63,4 +63,10 @@
#define __counted_by_be(m)
#endif

+#ifdef __KERNEL__
+#define __kernel_nonstring __nonstring
+#else
+#define __kernel_nonstring
+#endif
+
#endif /* _UAPI_LINUX_STDDEF_H */
--
2.34.1