From: Kees Cook <kees@kernel.org>
To: ardb@kernel.org, nathan@kernel.org, Bill Wendling <morbo@google.com>
Cc: gustavoars@kernel.org, ndesaulniers@google.com,
justinstitt@google.com, broonie@kernel.org, elver@google.com,
alan.maguire@oracle.com, namjain@linux.microsoft.com,
peterz@infradead.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org, llvm@lists.linux.dev
Subject: Re: [PATCH v4] compiler_types: Allow opting out of __counted_by and __counted_by_ptr
Date: Tue, 6 Oct 2026 07:12:07 -0700 [thread overview]
Message-ID: <202610060642.7C4125F@keescook> (raw)
In-Reply-To: <20261006094358.2948476-1-morbo@google.com>
On Tue, Oct 06, 2026 at 09:43:58AM +0000, Bill Wendling wrote:
> Code that runs outside the kernel proper, such as the EFI stub, gets
> nothing out of the counted_by annotations: the bounds checks they feed
> (FORTIFY_SOURCE, UBSAN_BOUNDS) are already disabled there.
>
> The annotations can also break the build. A __counted_by_ptr() that
> names a member declared after the pointer needs Clang's
> '-fexperimental-late-parse-attributes', which the top-level Makefile
> adds to 'KBUILD_CFLAGS'. The x86 EFI stub builds its own cflags and does
> not get that flag, so it fails as soon as such a struct is pulled in
> through a common header.
We have a distinction between parsing and output (instrumentation,
linkage, etc). FORTIFY_SOURCE and UBSAN_BOUNDS (and lots of other
things) control output (e.g. fortify alternative linkages, ubsan
instrumentation). We don't normally have parsing issues, as that kind
of thing is usually controlled by compiler flag options (like here). For
example, if a transparent struct ever leaked into a header that libstub
includes, we would explode as well, due to x86's resulting lack of
-fms-extensions.
So, I this should _not_ be managed with a NO_* flag, as that has been
traditionally about suppressing output. I don't think we want to mix
that idiom with parsing issues.
And other architectures solve this problem by not wiping KBUILD_CFLAGS in
the first place. :P So if we want to continue to accept the x86 exception
(which I would argue is the actual problem), we likely need to, instead,
construct an explicit export that is used to collect parsing control
options so that it can be re-included here. Today, I can think of
-fms-extensions besides -fexperimental-late-parse-attributes.
KBUILD_PARSE_CFLAGS += -fms-extensions
...
KBUILD_PARSE_CFLAGS += -fexperimental-late-parse-attributes
...
export KBUILD_PARSE_CFLAGS
KBUILD_CFLAGS += $(KBUILD_PARSE_CFLAGS)
...
We already do something like this for CLANG_FLAGS, which, given
-fexperimental-late-parse-attributes being Clang-specific, perhaps we
ignore my -fms-extensions future-proofing, and just add it there, but
it doesn't look like that is how scripts/Makefile.clang was intended to
be used.
But, again, I think the problem is x86's wipe of the flags. In fact, I
see an explicit problem with that today, which is the loss of
-fauto-trivial-var-init, which all the other arch's stub gain (it's an
output flag, but it happens to neither change linkage nor create hooked
instrumentation). So x86 efi stub lacks stack var zeroing but all the
other archs have it.
Can we just fix x86 correctly to use filter-out, etc, there?
-Kees
--
Kees Cook
next prev parent reply other threads:[~2026-10-06 14:12 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-05 10:25 [PATCH] " Bill Wendling
2026-10-05 10:44 ` Justin Stitt
2026-10-05 10:53 ` Ard Biesheuvel
2026-10-05 15:52 ` Bill Wendling
2026-10-05 19:19 ` Bill Wendling
2026-10-05 19:20 ` [PATCH v3] " Bill Wendling
2026-10-05 21:25 ` Ard Biesheuvel
2026-10-06 7:30 ` Justin Stitt
2026-10-06 8:07 ` Ard Biesheuvel
2026-10-06 9:23 ` Bill Wendling
2026-10-06 9:43 ` [PATCH v4] " Bill Wendling
2026-10-06 10:08 ` Ard Biesheuvel
2026-10-06 13:46 ` Bill Wendling
2026-10-06 14:12 ` Kees Cook [this message]
2026-10-06 13:45 ` [PATCH v5] " Bill Wendling
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202610060642.7C4125F@keescook \
--to=kees@kernel.org \
--cc=alan.maguire@oracle.com \
--cc=ardb@kernel.org \
--cc=broonie@kernel.org \
--cc=elver@google.com \
--cc=gustavoars@kernel.org \
--cc=justinstitt@google.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=morbo@google.com \
--cc=namjain@linux.microsoft.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®