From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Ingo Molnar <mingo@kernel.org>
Cc: Dave Hansen <dave.hansen@intel.com>,
x86@kernel.org, linux-kernel@vger.kernel.org,
Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
David Woodhouse <dwmw2@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Linus Torvalds <torvalds@linux-foundation.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: Re: [PATCH] x86/entry/64: Fix CR3 restore order in paranoid_exit()
Date: Wed, 14 Feb 2018 10:11:48 -0600 [thread overview]
Message-ID: <20180214161148.c4uxsmbwycsbcfh4@treble> (raw)
In-Reply-To: <20180214073910.boevmg65upbk3vqb@gmail.com>
On Wed, Feb 14, 2018 at 08:39:11AM +0100, Ingo Molnar wrote:
>
> * Dave Hansen <dave.hansen@intel.com> wrote:
>
> > On 02/13/2018 06:27 PM, Josh Poimboeuf wrote:
> > > --- a/arch/x86/entry/entry_64.S
> > > +++ b/arch/x86/entry/entry_64.S
> > > @@ -1167,10 +1167,10 @@ ENTRY(paranoid_exit)
> > > UNWIND_HINT_REGS
> > > DISABLE_INTERRUPTS(CLBR_ANY)
> > > TRACE_IRQS_OFF_DEBUG
> > > + RESTORE_CR3 scratch_reg=%r15 save_reg=%r14
> > > testl %ebx, %ebx /* swapgs needed? */
> > > jnz .Lparanoid_exit_no_swapgs
> > > TRACE_IRQS_IRETQ
> > > - RESTORE_CR3 scratch_reg=%rbx save_reg=%r14
> > > SWAPGS_UNSAFE_STACK
> > > jmp .Lparanoid_exit_restore
> > > .Lparanoid_exit_no_swapgs:
> >
> > TRACE_IRQS_* call non-entry functions that are not mapped by the user
> > CR3. How can this possibly work? What am I missing?
>
> How about something like the patch below? (Totally untested)
>
> Thanks,
>
> Ingo
> ---
> arch/x86/entry/entry_64.S | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
> index cd216c9431e1..8971bd64d515 100644
> --- a/arch/x86/entry/entry_64.S
> +++ b/arch/x86/entry/entry_64.S
> @@ -1175,6 +1175,7 @@ ENTRY(paranoid_exit)
> jmp .Lparanoid_exit_restore
> .Lparanoid_exit_no_swapgs:
> TRACE_IRQS_IRETQ_DEBUG
> + RESTORE_CR3 scratch_reg=%rbx save_reg=%r14
> .Lparanoid_exit_restore:
> jmp restore_regs_and_return_to_kernel
> END(paranoid_exit)
Dave was right, my patch was obviously bogus. I couldn't figure out a
real reproducer, so I made an artificial one (see below) and can confirm
that your patch fixes it.
I would resubmit the patch, but now you're the author, so I'm not sure
how that works with the SOB.
Feel free to add my
Reported-and-tested-by: Josh Poimboeuf <jpoimboe@redhat.com>
Thanks!
-------------
diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index 68c95a09b48d..c181eb23109b 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -325,6 +325,8 @@ syscall_return_via_sysret:
*/
SWITCH_TO_USER_CR3_STACK scratch_reg=%rdi
+ int3
+
popq %rdi
popq %rsp
USERGS_SYSRET64
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index 3d9b2308e7fa..74fabcdf6c36 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -605,6 +605,8 @@ dotraplinkage void notrace do_int3(struct pt_regs *regs, long error_code)
goto exit;
#endif
+ goto exit;
+
if (notify_die(DIE_INT3, "int3", regs, error_code, X86_TRAP_BP,
SIGTRAP) == NOTIFY_STOP)
goto exit;
next prev parent reply other threads:[~2018-02-14 16:11 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-14 2:27 Josh Poimboeuf
2018-02-14 4:19 ` Dave Hansen
2018-02-14 7:39 ` Ingo Molnar
2018-02-14 16:11 ` Josh Poimboeuf [this message]
2018-02-14 22:27 ` Ingo Molnar
2018-02-14 16:13 ` Thomas Gleixner
2018-02-14 17:16 ` Andy Lutomirski
2018-02-14 23:31 ` [tip:x86/pti] x86/entry/64: Fix CR3 restore " tip-bot for Ingo Molnar
2018-02-15 0:31 ` tip-bot for Ingo Molnar
2018-02-14 7:35 ` [PATCH] x86/entry/64: Fix CR3 restore order " Ingo Molnar
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=20180214161148.c4uxsmbwycsbcfh4@treble \
--to=jpoimboe@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=dave.hansen@intel.com \
--cc=dwmw2@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--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
all inboxes | Powered by JetHome®