2018-03-14 11:26:34

by Andy Whitcroft

[permalink] [raw]
Subject: [PATCH 1/1] x86/speculation, objtool: Annotate indirect calls/jumps for objtool on 32bit

In 9e0e3c5130e9 ("x86/speculation, objtool: Annotate indirect calls/jumps
for objtool") we added annotations for CALL_NOSPEC/JMP_NOSPEC on x86 64bit.
We did not annotate the 32bit path. Annotate it similarly.

Signed-off-by: Andy Whitcroft <[email protected]>
---
arch/x86/include/asm/nospec-branch.h | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

While reviewing indirect calls in our builds I noted that the
i386 retpoline CALL_NOSPEC is not annotated safe even though
its amd64 equivalent is. I cannot see any reason this is not
also inherantly safe. Peter was there a reason that you did
not annotate this one too? Anyhow, on the assumption this was
just missed, this patch annotates it.

-apw

diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
index d0dabeae0505..07886162bdf8 100644
--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -183,7 +183,10 @@
* otherwise we'll run out of registers. We don't care about CET
* here, anyway.
*/
-# define CALL_NOSPEC ALTERNATIVE("call *%[thunk_target]\n", \
+# define CALL_NOSPEC \
+ ALTERNATIVE( \
+ ANNOTATE_RETPOLINE_SAFE \
+ "call *%[thunk_target]\n", \
" jmp 904f;\n" \
" .align 16\n" \
"901: call 903f;\n" \
--
2.15.1



2018-03-14 11:53:18

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [PATCH 1/1] x86/speculation, objtool: Annotate indirect calls/jumps for objtool on 32bit

On Wed, Mar 14, 2018 at 11:24:27AM +0000, Andy Whitcroft wrote:
> In 9e0e3c5130e9 ("x86/speculation, objtool: Annotate indirect calls/jumps
> for objtool") we added annotations for CALL_NOSPEC/JMP_NOSPEC on x86 64bit.
> We did not annotate the 32bit path. Annotate it similarly.
>
> Signed-off-by: Andy Whitcroft <[email protected]>
> ---
> arch/x86/include/asm/nospec-branch.h | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> While reviewing indirect calls in our builds I noted that the
> i386 retpoline CALL_NOSPEC is not annotated safe even though
> its amd64 equivalent is. I cannot see any reason this is not
> also inherantly safe. Peter was there a reason that you did
> not annotate this one too? Anyhow, on the assumption this was
> just missed, this patch annotates it.

Yeah, just an oversight aided by the fact that I (obviously) never build
32bit kernels.

> diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
> index d0dabeae0505..07886162bdf8 100644
> --- a/arch/x86/include/asm/nospec-branch.h
> +++ b/arch/x86/include/asm/nospec-branch.h
> @@ -183,7 +183,10 @@
> * otherwise we'll run out of registers. We don't care about CET
> * here, anyway.
> */
> -# define CALL_NOSPEC ALTERNATIVE("call *%[thunk_target]\n", \
> +# define CALL_NOSPEC \
> + ALTERNATIVE( \
> + ANNOTATE_RETPOLINE_SAFE \
> + "call *%[thunk_target]\n", \
> " jmp 904f;\n" \
> " .align 16\n" \
> "901: call 903f;\n" \

Acked-by: Peter Zijlstra (Intel) <[email protected]>

2018-03-14 12:25:42

by Ingo Molnar

[permalink] [raw]
Subject: Re: [PATCH 1/1] x86/speculation, objtool: Annotate indirect calls/jumps for objtool on 32bit


* Peter Zijlstra <[email protected]> wrote:

> On Wed, Mar 14, 2018 at 11:24:27AM +0000, Andy Whitcroft wrote:
> > In 9e0e3c5130e9 ("x86/speculation, objtool: Annotate indirect calls/jumps
> > for objtool") we added annotations for CALL_NOSPEC/JMP_NOSPEC on x86 64bit.
> > We did not annotate the 32bit path. Annotate it similarly.
> >
> > Signed-off-by: Andy Whitcroft <[email protected]>
> > ---
> > arch/x86/include/asm/nospec-branch.h | 5 ++++-
> > 1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > While reviewing indirect calls in our builds I noted that the
> > i386 retpoline CALL_NOSPEC is not annotated safe even though
> > its amd64 equivalent is. I cannot see any reason this is not
> > also inherantly safe. Peter was there a reason that you did
> > not annotate this one too? Anyhow, on the assumption this was
> > just missed, this patch annotates it.
>
> Yeah, just an oversight aided by the fact that I (obviously) never build
> 32bit kernels.
>
> > diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
> > index d0dabeae0505..07886162bdf8 100644
> > --- a/arch/x86/include/asm/nospec-branch.h
> > +++ b/arch/x86/include/asm/nospec-branch.h
> > @@ -183,7 +183,10 @@
> > * otherwise we'll run out of registers. We don't care about CET
> > * here, anyway.
> > */
> > -# define CALL_NOSPEC ALTERNATIVE("call *%[thunk_target]\n", \
> > +# define CALL_NOSPEC \
> > + ALTERNATIVE( \
> > + ANNOTATE_RETPOLINE_SAFE \
> > + "call *%[thunk_target]\n", \
> > " jmp 904f;\n" \
> > " .align 16\n" \
> > "901: call 903f;\n" \
>
> Acked-by: Peter Zijlstra (Intel) <[email protected]>

Applied, thanks guys!

Ingo

Subject: [tip:x86/pti] x86/speculation, objtool: Annotate indirect calls/jumps for objtool on 32-bit kernels

Commit-ID: a14bff131108faf50cc0cf864589fd71ee216c96
Gitweb: https://git.kernel.org/tip/a14bff131108faf50cc0cf864589fd71ee216c96
Author: Andy Whitcroft <[email protected]>
AuthorDate: Wed, 14 Mar 2018 11:24:27 +0000
Committer: Ingo Molnar <[email protected]>
CommitDate: Wed, 14 Mar 2018 13:24:31 +0100

x86/speculation, objtool: Annotate indirect calls/jumps for objtool on 32-bit kernels

In the following commit:

9e0e3c5130e9 ("x86/speculation, objtool: Annotate indirect calls/jumps for objtool")

... we added annotations for CALL_NOSPEC/JMP_NOSPEC on 64-bit x86 kernels,
but we did not annotate the 32-bit path.

Annotate it similarly.

Signed-off-by: Andy Whitcroft <[email protected]>
Acked-by: Peter Zijlstra (Intel) <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Arjan van de Ven <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Josh Poimboeuf <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
---
arch/x86/include/asm/nospec-branch.h | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
index b7063cfa19f9..b3996d60f981 100644
--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -183,7 +183,10 @@
* otherwise we'll run out of registers. We don't care about CET
* here, anyway.
*/
-# define CALL_NOSPEC ALTERNATIVE("call *%[thunk_target]\n", \
+# define CALL_NOSPEC \
+ ALTERNATIVE( \
+ ANNOTATE_RETPOLINE_SAFE \
+ "call *%[thunk_target]\n", \
" jmp 904f;\n" \
" .align 16\n" \
"901: call 903f;\n" \

2018-03-14 13:06:32

by Josh Poimboeuf

[permalink] [raw]
Subject: Re: [tip:x86/pti] x86/speculation, objtool: Annotate indirect calls/jumps for objtool on 32-bit kernels

On Wed, Mar 14, 2018 at 05:28:01AM -0700, tip-bot for Andy Whitcroft wrote:
> Commit-ID: a14bff131108faf50cc0cf864589fd71ee216c96
> Gitweb: https://git.kernel.org/tip/a14bff131108faf50cc0cf864589fd71ee216c96
> Author: Andy Whitcroft <[email protected]>
> AuthorDate: Wed, 14 Mar 2018 11:24:27 +0000
> Committer: Ingo Molnar <[email protected]>
> CommitDate: Wed, 14 Mar 2018 13:24:31 +0100
>
> x86/speculation, objtool: Annotate indirect calls/jumps for objtool on 32-bit kernels
>
> In the following commit:
>
> 9e0e3c5130e9 ("x86/speculation, objtool: Annotate indirect calls/jumps for objtool")
>
> ... we added annotations for CALL_NOSPEC/JMP_NOSPEC on 64-bit x86 kernels,
> but we did not annotate the 32-bit path.
>
> Annotate it similarly.

This patch has no effect because objtool only supports 64-bit kernels.

--
Josh

2018-03-14 13:42:38

by Ingo Molnar

[permalink] [raw]
Subject: Re: [tip:x86/pti] x86/speculation, objtool: Annotate indirect calls/jumps for objtool on 32-bit kernels


* Josh Poimboeuf <[email protected]> wrote:

> On Wed, Mar 14, 2018 at 05:28:01AM -0700, tip-bot for Andy Whitcroft wrote:
> > Commit-ID: a14bff131108faf50cc0cf864589fd71ee216c96
> > Gitweb: https://git.kernel.org/tip/a14bff131108faf50cc0cf864589fd71ee216c96
> > Author: Andy Whitcroft <[email protected]>
> > AuthorDate: Wed, 14 Mar 2018 11:24:27 +0000
> > Committer: Ingo Molnar <[email protected]>
> > CommitDate: Wed, 14 Mar 2018 13:24:31 +0100
> >
> > x86/speculation, objtool: Annotate indirect calls/jumps for objtool on 32-bit kernels
> >
> > In the following commit:
> >
> > 9e0e3c5130e9 ("x86/speculation, objtool: Annotate indirect calls/jumps for objtool")
> >
> > ... we added annotations for CALL_NOSPEC/JMP_NOSPEC on 64-bit x86 kernels,
> > but we did not annotate the 32-bit path.
> >
> > Annotate it similarly.
>
> This patch has no effect because objtool only supports 64-bit kernels.

Yeah, indeed - but it's still a good change for completeness, right?

Thanks,

Ingo

2018-03-14 13:53:41

by Josh Poimboeuf

[permalink] [raw]
Subject: Re: [tip:x86/pti] x86/speculation, objtool: Annotate indirect calls/jumps for objtool on 32-bit kernels

On Wed, Mar 14, 2018 at 02:39:43PM +0100, Ingo Molnar wrote:
>
> * Josh Poimboeuf <[email protected]> wrote:
>
> > On Wed, Mar 14, 2018 at 05:28:01AM -0700, tip-bot for Andy Whitcroft wrote:
> > > Commit-ID: a14bff131108faf50cc0cf864589fd71ee216c96
> > > Gitweb: https://git.kernel.org/tip/a14bff131108faf50cc0cf864589fd71ee216c96
> > > Author: Andy Whitcroft <[email protected]>
> > > AuthorDate: Wed, 14 Mar 2018 11:24:27 +0000
> > > Committer: Ingo Molnar <[email protected]>
> > > CommitDate: Wed, 14 Mar 2018 13:24:31 +0100
> > >
> > > x86/speculation, objtool: Annotate indirect calls/jumps for objtool on 32-bit kernels
> > >
> > > In the following commit:
> > >
> > > 9e0e3c5130e9 ("x86/speculation, objtool: Annotate indirect calls/jumps for objtool")
> > >
> > > ... we added annotations for CALL_NOSPEC/JMP_NOSPEC on 64-bit x86 kernels,
> > > but we did not annotate the 32-bit path.
> > >
> > > Annotate it similarly.
> >
> > This patch has no effect because objtool only supports 64-bit kernels.
>
> Yeah, indeed - but it's still a good change for completeness, right?

Yeah, it's fine. Objtool won't use it, but I suppose it makes the code
less surprising and more consistent for humans.

--
Josh