From: julien.thierry@arm.com (Julien Thierry)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 5/5] ARM: spectre-v2: per-CPU vtables to work around big.Little systems
Date: Thu, 20 Sep 2018 10:28:51 +0100 [thread overview]
Message-ID: <42b426db-3d7f-0bcc-4c16-c2b36ea786e0@arm.com> (raw)
In-Reply-To: <20180920092129.GJ30658@n2100.armlinux.org.uk>
On 20/09/18 10:21, Russell King - ARM Linux wrote:
> On Thu, Sep 20, 2018 at 10:04:44AM +0100, Julien Thierry wrote:
>> Hi Russell,
>>
>> On 19/09/18 10:49, Russell King wrote:
>>> In big.Little systems, some CPUs require the Spectre workarounds in
>>> paths such as the context switch, but other CPUs do not. In order
>>> to handle these differences, we need per-CPU vtables.
>>>
>>> We are unable to use the kernel's per-CPU variables to support this
>>> as per-CPU is not initialised at times when we need access to the
>>> vtables, so we have to use an array indexed by logical CPU number.
>>>
>>> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
>>> ---
>>> arch/arm/include/asm/proc-fns.h | 14 ++++++++++++++
>>> arch/arm/kernel/setup.c | 5 +++++
>>> arch/arm/kernel/smp.c | 31 +++++++++++++++++++++++++++++++
>>> arch/arm/mm/proc-v7-bugs.c | 17 ++---------------
>>> 4 files changed, 52 insertions(+), 15 deletions(-)
>>>
>>> diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
>>> index 571a1346245b..ddbb25cb8968 100644
>>> --- a/arch/arm/include/asm/proc-fns.h
>>> +++ b/arch/arm/include/asm/proc-fns.h
>>> @@ -104,11 +104,25 @@ extern void cpu_do_resume(void *);
>>> #else
>>> extern struct processor processor;
>>> +#if defined(CONFIG_BIG_LITTLE) && defined(CONFIG_HARDEN_BRANCH_PREDICTOR)
>>> +#include <linux/smp.h>
>>> +/*
>>> + * This can't be a per-cpu variable because we need to access it before
>>> + * per-cpu has been initialised.
>>> + */
>>> +extern struct processor *cpu_vtable[];
>>> +#define PROC_VTABLE(f) cpu_vtable[smp_processor_id()]->f
>>> +static inline void init_proc_vtable(const struct processor *p)
>>> +{
>>> + *cpu_vtable[smp_processor_id()] = *p;
>>> +}
>>
>> As you stated, 32-bit ARM can only have up to 8 logical CPUs. So, do we save
>> much by having an added level of indirection? (i.e. having a table of
>> pointers instead of directly having a table of struct processor)
>
> Yes we do - in a word, security.
>
> If we made this a table of struct processor, because it is written to
> after boot, it would need to be writable for the lifetime of the kernel.
> Since it is in the kernel's static data section, it will be at a well-
> known offset, which means it's a target for attackers to change the
> function pointers.
>
> Exactly this was true of the 'processor' variable, which gained a
> __ro_after_init annotation a while back - and going to a table of
> struct processor would mean that we end up back in that situation.
>
> Having a table of pointers to struct processor means there is an
> additional level of complexity for attackers to get around - they would
> first need to copy an existing table, change its contents, and then
> change the appropriate CPU's cpu_vtable pointer to point to their table.
> Having a table of struct processor just means an attacker would only
> need to poke one 32-bit word in the array for the appropriate CPU to
> gain control.
>
> So yes, this is slightly more complex, but it's that way to avoid
> undoing the benefits that have previously been gained through
> facilities such as read-only data after kernel initialisation.
>
I see, thanks for explaining. A very good reason for it then :) .
Reviewed-by: Julien Thierry <julien.thierry@arm.com>
Thanks,
--
Julien Thierry
next prev parent reply other threads:[~2018-09-20 9:28 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-19 9:48 [PATCH 0/5] Spectre big.Little updates Russell King - ARM Linux
2018-09-19 9:48 ` [PATCH 1/5] ARM: make lookup_processor_type() non-__init Russell King
2018-09-20 9:07 ` Julien Thierry
2018-09-19 9:48 ` [PATCH 2/5] ARM: split out processor lookup Russell King
2018-09-20 9:05 ` Julien Thierry
2018-09-19 9:49 ` [PATCH 3/5] ARM: clean up per-processor check_bugs method call Russell King
2018-09-20 9:06 ` Julien Thierry
2018-09-19 9:49 ` [PATCH 4/5] ARM: add PROC_VTABLE macro Russell King
2018-09-20 9:07 ` Julien Thierry
2018-09-19 9:49 ` [PATCH 5/5] ARM: spectre-v2: per-CPU vtables to work around big.Little systems Russell King
2018-09-20 9:04 ` Julien Thierry
2018-09-20 9:21 ` Russell King - ARM Linux
2018-09-20 9:28 ` Julien Thierry [this message]
2018-10-05 9:09 ` Marek Szyprowski
2018-10-05 9:35 ` Krzysztof Kozlowski
2018-10-05 9:46 ` Russell King - ARM Linux
2018-10-30 10:50 ` Russell King - ARM Linux
2018-10-31 15:21 ` Marek Szyprowski
2018-10-31 18:12 ` Russell King - ARM Linux
2018-11-02 17:17 ` Kevin Hilman
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=42b426db-3d7f-0bcc-4c16-c2b36ea786e0@arm.com \
--to=julien.thierry@arm.com \
--cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).