Re: [RFC][PATCH 2/2] x86: Clean up default rethunk warning

From: Peter Zijlstra
Date: Mon Nov 04 2024 - 09:30:09 EST


On Mon, Nov 04, 2024 at 12:47:28PM +0100, Borislav Petkov wrote:
> On Mon, Oct 07, 2024 at 10:32:12AM +0200, Peter Zijlstra wrote:
> > - .section .text..__x86.indirect_thunk
> > +#define WARN_ONCE \
>
> This should be in the asm section of arch/x86/include/asm/bug.h so that other
> asm code can use it. It will come in handy...
>
> > + 1: ALTERNATIVE "", "ud2", X86_FEATURE_ALWAYS ; \
>
> ... but uff, you can't because of this ALTERNATIVE. This is a conditional
> WARN_ONCE. Yuck.
>
> I guess ALT_WARN_ONCE or so...

Yeah, Josh already said similar things.

> > + ASM_BUGTABLE_FLAGS(1b, 0, 0, BUGFLAG_WARNING | BUGFLAG_ONCE) ; \
> > + REACHABLE
> >
> > + .section .text..__x86.indirect_thunk
> >
> > .macro POLINE reg
> > ANNOTATE_INTRA_FUNCTION_CALL
> > @@ -382,16 +387,15 @@ SYM_FUNC_END(call_depth_return_thunk)
> > SYM_CODE_START(__x86_return_thunk)
> > UNWIND_HINT_FUNC
> > ANNOTATE_NOENDBR
> > -#if defined(CONFIG_MITIGATION_UNRET_ENTRY) || \
> > - defined(CONFIG_MITIGATION_SRSO) || \
> > - defined(CONFIG_MITIGATION_CALL_DEPTH_TRACKING)
> > - ALTERNATIVE __stringify(ANNOTATE_UNRET_SAFE; ret), \
> > - "jmp warn_thunk_thunk", X86_FEATURE_ALWAYS
> > -#else
> > +
> > +#ifdef CONFIG_X86_64
> > + WARN_ONCE
> > +#endif
>
> And you can add an empty 32-bit WARN_ONCE macro so that we don't have this
> ifdeffery here where ifdeffery gives the last drop of making this file totally
> unreadable...

I just realized all the rethunk crap is 64bit only anyway. So it don't
matter.

But the reason I did this is that we never rewrite thunk calls on 32bit
(really, we should just strip all mitigation shit from it and leave it
to rot).