From: Kees Cook <keescook@chromium.org>
To: Borislav Petkov <bp@alien8.de>
Cc: "Maciej W. Rozycki" <macro@orcam.me.uk>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H. Peter Anvin" <hpa@zytor.com>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86: Disable kernel stack offset randomization for !TSC
Date: Fri, 13 Jan 2023 15:53:45 -0800 [thread overview]
Message-ID: <202301131547.81D41D8@keescook> (raw)
In-Reply-To: <Y7sfdxJ5/2DSQK/l@zn.tnic>
On Sun, Jan 08, 2023 at 08:55:06PM +0100, Borislav Petkov wrote:
> On Sun, Jan 08, 2023 at 07:42:54PM +0000, Maciej W. Rozycki wrote:
> > For x86 kernel stack offset randomization uses the RDTSC instruction,
> > which causes an invalid opcode exception with hardware that does not
> > implement this instruction:
>
> Out of pure curiosity, what hw is that?
>
> Also, I guess the fix should be something like this instead:
>
> ---
> diff --git a/arch/x86/include/asm/entry-common.h b/arch/x86/include/asm/entry-common.h
> index 117903881fe4..57b372ca6ce7 100644
> --- a/arch/x86/include/asm/entry-common.h
> +++ b/arch/x86/include/asm/entry-common.h
> @@ -85,7 +85,8 @@ static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
> * Therefore, final stack offset entropy will be 5 (x86_64) or
> * 6 (ia32) bits.
> */
> - choose_random_kstack_offset(rdtsc() & 0xFF);
> + if (cpu_feature_enabled(X86_FEATURE_TSC))
> + choose_random_kstack_offset(rdtsc() & 0xFF);
> }
> #define arch_exit_to_user_mode_prepare arch_exit_to_user_mode_prepare
I think probably the entire feature should just be disabled in early
boot, checking for TSC, and then using:
if (!cpu_feature_enabled(X86_FEATURE_TSC))
static_branch_disable(&randomize_kstack_offset);
I'm not sure the best place to put that where it's early but late enough
that static branches are working...
--
Kees Cook
prev parent reply other threads:[~2023-01-13 23:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-08 19:42 [PATCH] x86: Disable kernel stack offset randomization for !TSC Maciej W. Rozycki
2023-01-08 19:55 ` Borislav Petkov
2023-01-08 20:04 ` Maciej W. Rozycki
2023-01-08 20:11 ` Borislav Petkov
2023-01-08 20:39 ` Maciej W. Rozycki
2023-01-13 23:53 ` Kees Cook [this message]
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=202301131547.81D41D8@keescook \
--to=keescook@chromium.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=macro@orcam.me.uk \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--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