[PATCH] arm64: Work around missing `bti c` in modules

Mark Brown broonie at kernel.org
Wed Aug 31 03:41:45 PDT 2022


On Tue, Aug 30, 2022 at 01:08:26PM -0700, D Scott Phillips wrote:

> GCC does not insert a `bti c` instruction at the beginning of a function
> when all callers reach the function through a direct branch[1]. In the case
> of cross-section calls (like __init to non __init), a thunk may be inserted
> which uses an indirect branch. If that happens, the first instruction in
> the callee function will result in a Branch Target Exception due to the
> missing `bti c`.

Oh, nice - I think this is a good approach.  I'd been poking at things
but not come up with anything yet and didn't want to just disable BTI
since it'd disable BTI for the fairly large set of users with small
enough kernels.  It does weaken the protection but is clearly better
than just disabling it.

> +	/*
> +	 * GCC does not insert a `bti c` instruction at the beginning
> +	 * of a function when all callers reach the function through a
> +	 * direct branch. In the case of cross-section calls (like
> +	 * __init to non __init), a thunk may be inserted which uses
> +	 * an indirect branch. If that happens, the first instruction
> +	 * in the callee function will result in a Branch Target
> +	 * Exception due to the missing `bti c`.
> +	 *
> +	 * If that's the case here, clear PSTATE.BTYPE and resume.
> +	 */

This comment should reference the bug, I'm assuming GCC will fix this at
which point we should stop doing this.

> +	if (IS_ENABLED(CONFIG_CC_IS_GCC)) {

I think we should add a new Kconfig symbol for this which is currently
just def_bool y for GCC but which we can add a version check for when
there is a fix so that kernels built with an unaffected toolchain don't
have the workaround code.  We could do that incrementally but we're more
likely to remember if the placeholder is there already.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20220831/63ba7b32/attachment.sig>


More information about the linux-arm-kernel mailing list