2022-03-03 12:18:01

by Peter Zijlstra

[permalink] [raw]
Subject: [PATCH v3 05/39] x86/ibt: Add ANNOTATE_NOENDBR

In order to have objtool warn about code references to !ENDBR
instruction, we need an annotation to allow this for non-control-flow
instances -- consider text range checks, text patching, or return
trampolines etc.

Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Reviewed-by: Kees Cook <[email protected]>
---
include/linux/objtool.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)

--- a/include/linux/objtool.h
+++ b/include/linux/objtool.h
@@ -77,6 +77,12 @@ struct unwind_hint {
#define STACK_FRAME_NON_STANDARD_FP(func)
#endif

+#define ANNOTATE_NOENDBR \
+ "986: \n\t" \
+ ".pushsection .discard.noendbr\n\t" \
+ _ASM_PTR " 986b\n\t" \
+ ".popsection\n\t"
+
#else /* __ASSEMBLY__ */

/*
@@ -129,6 +135,13 @@ struct unwind_hint {
.popsection
.endm

+.macro ANNOTATE_NOENDBR
+.Lhere_\@:
+ .pushsection .discard.noendbr
+ .quad .Lhere_\@
+ .popsection
+.endm
+
#endif /* __ASSEMBLY__ */

#else /* !CONFIG_STACK_VALIDATION */
@@ -139,12 +152,15 @@ struct unwind_hint {
"\n\t"
#define STACK_FRAME_NON_STANDARD(func)
#define STACK_FRAME_NON_STANDARD_FP(func)
+#define ANNOTATE_NOENDBR
#else
#define ANNOTATE_INTRA_FUNCTION_CALL
.macro UNWIND_HINT sp_reg:req sp_offset=0 type:req end=0
.endm
.macro STACK_FRAME_NON_STANDARD func:req
.endm
+.macro ANNOTATE_NOENDBR
+.endm
#endif

#endif /* CONFIG_STACK_VALIDATION */



2022-03-04 20:55:37

by Josh Poimboeuf

[permalink] [raw]
Subject: Re: [PATCH v3 05/39] x86/ibt: Add ANNOTATE_NOENDBR

On Thu, Mar 03, 2022 at 12:23:26PM +0100, Peter Zijlstra wrote:
> In order to have objtool warn about code references to !ENDBR
> instruction, we need an annotation to allow this for non-control-flow
> instances -- consider text range checks, text patching, or return
> trampolines etc.
>
> Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
> Reviewed-by: Kees Cook <[email protected]>
> ---
> include/linux/objtool.h | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)

Also needs copied over to tools/include/linux/objtool.h to avoid the
sync warning.

--
Josh

2022-03-04 21:13:21

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [PATCH v3 05/39] x86/ibt: Add ANNOTATE_NOENDBR

On Fri, Mar 04, 2022 at 10:59:53AM -0800, Josh Poimboeuf wrote:
> On Thu, Mar 03, 2022 at 12:23:26PM +0100, Peter Zijlstra wrote:
> > In order to have objtool warn about code references to !ENDBR
> > instruction, we need an annotation to allow this for non-control-flow
> > instances -- consider text range checks, text patching, or return
> > trampolines etc.
> >
> > Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
> > Reviewed-by: Kees Cook <[email protected]>
> > ---
> > include/linux/objtool.h | 16 ++++++++++++++++
> > 1 file changed, 16 insertions(+)
>
> Also needs copied over to tools/include/linux/objtool.h to avoid the
> sync warning.

Urgh yeah, I keep meaning to add that bit and then immediately forget
about it :/