linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Sami Tolvanen <samitolvanen@google.com>
Cc: X86 ML <x86@kernel.org>, Kees Cook <keescook@chromium.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Sedat Dilek <sedat.dilek@gmail.com>,
	linux-hardening@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>,
	clang-built-linux <clang-built-linux@googlegroups.com>,
	Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [PATCH v2 00/14] x86: Add support for Clang CFI
Date: Thu, 26 Aug 2021 13:43:59 +0200	[thread overview]
Message-ID: <YSd+f9aY3kpdUo4r@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <CABCJKud6JBk0QP0aSqM3ptRqbZLfKpfsHNF0RcTq4L-rbc7+uw@mail.gmail.com>

On Wed, Aug 25, 2021 at 08:49:36AM -0700, Sami Tolvanen wrote:
> On Tue, Aug 24, 2021 at 12:47 PM Peter Zijlstra <peterz@infradead.org> wrote:
> >
> > On Mon, Aug 23, 2021 at 10:13:04AM -0700, Sami Tolvanen wrote:
> > > This series adds support for Clang's Control-Flow Integrity (CFI)
> > > checking to x86_64. With CFI, the compiler injects a runtime
> > > check before each indirect function call to ensure the target is
> > > a valid function with the correct static type. This restricts
> > > possible call targets and makes it more difficult for an attacker
> > > to exploit bugs that allow the modification of stored function
> > > pointers. For more details, see:
> >
> > If I understand this right; tp_stub_func() in kernel/tracepoint.c
> > violates this (as would much of the HAVE_STATIC_CALL=n code, luckily
> > that is not a valid x86_64 configuration).
> >
> > Specifically, we assign &tp_stub_func to tracepoint_func::func, but that
> > function pointer is only ever indirectly called when cast to the
> > tracepoint prototype:
> >
> >   ((void(*)(void *, proto))(it_func))(__data, args);
> >
> > (see DEFINE_TRACE_FN() in linux/tracepoint.h)
> >
> > This means the indirect function type and the target function type
> > mismatch, resulting in that runtime check you added to trigger.
> 
> Thanks for pointing this out. Yes, that would clearly trip CFI.
> 
> Any concerns about just writing a magic value to the slot instead of
> pointing it to a stub function, and checking for it before the call?

Performance :-) that compare is going to be useless roughly 100% of the
time.

> > Hitting tp_stub_func() at runtime is exceedingly rare, but possible.
> >
> > I realize this is strictly UB per C, but realistically any CDECL ABI
> > requires that any function with arbitrary signature:
> >
> >   void foo(...)
> >   {
> >   }
> >
> > translates to the exact same code. Specifically on x86-64, the super
> > impressive:
> >
> > foo:
> >         RET
> >
> > And as such this works just fine. Except now you wrecked it.
> 
> Sure. Another option is to disable CFI for the functions that perform
> the call, but I would rather avoid that whenever possible.

Is there no means of teaching the compiler about these magical
functions? There's only two possible stubs:

  void foo(...)
  {
  }

and

  unsigned long bar(...)
  {
	return 0;
  }

Both exist in the kernel. We can easily give them a special function
attribute to call them out.

  reply	other threads:[~2021-08-26 11:44 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-23 17:13 Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 01/14] objtool: Add CONFIG_CFI_CLANG support Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 02/14] objtool: Add ASM_STACK_FRAME_NON_STANDARD Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 03/14] linkage: Add DECLARE_ASM_FUNC_SYMBOL Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 04/14] ftrace: Use an opaque type for functions not callable from C Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 05/14] lkdtm: Disable UNSET_SMEP with CFI Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 06/14] lkdtm: Use an opaque type for lkdtm_rodata_do_nothing Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 07/14] x86: Use an opaque type for functions not callable from C Sami Tolvanen
2021-08-26 16:54   ` Andy Lutomirski
2021-08-26 22:11     ` Sami Tolvanen
2021-08-26 23:23       ` Andy Lutomirski
2021-08-26 23:45         ` Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 08/14] x86/extable: Do not mark exception callback as CFI Sami Tolvanen
2021-08-26 16:56   ` Andy Lutomirski
2021-08-30 19:57     ` Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 09/14] x86/purgatory: Disable CFI Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 10/14] x86, relocs: Ignore __typeid__ relocations Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 11/14] x86, module: " Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 12/14] x86, cpu: Use LTO for cpu.c with CFI Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 13/14] x86, kprobes: Fix optprobe_template_func type mismatch Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 14/14] x86, build: Allow CONFIG_CFI_CLANG to be selected Sami Tolvanen
2021-08-23 17:16 ` [PATCH v2 00/14] x86: Add support for Clang CFI Tom Stellard
2021-08-23 17:20   ` Sami Tolvanen
2021-08-24 17:26     ` Tom Stellard
2021-08-24 17:30       ` Sami Tolvanen
2021-08-24 19:46 ` Peter Zijlstra
2021-08-25 15:49   ` Sami Tolvanen
2021-08-26 11:43     ` Peter Zijlstra [this message]
2021-08-26 21:52       ` Sami Tolvanen

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=YSd+f9aY3kpdUo4r@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=clang-built-linux@googlegroups.com \
    --cc=jpoimboe@redhat.com \
    --cc=keescook@chromium.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=rostedt@goodmis.org \
    --cc=samitolvanen@google.com \
    --cc=sedat.dilek@gmail.com \
    --cc=x86@kernel.org \
    --subject='Re: [PATCH v2 00/14] x86: Add support for Clang CFI' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).