lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Tue, 14 Mar 2023 11:06:51 +0100
From:   Peter Zijlstra <peterz@...radead.org>
To:     Josh Poimboeuf <jpoimboe@...nel.org>
Cc:     Sami Tolvanen <samitolvanen@...gle.com>, x86@...nel.org,
        linux-kernel@...r.kernel.org, Mark Rutland <mark.rutland@....com>,
        Jason Baron <jbaron@...mai.com>,
        Steven Rostedt <rostedt@...dmis.org>,
        Ard Biesheuvel <ardb@...nel.org>,
        Christophe Leroy <christophe.leroy@...roup.eu>,
        Paolo Bonzini <pbonzini@...hat.com>,
        Sean Christopherson <seanjc@...gle.com>,
        Nick Desaulniers <ndesaulniers@...gle.com>
Subject: Re: [RFC][PATCH 1/5] static_call: Make NULL static calls consistent

On Mon, Mar 13, 2023 at 06:58:36PM -0700, Josh Poimboeuf wrote:
> On Mon, Mar 13, 2023 at 10:48:58AM -0700, Sami Tolvanen wrote:
> > On Sun, Mar 12, 2023 at 8:17 AM Peter Zijlstra <peterz@...radead.org> wrote:
> > >
> > > On Fri, Mar 10, 2023 at 05:20:04PM -0800, Josh Poimboeuf wrote:
> > > >   2) Create yet another "tier" of static call implementations, for
> > > >      arches which can have the unfortunate combo of CFI_CLANG +
> > > >      !HAVE_STATIC_CALL.  CONFIG_ALMOST_DONT_HAVE_STATIC_CALL?
> > > >
> > > >      The arch can define ARCH_DEFINE_STATIC_CALL_NOP() which uses inline
> > > >      asm to create a CFI-compliant NOP/BUG/whatever version of the
> > > >      function (insert lots of hand-waving).  Is the kcfi hash available
> > > >      to inline asm at build time?
> > >
> > > Yes, clang creates magic symbol for everything it sees a declaration
> > > for. This symbols can be referenced from asm, linking will make it all
> > > work.
> > >
> > > And yes, C sucks, you can't actually create a function definition from a
> > > type :/ Otherwise this could be trivially fixable.
> > 
> > Wouldn't creating a separate inline assembly nop function that
> > references the CFI hash of another function with the correct type
> > potentially solve this issue like Josh suggested?

Yes it would, and the below looks about right. It's just a shame the C
language itself cannot sanely express that. Also, having a ton of silly
little nop functions is daft, but alas.

> Right, I was thinking something like this, where the nop function gets
> generated by DEFINE_STATIC_CALL().
> 
> Completely untested of course...
> 
> #define STATIC_CALL_NOP_PREFIX		__SCN__
> #define STATIC_CALL_NOP(name)		__PASTE(STATIC_CALL_NOP_PREFIX, name)
> #define STATIC_CALL_NOP_STR(name)	__stringify(STATIC_CALL_NOP(name))
> 
> #define ARCH_DEFINE_STATIC_CALL_NOP(name, func)				\
> 	asm(".align 4						\n"	\

IIRC arm64 just changed (or is about to) their alignment muck. I think
you can write this like:

	    ".balign " __stringify(CONFIG_FUNCTION_ALIGNMENT) " \n"	\

or somesuch...

> 	    ".word __kcfi_typeid_" STATIC_CALL_NOP_STR(name) "  \n"	\
> 	    ".globl " STATIC_CALL_NOP_STR(name) "		\n"	\
> 	    STATIC_CALL_NOP_STR(name) ":			\n"	\
> 	    "bti c						\n"	\
> 	    "mov x0, xzr					\n"	\
> 	    "ret						\n"	\
> 	    ".type " STATIC_CALL_NOP_STR(name) ", @function	\n"	\
> 	    ".size " STATIC_CALL_NOP_STR(name) ", . - " STATIC_CALL_NOP_STR(name) " \n")
> 
> #define DECLARE_STATIC_CALL(name, func)					\
> 	extern struct static_call_key STATIC_CALL_KEY(name);		\
> 	extern typeof(func) STATIC_CALL_TRAMP(name)			\
> 	extern typeof(func) STATIC_CALL_NOP(name)
> 
> #define DEFINE_STATIC_CALL(name, _func, _func_init)			\
> 	DECLARE_STATIC_CALL(name, _func);				\
> 	ARCH_DEFINE_STATIC_CALL_NOP(name);				\
> 	struct static_call_key STATIC_CALL_KEY(name) = {		\
> 		.func = _func_init,					\
> 	}
> -- 
> Josh

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ