All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: Nathan Chancellor <nathan@kernel.org>
Cc: "Gustavo A . R . Silva" <gustavoars@kernel.org>,
	"Nicolas Schier" <nicolas.schier@linux.dev>,
	"Masahiro Yamada" <masahiroy@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	linux-kbuild@vger.kernel.org,
	"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>,
	"Tamir Duberstein" <tamird@gmail.com>,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH] kbuild: Enable GCC diagnostic context for value-tracking warnings
Date: Fri, 21 Nov 2025 10:30:48 -0800	[thread overview]
Message-ID: <202511211027.864DFA90@keescook> (raw)
In-Reply-To: <20251120064923.GA3320872@ax162>

On Wed, Nov 19, 2025 at 11:49:23PM -0700, Nathan Chancellor wrote:
> On Wed, Nov 19, 2025 at 02:44:31PM -0800, Kees Cook wrote:
> > Enable GCC 16's coming "-fdiagnostics-show-context=2" option[1] to
> > provide enhanced diagnostic information for value-tracking warnings, which
> > displays the control flow chain leading to the diagnostic. This covers our
> > existing use of -Wrestrict and -Wstringop-overread, and gets us closer to
> > enabling -Warray-bounds, -Wstringop-overflow, and -Wstringop-truncation.
> > 
> > The context depth of 2 provides the immediate decision path that led to
> > the problematic code location, showing conditional checks and branch
> > decisions that caused the warning. This will help us understand why
> > GCC's value-tracking analysis triggered the warning and makes it easier
> > to determine whether warnings are legitimate issues or false positives.
> 
> Would we ever want a depth more than 2? In other words, should this be
> customizable in case there is a warning that needs more context?

Honestly, I'm not sure yet. I think if we find it to be true, we can
add it then. So far, everything I've found works with =1, but I went
with =2 just to be conservative. (And I did build time comparisons --
there is no measurable difference between off, 1, or 2.)

> > For example, an array bounds warning will now show the conditional
> > statements (like "if (i >= 4)") that established the out-of-bounds access
> > range, directly connecting the control flow to the warning location.
> > This is particularly valuable when GCC's interprocedural analysis can
> > generate warnings that are difficult to understand without seeing the
> > inferred control flow.
> 
> Not that it is that different from what you describe here but having an
> actual example of the insight that this gives using a problematic case
> from the past (such as one that resulted in these various warnings
> getting disabled) might be useful for future travellers.

Yeah, I can list some of the prior fixes.

> > Link: https://github.com/gcc-mirror/gcc/commit/6faa3cfe60ff9769d1bebfffdd2c7325217d7389 [1]
> 
> I have a small preference for using links that the project controls,
> i.e.
> 
>   https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=6faa3cfe60ff9769d1bebfffdd2c7325217d7389
> 
> but I am guessing that mirror is not going anywhere and we have the hash
> regardless so consider it a nit.

I regularly have gcc.gnu.org time out for me, so I've been using github
for trees and references, but I can change this.

> 
> > Signed-off-by: Kees Cook <kees@kernel.org>
> > ---
> 
> Reviewed-by: Nathan Chancellor <nathan@kernel.org>

Thanks!

> Should we take this via Kbuild or do you want to take it via the
> hardening tree?

I figured I'd take it via the hardening tree, but I have no strong
rationale for that. ;)

-Kees

-- 
Kees Cook

  reply	other threads:[~2025-11-21 18:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-19 22:44 [PATCH] kbuild: Enable GCC diagnostic context for value-tracking warnings Kees Cook
2025-11-20  6:49 ` Nathan Chancellor
2025-11-21 18:30   ` Kees Cook [this message]
2025-11-20  8:17 ` Miguel Ojeda
2025-11-21 18:32   ` Kees Cook

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=202511211027.864DFA90@keescook \
    --to=kees@kernel.org \
    --cc=gustavoars@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=nathan@kernel.org \
    --cc=nicolas.schier@linux.dev \
    --cc=ojeda@kernel.org \
    --cc=tamird@gmail.com \
    --cc=thomas.weissschuh@linutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.