From: Peter Zijlstra <peterz@infradead.org>
To: Nick Desaulniers <ndesaulniers@google.com>
Cc: Borislav Petkov <bp@alien8.de>,
x86@kernel.org, linux-kernel@vger.kernel.org,
David.Kaplan@amd.com, Andrew.Cooper3@citrix.com,
jpoimboe@kernel.org, gregkh@linuxfoundation.org, matz@suse.de,
joao.moreira@intel.com, samitolvanen@google.com
Subject: Re: [RFC][PATCH 02/17] x86/cpu: Clean up SRSO return thunk mess
Date: Sat, 12 Aug 2023 13:20:57 +0200 [thread overview]
Message-ID: <20230812112057.GA749618@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <CAKwvOd=UXhDShdPsofrWScxdF-mTNnDTCNYZDP1rAhhKCB7jVA@mail.gmail.com>
On Fri, Aug 11, 2023 at 10:00:31AM -0700, Nick Desaulniers wrote:
> On Fri, Aug 11, 2023 at 12:01 AM Peter Zijlstra <peterz@infradead.org> wrote:
> >
> > On Thu, Aug 10, 2023 at 02:37:56PM +0200, Peter Zijlstra wrote:
> >
> > > After this patch things look equivalent to:
> > >
> > > SYM_FUNC_START(foo)
> > > ...
> > > ALTERNATIVE "ret; int3"
> > > "jmp __x86_return_thunk", X86_FEATURE_RETHUNK
> > > "jmp srso_return_thunk, X86_FEATURE_SRSO
> > > "jmp srsi_alias_return_thunk", X86_FEATURE_SRSO_ALIAS
> > > SYM_FUNC_END(foo)
> > >
> > > SYM_CODE_START(srso_return_thunk)
> > > UNWIND_HINT_FUNC
> > > ANNOTATE_NOENDBR
> > > call srso_safe_ret;
> > > ud2
> > > SYM_CODE_END(srso_return_thunk)
> > >
> > > SYM_CODE_START(srso_alias_return_thunk)
> > > UNWIND_HINT_FUNC
> > > ANNOTATE_NOENDBR
> > > call srso_alias_safe_ret;
> > > ud2
> > > SYM_CODE_END(srso_alias_return_thunk)
> > >
> >
> > So it looks like the compilers are still not emitting int3 after jmp,
> > even with the SLS options enabled :/
> >
> > This means the tail end of functions compiled with:
> >
> > -mharden-sls=all -mfunction-return=thunk-extern
> >
> > Is still a regular: jmp __x86_return_thunk, no trailing trap.
> >
> > https://godbolt.org/z/Ecqv76YbE
>
> I don't have time to finish this today, but
> https://reviews.llvm.org/D157734 should do what you're looking for, I
> think.
Hmm, so your wording seems to imply regular SLS would already emit INT3
after jump, but I'm not seeing that in clang-16 output. Should I upgrade
my llvm?
[[edit]] Oooh, now I see, regular SLS would emit RET; INT3, but what I'm
alluding to was that sls=all should also emit INT3 after every JMP due
to AMD BTC. This is an SLS option that seems to have gone missing in
both compilers for a long while.
And yesterday I only quickly looked at bigger gcc output and not clang.
But when I look at clang-16 output I see things like:
1053: 2e e8 00 00 00 00 cs call 1059 <yield_to+0xe9> 1055: R_X86_64_PLT32 __x86_indirect_thunk_r11-0x4
1059: 84 c0 test %al,%al
105b: 74 1c je 1079 <yield_to+0x109>
105d: eb 6e jmp 10cd <yield_to+0x15d>
No INT3
105f: 41 bc 01 00 00 00 mov $0x1,%r12d
1065: 80 7c 24 04 00 cmpb $0x0,0x4(%rsp)
106a: 74 0d je 1079 <yield_to+0x109>
106c: 4d 39 fe cmp %r15,%r14
106f: 74 08 je 1079 <yield_to+0x109>
1071: 4c 89 ff mov %r15,%rdi
1074: e8 00 00 00 00 call 1079 <yield_to+0x109> 1075: R_X86_64_PLT32 resched_curr-0x4
1079: 4d 39 fe cmp %r15,%r14
107c: 74 08 je 1086 <yield_to+0x116>
107e: 4c 89 ff mov %r15,%rdi
1081: e8 00 00 00 00 call 1086 <yield_to+0x116> 1082: R_X86_64_PLT32 _raw_spin_unlock-0x4
1086: 4c 89 f7 mov %r14,%rdi
1089: e8 00 00 00 00 call 108e <yield_to+0x11e> 108a: R_X86_64_PLT32 _raw_spin_unlock-0x4
108e: f7 c3 00 02 00 00 test $0x200,%ebx
1094: 74 06 je 109c <yield_to+0x12c>
1096: ff 15 00 00 00 00 call *0x0(%rip) # 109c <yield_to+0x12c> 1098: R_X86_64_PC32 pv_ops+0xfc
109c: 45 85 e4 test %r12d,%r12d
109f: 7e 05 jle 10a6 <yield_to+0x136>
10a1: e8 00 00 00 00 call 10a6 <yield_to+0x136> 10a2: R_X86_64_PLT32 schedule-0x4
10a6: 44 89 e0 mov %r12d,%eax
10a9: 48 83 c4 08 add $0x8,%rsp
10ad: 5b pop %rbx
10ae: 41 5c pop %r12
10b0: 41 5d pop %r13
10b2: 41 5e pop %r14
10b4: 41 5f pop %r15
10b6: 5d pop %rbp
10b7: 2e e9 00 00 00 00 cs jmp 10bd <yield_to+0x14d> 10b9: R_X86_64_PLT32 __x86_return_thunk-0x4
CS padding!!
10bd: 41 bc fd ff ff ff mov $0xfffffffd,%r12d
10c3: f7 c3 00 02 00 00 test $0x200,%ebx
So since you (surprisingly!) CS pad the return thunk, I *could* pull it
off there, 6 bytes is enough space to write: 'CALL foo; INT3'
But really SLS *should* put INT3 after every JMP instruction -- of
course including the return thunk one.
next prev parent reply other threads:[~2023-08-12 11:21 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-09 7:12 [RFC][PATCH 00/17] Fix up the recent SRSO patches Peter Zijlstra
2023-08-09 7:12 ` [RFC][PATCH 01/17] x86/alternative: Unconditional custom return thunk Peter Zijlstra
2023-08-09 9:31 ` Nikolay Borisov
2023-08-10 11:37 ` Borislav Petkov
2023-08-09 7:12 ` [RFC][PATCH 02/17] x86/cpu: Clean up SRSO return thunk mess Peter Zijlstra
2023-08-09 15:45 ` Nikolay Borisov
2023-08-10 11:51 ` Borislav Petkov
2023-08-10 12:37 ` Peter Zijlstra
2023-08-10 12:56 ` Borislav Petkov
2023-08-10 13:22 ` Peter Zijlstra
2023-08-11 7:01 ` Peter Zijlstra
2023-08-11 17:00 ` Nick Desaulniers
2023-08-12 11:20 ` Peter Zijlstra [this message]
2023-08-09 7:12 ` [RFC][PATCH 03/17] x86/cpu: Make srso_untrain_ret consistent Peter Zijlstra
2023-08-10 12:00 ` Borislav Petkov
2023-08-09 7:12 ` [RFC][PATCH 04/17] objtool/x86: Fix SRSO mess Peter Zijlstra
2023-08-10 12:06 ` Borislav Petkov
2023-08-10 12:48 ` Peter Zijlstra
2023-08-10 12:50 ` Peter Zijlstra
2023-08-10 15:02 ` Borislav Petkov
2023-08-10 15:22 ` Peter Zijlstra
2023-08-09 7:12 ` [RFC][PATCH 05/17] x86/cpu: Cleanup the untrain mess Peter Zijlstra
2023-08-09 12:51 ` Josh Poimboeuf
2023-08-09 13:12 ` Peter Zijlstra
2023-08-09 13:26 ` Peter Zijlstra
2023-08-12 18:30 ` Borislav Petkov
2023-08-09 7:12 ` [RFC][PATCH 06/17] x86/cpu: Add SRSO untrain to retbleed= Peter Zijlstra
2023-08-09 13:42 ` Josh Poimboeuf
2023-08-09 14:06 ` Peter Zijlstra
2023-08-09 14:28 ` Josh Poimboeuf
2023-08-09 15:08 ` Peter Zijlstra
2023-08-09 15:43 ` Josh Poimboeuf
2023-08-09 14:31 ` Andrew.Cooper3
2023-08-09 14:39 ` Josh Poimboeuf
2023-08-10 15:44 ` Borislav Petkov
2023-08-10 16:10 ` Josh Poimboeuf
2023-08-11 10:27 ` Borislav Petkov
2023-08-12 11:32 ` Peter Zijlstra
2023-08-12 12:12 ` Borislav Petkov
2023-08-14 15:45 ` David Laight
2023-08-12 11:24 ` Peter Zijlstra
2023-08-12 12:10 ` Borislav Petkov
2023-08-14 10:56 ` Peter Zijlstra
2023-08-09 7:12 ` [RFC][PATCH 07/17] x86/cpu/kvm: Provide UNTRAIN_RET_VM Peter Zijlstra
2023-08-09 13:50 ` Josh Poimboeuf
2023-08-09 14:06 ` Peter Zijlstra
2023-08-09 14:30 ` Josh Poimboeuf
2023-08-09 15:10 ` Peter Zijlstra
2023-08-13 10:36 ` Borislav Petkov
2023-08-14 10:35 ` Peter Zijlstra
2023-08-09 7:12 ` [RFC][PATCH 08/17] x86/cpu: Add IBPB on VMEXIT to retbleed= Peter Zijlstra
2023-08-09 7:12 ` [RFC][PATCH 09/17] x86: Remove CONFIG_CPU_SRSO Peter Zijlstra
2023-08-09 13:57 ` Josh Poimboeuf
2023-08-09 7:12 ` [RFC][PATCH 10/17] x86: Remove CPU_IBPB_ENTRY Peter Zijlstra
2023-08-09 7:12 ` [RFC][PATCH 11/17] x86/cpu: Remove all SRSO interface nonsense Peter Zijlstra
2023-08-09 13:10 ` Andrew.Cooper3
2023-08-09 13:36 ` Peter Zijlstra
2023-08-09 14:05 ` Josh Poimboeuf
2023-08-09 14:43 ` Peter Zijlstra
2023-08-09 14:51 ` Josh Poimboeuf
2023-08-09 15:34 ` Josh Poimboeuf
2023-08-09 7:12 ` [RFC][PATCH 12/17] x86/cpu: Rename original retbleed return thunk Peter Zijlstra
2023-08-09 14:20 ` Josh Poimboeuf
2023-08-09 14:22 ` Peter Zijlstra
2023-08-10 11:06 ` Andrew.Cooper3
2023-08-10 13:02 ` Peter Zijlstra
2023-08-13 15:23 ` Andrew.Cooper3
2023-08-14 10:34 ` Peter Zijlstra
2023-08-14 11:31 ` Andrew.Cooper3
2023-08-14 12:06 ` Peter Zijlstra
2023-08-09 7:12 ` [RFC][PATCH 13/17] objtool/x86: Add arch_is_offset_insn() Peter Zijlstra
2023-08-09 9:56 ` Nikolay Borisov
2023-08-09 14:34 ` Josh Poimboeuf
2023-08-09 7:12 ` [RFC][PATCH 14/17] objtool: Add comments to the arch_is_$foo() magic symbols Peter Zijlstra
2023-08-09 7:12 ` [RFC][PATCH 15/17] x86/cpu: Rename srso_(.*)_alias to srso_alias_\1 Peter Zijlstra
2023-08-09 7:12 ` [RFC][PATCH 16/17] x86/alternatives: Simplify ALTERNATIVE_n() Peter Zijlstra
2023-08-09 7:12 ` [RFC][PATCH 17/17] x86/cpu: Use fancy alternatives to get rid of entry_untrain_ret() Peter Zijlstra
2023-08-09 9:04 ` [RFC][PATCH 00/17] Fix up the recent SRSO patches Nikolay Borisov
2023-08-09 10:04 ` Andrew.Cooper3
2023-08-09 11:58 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230812112057.GA749618@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=Andrew.Cooper3@citrix.com \
--cc=David.Kaplan@amd.com \
--cc=bp@alien8.de \
--cc=gregkh@linuxfoundation.org \
--cc=joao.moreira@intel.com \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matz@suse.de \
--cc=ndesaulniers@google.com \
--cc=samitolvanen@google.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome