public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@kernel.org>
To: Mark Rutland <mark.rutland@arm.com>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Jason Baron <jbaron@akamai.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ard Biesheuvel <ardb@kernel.org>,
	Christophe Leroy <christophe.leroy@csgroup.eu>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Sean Christopherson <seanjc@google.com>,
	Sami Tolvanen <samitolvanen@google.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Will McVicker <willmcvicker@google.com>,
	Kees Cook <keescook@chromium.org>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v2 08/11] arm64/static_call: Fix static call CFI violations
Date: Wed, 22 Mar 2023 11:09:22 -0700	[thread overview]
Message-ID: <20230322180922.htvb2zau2w7oichy@treble> (raw)
In-Reply-To: <ZBry75KS3F+a0VM0@FVFF77S0Q05N>

On Wed, Mar 22, 2023 at 12:22:07PM +0000, Mark Rutland wrote:
> > The problem is that the __perf_guest_state() static call does an
> > indirect branch to __static_call_return0(), which isn't CFI-compliant.
> 
> IIUC that'd be broken even with the old CFI mechanism, since commit:
> 
>   87b940a0675e2526 ("perf/core: Use static_call to optimize perf_guest_info_callbacks")
> 
> If so, we probably want a Fixes tag?

Yeah, it should definitely get a Fixes tag.  I wasn't quite sure if this
bug started with the above commit or with the CFI_CLANG switch to kcfi.
And then I forgot to investigate.

> > +/* Generate a CFI-compliant static call NOP function */
> > +#define __ARCH_DEFINE_STATIC_CALL_CFI(name, insns)			\
> > +	asm(".align 4						\n"	\
> > +	    ".word __kcfi_typeid_" name "			\n"	\
> > +	    ".globl " name "					\n"	\
> > +	    name ":						\n"	\
> > +	    "bti c						\n"	\
> > +	    insns "						\n"	\
> > +	    "ret						\n"	\
> > +	    ".type " name ", @function				\n"	\
> > +	    ".size " name ", . - " name "			\n")
> > +
> > +#define __ARCH_DEFINE_STATIC_CALL_RET0_CFI(name)			\
> > +	GEN_CFI_SYM(STATIC_CALL_RET0_CFI(name));			\
> > +	__ARCH_DEFINE_STATIC_CALL_CFI(STATIC_CALL_RET0_CFI_STR(name), "mov x0, xzr")
> 
> This looks correct, but given we're generating a regular functions it's
> unfortunate we can't have the compiler generate the actual code with something
> like:
> 
> #define __ARCH_DEFINE_STATIC_CALL_RET0_CFI(rettype, name, args...)	\
> rettype name(args)							\
> {									\
> 	return (rettype)0;						\
> }
> 
> ... but I guess passing the rettype and args around is painful.

Hm, I hadn't considered that.  I'll play around with it.

> Regardless, I gave this a spin atop v6.3-rc3 using LLVM 16.0.0 and CFI_CLANG,
> and it does seem to work, so:
> 
> Tested-by: Mark Rutland <mark.rutland@arm.com>

Thanks!

-- 
Josh

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2023-03-22 18:10 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-22  4:00 [PATCH v2 00/11] static_call: Improve NULL/ret0 handling Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 01/11] static_call: Improve key type abstraction Josh Poimboeuf
2023-03-22  4:53   ` Josh Poimboeuf
2023-03-22  5:02   ` [PATCH v2.1 " Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 02/11] static_call: Flip key type union bit Josh Poimboeuf
2023-03-22  5:03   ` [PATCH v2.1 " Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 03/11] static_call: Remove static_call_mod_init() declaration Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 04/11] static_call: Remove static_call.h dependency on cpu.h Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 05/11] static_call: Make ARCH_ADD_TRAMP_KEY() generic Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 06/11] static_call: "EXPORT_STATIC_CALL_TRAMP" -> "EXPORT_STATIC_CALL_RO" Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 07/11] static_call: Reorganize static call headers Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 08/11] arm64/static_call: Fix static call CFI violations Josh Poimboeuf
2023-03-22 12:22   ` Mark Rutland
2023-03-22 14:19     ` Peter Zijlstra
2023-03-22 18:26       ` Josh Poimboeuf
2023-03-22 18:09     ` Josh Poimboeuf [this message]
2023-03-22 18:07   ` Sami Tolvanen
2023-03-22 18:33     ` Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 09/11] static_call: Make NULL static calls consistent Josh Poimboeuf
2023-03-22 14:45   ` Peter Zijlstra
2023-03-22 14:59   ` Peter Zijlstra
2023-03-22 18:35     ` Josh Poimboeuf
2023-03-22 15:04   ` Christophe Leroy
2023-03-22  4:00 ` [PATCH v2 10/11] static_call: Remove static_call_cond() Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 11/11] static_call: Remove DEFINE_STATIC_CALL_RET0() Josh Poimboeuf
2023-03-22 15:04   ` Christophe Leroy
2023-03-22 18:50     ` Josh Poimboeuf
2023-03-22 15:15   ` Peter Zijlstra
2023-03-22 18:45     ` Josh Poimboeuf

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=20230322180922.htvb2zau2w7oichy@treble \
    --to=jpoimboe@kernel.org \
    --cc=ardb@kernel.org \
    --cc=christophe.leroy@csgroup.eu \
    --cc=jbaron@akamai.com \
    --cc=keescook@chromium.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=ndesaulniers@google.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=samitolvanen@google.com \
    --cc=seanjc@google.com \
    --cc=willmcvicker@google.com \
    --cc=x86@kernel.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