[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <202508251953.F5194A2@keescook>
Date: Mon, 25 Aug 2025 19:54:44 -0700
From: Kees Cook <kees@...nel.org>
To: Jakub Kicinski <kuba@...nel.org>
Cc: davem@...emloft.net, netdev@...r.kernel.org, edumazet@...gle.com,
pabeni@...hat.com, andrew+netdev@...n.ch, horms@...nel.org,
dhowells@...hat.com, gustavoars@...nel.org,
aleksander.lobakin@...el.com, tstruk@...aio.com
Subject: Re: [PATCH net-next] stddef: don't include compiler_types.h in the
uAPI header
On Wed, Aug 20, 2025 at 10:17:52AM -0700, Jakub Kicinski wrote:
> I realized this include is to give kernel's __counted_by and friends
> precedence over the empty uAPI-facing defines.
Right.
> Not sure this is the most fortunate approach, personally I'd rather wrap
> our empty user-space-facing defines under ifndef __KERNEL__. I think
> it'd be better from "include what you need" perspective. Perhaps stddef
> pulling in compiler annotations is expected, dunno...
I'm trying to leave the door open for userspace to start using these, if
they defined them too.
> Would you be okay with:
>
> diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
> index 6bbccb43f7e7..4c20c62c4faf 100755
> --- a/scripts/headers_install.sh
> +++ b/scripts/headers_install.sh
> @@ -32,7 +32,7 @@ fi
> sed -E -e '
> s/([[:space:](])(__user|__force|__iomem)[[:space:]]/\1/g
> s/__attribute_const__([[:space:]]|$)/\1/g
> - s@...nclude <linux/compiler(|_types).h>@@
> + s@...nclude <linux/compiler.h>@@
> s/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g
> s/(^|[[:space:](])(inline|asm|volatile)([[:space:](]|$)/\1__\2__\3/g
> s@#(ifndef|define|endif[[:space:]]*/[*])[[:space:]]*_UAPI@#\1 @
> diff --git a/include/uapi/linux/stddef.h b/include/uapi/linux/stddef.h
> index b87df1b485c2..9a28f7d9a334 100644
> --- a/include/uapi/linux/stddef.h
> +++ b/include/uapi/linux/stddef.h
> @@ -2,7 +2,9 @@
> #ifndef _UAPI_LINUX_STDDEF_H
> #define _UAPI_LINUX_STDDEF_H
>
> +#ifdef __KERNEL__
> #include <linux/compiler_types.h>
> +#endif
>
> ? As you pointed out compiler_types.h is only included under stddef.h
> so the special handling in the installation script is easily avoided.
I think this should be fine, but something is itching at my mind that
doing __KERNEL__ checks in uAPI is fragile. I can't substantiate this
sensation, though. :P
--
Kees Cook
Powered by blists - more mailing lists