Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Kees Cook <kees@kernel.org>
Cc: Sami Tolvanen <samitolvanen@google.com>,
	Nathan Chancellor <nathan@kernel.org>,
	Arnd Bergmann <arnd@arndb.de>,
	Brendan Higgins <brendan.higgins@linux.dev>,
	David Gow <david@davidgow.net>, Rae Moar <raemoar63@gmail.com>,
	llvm@lists.linux.dev, kunit-dev@googlegroups.com,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH v2] kunit: cfi: Add test for kCFI indirect-call type checks
Date: Fri, 19 Jun 2026 11:51:29 +0200	[thread overview]
Message-ID: <20260619095129.GE49529@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20260619093708.GT49951@noisy.programming.kicks-ass.net>

On Fri, Jun 19, 2026 at 11:37:08AM +0200, Peter Zijlstra wrote:
> On Thu, Jun 18, 2026 at 02:09:50PM -0700, Kees Cook wrote:
> 
> > diff --git a/kernel/cfi.c b/kernel/cfi.c
> > index 4dad04ead06c..8cb6a274c865 100644
> > --- a/kernel/cfi.c
> > +++ b/kernel/cfi.c
> > @@ -8,12 +8,61 @@
> >  #include <linux/bpf.h>
> >  #include <linux/cfi_types.h>
> >  #include <linux/cfi.h>
> > +#include <linux/rcupdate.h>
> >  
> >  bool cfi_warn __ro_after_init = IS_ENABLED(CONFIG_CFI_PERMISSIVE);
> >  
> > +#if IS_ENABLED(CONFIG_CFI_KUNIT_TEST)
> > +static bool (*cfi_kunit_failure_hook)(void);
> > +
> > +void cfi_kunit_set_failure_hook(bool (*hook)(void))
> > +{
> 	BUG_ON(cfi_kunit_failure_hook);
> > +	WRITE_ONCE(cfi_kunit_failure_hook, hook);
> > +
> > +	/*
> > +	 * On unregister, wait for any in-flight cfi_kunit_handled() caller to
> > +	 * finish before the (possibly module-resident) hook can be freed.
> > +	 */
> > +	if (!hook)
> > +		synchronize_rcu();
> > +}
> > +EXPORT_SYMBOL_GPL(cfi_kunit_set_failure_hook);
> EXPORT_SYMBOL_FOR_MODULES(cfi_kunit_set_failure_hook, "cfi_kunit")

> >  enum bug_trap_type report_cfi_failure(struct pt_regs *regs, unsigned long addr,
> >  				      unsigned long *target, u32 type)
> >  {
> > +	/*
> > +	 * Let a registered KUnit test consume and count its own deliberate
> > +	 * violations. If it claims the failure, suppress the report and tell
> > +	 * the arch handler to skip the trap and resume the thread, regardless
> > +	 * of CFI_PERMISSIVE.
> > +	 */
> > +	if (cfi_kunit_handled())
> > +		return BUG_TRAP_TYPE_WARN;
> 
> Somewhat ironic to make an indirect call failure do an indirect call,
> which can fail...
> 
> This is really rather horrible. Also, now all an attacker needs to do is
> ensure cfi_kunit_handled() unconditionally returns true. IOW, no distro
> must ever have this KUNIT crap enabled.

Also, if this lives, the check should at least trip the cfi_warn path,
being completely silent is terrible.

That is:

	if (cfi_warn || cfi_kunit_handled())

And then we must ensure that this warn is not suppressible by that other
kunit crud.

  reply	other threads:[~2026-06-19  9:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-18 21:09 [PATCH v2] kunit: cfi: Add test for kCFI indirect-call type checks Kees Cook
2026-06-19  9:37 ` Peter Zijlstra
2026-06-19  9:51   ` Peter Zijlstra [this message]
2026-06-19 20:44     ` Kees Cook
2026-06-19 20:54       ` Kees Cook
2026-06-19 20:42   ` 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=20260619095129.GE49529@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=arnd@arndb.de \
    --cc=brendan.higgins@linux.dev \
    --cc=david@davidgow.net \
    --cc=kees@kernel.org \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=nathan@kernel.org \
    --cc=raemoar63@gmail.com \
    --cc=samitolvanen@google.com \
    /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