linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb@kernel.org>
To: linux-arm-kernel@lists.infradead.org
Cc: Ard Biesheuvel <ardb@kernel.org>,
	Keith Packard <keithpac@amazon.com>,
	Russell King <linux@armlinux.org.uk>,
	Kees Cook <keescook@chromium.org>, Arnd Bergmann <arnd@arndb.de>,
	Linus Walleij <linus.walleij@linaro.org>
Subject: [PATCH v5 0/5] ARM: support THREAD_INFO_IN_TASK
Date: Sat, 18 Sep 2021 10:44:33 +0200	[thread overview]
Message-ID: <20210918084438.3288002-1-ardb@kernel.org> (raw)

Placing thread_info in the kernel stack leaves it vulnerable to stack
overflow attacks. This short series addresses that by using the existing
THREAD_INFO_IN_TASK infrastructure.

Changes since v4:

- Pass -mtp=cp15 to the compiler to force the use of the TLS register
  when __builtin_thread_pointer() is used - this allows us to enable its
  use on Clang as well.

- Tweak the __switch_to() changes not to affect builds that have the
  feature disabled (as requested by Russell), and to defer update of the
  TLS register to the point where the stack pointer is updated as well.

- Tweak the #ifdef's so we avoid touching the TLS registers on builds
  that may target v6 systems without HWCAP_TLS.

- Use task_cpu() in the final patch to assign thread_info->cpu, so that
  this series can be carried independently of the series I proposed for
  moving the CPU field back into thread_info [1].

Changes since v3:

- Leave the CPU field in thread_info, and keep it in sync at context
  switch time. This is by far the easiest and cleanest way to work
  around the fact that it is infeasible to implement
  raw_smp_processor_id() in terms of task_struct::cpu (for reasons of
  header soup).

- Drop the VFP changes, they are no longer necessary given the previous
  point.

- Drop the change to pass the CPU number to secondary_start_kernel().
  Given that we also need to pass the idle task pointer, which carries
  the CPU number, passing the CPU number directly is redundant.

- Use the TPIDRURO register to carry 'current' while running in the
  kernel, and keep using TPIDRPRW for the per-CPU offset as before. This
  way, there is no need to make any changes to the way the per-CPU offsets
  are programmed. It also avoids the concurrency issues that would
  result from carrying the 'current' pointer in a per-CPU variable.

- Update the per-task stack protector plugin to pull the stack canary
  value directly from the task struct.

Cc: Keith Packard <keithpac@amazon.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Kees Cook <keescook@chromium.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Linus Walleij <linus.walleij@linaro.org>

[0] https://lore.kernel.org/all/20210907220038.91021-1-keithpac@amazon.com/
[1] https://lore.kernel.org/all/20210914121036.3975026-1-ardb@kernel.org/

Ard Biesheuvel (4):
  gcc-plugins: arm-ssp: Prepare for THREAD_INFO_IN_TASK support
  ARM: smp: Free up the TLS register while running in the kernel
  ARM: smp: Store current pointer in TPIDRURO register if available
  ARM: smp: Enable THREAD_INFO_IN_TASK

Keith Packard (1):
  ARM: smp: Pass task to secondary_start_kernel

 arch/arm/Kconfig                              |  8 +++-
 arch/arm/Makefile                             |  9 ++--
 arch/arm/include/asm/assembler.h              | 29 ++++++++++++
 arch/arm/include/asm/current.h                | 50 ++++++++++++++++++++
 arch/arm/include/asm/smp.h                    |  3 +-
 arch/arm/include/asm/stackprotector.h         |  2 -
 arch/arm/include/asm/switch_to.h              | 16 +++++++
 arch/arm/include/asm/thread_info.h            | 15 ++++--
 arch/arm/include/asm/tls.h                    | 10 ++--
 arch/arm/kernel/asm-offsets.c                 |  6 +--
 arch/arm/kernel/entry-armv.S                  |  5 ++
 arch/arm/kernel/entry-common.S                |  1 +
 arch/arm/kernel/entry-header.S                |  8 ++++
 arch/arm/kernel/head-common.S                 |  5 ++
 arch/arm/kernel/head-nommu.S                  |  1 +
 arch/arm/kernel/head.S                        |  5 +-
 arch/arm/kernel/process.c                     |  8 ++--
 arch/arm/kernel/smp.c                         | 13 ++++-
 arch/arm/mm/proc-macros.S                     |  3 +-
 scripts/gcc-plugins/arm_ssp_per_task_plugin.c | 27 +++--------
 20 files changed, 174 insertions(+), 50 deletions(-)
 create mode 100644 arch/arm/include/asm/current.h

-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

             reply	other threads:[~2021-09-18  8:47 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-18  8:44 Ard Biesheuvel [this message]
2021-09-18  8:44 ` [PATCH v5 1/5] gcc-plugins: arm-ssp: Prepare for THREAD_INFO_IN_TASK support Ard Biesheuvel
2021-09-18 23:20   ` Linus Walleij
2021-09-18  8:44 ` [PATCH v5 2/5] ARM: smp: Pass task to secondary_start_kernel Ard Biesheuvel
2021-09-18 23:20   ` Linus Walleij
2021-09-18  8:44 ` [PATCH v5 3/5] ARM: smp: Free up the TLS register while running in the kernel Ard Biesheuvel
2021-09-21 15:20   ` Linus Walleij
2021-09-18  8:44 ` [PATCH v5 4/5] ARM: smp: Store current pointer in TPIDRURO register if available Ard Biesheuvel
2021-09-21 15:45   ` Linus Walleij
2021-09-21 15:59     ` Ard Biesheuvel
2021-09-18  8:44 ` [PATCH v5 5/5] ARM: smp: Enable THREAD_INFO_IN_TASK Ard Biesheuvel
2021-09-19 13:38   ` Amit Kachhap
2021-09-19 16:22     ` Ard Biesheuvel
2021-09-21 16:20   ` Linus Walleij
2021-09-19 13:44 ` [PATCH v5 0/5] ARM: support THREAD_INFO_IN_TASK Amit Kachhap
2021-09-19 16:23   ` Ard Biesheuvel

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=20210918084438.3288002-1-ardb@kernel.org \
    --to=ardb@kernel.org \
    --cc=arnd@arndb.de \
    --cc=keescook@chromium.org \
    --cc=keithpac@amazon.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    /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).