Skip to content

implement TLS register based stack canary for ARM

Ard Biesheuvel linux-hardening 6 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v6 Latest1 patch 3 repliesIn review
  2. v51 patch 6 repliesSuperseded
  3. v41 patch 6 repliesSuperseded
Earlier versions · 3
VersionPostedPatchesRepliesStatus
v31 patch1 replySuperseded
v2 RFC1 patch1 replySuperseded
v1 RFC1 patch2 repliesSuperseded

Changes in v6 from the cover letter

- rebase onto latest changes, including .c -> .cc rename
- ensure that tests execute only on targets that can support them

Patches in v6 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/1Add support for TLS register based stack protector canary accessgcc/config/arm/arm-opts.h gcc/config/arm/arm-protos.h gcc/config/arm/arm.cc +5 more+184 -23 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v6 yet.

Read the v6 thread

Cover letter [PATCH v6 0/1] implement TLS register based stack canary for ARM

Bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102352

In the Linux kernel, user processes calling into the kernel are essentially threads running in the same address space, of a program that never terminates. This means that using a global variable for the stack protector canary value is problematic on SMP systems, as we can never change it unless we reboot the system. (Processes that sleep for any reason will do so on a call into the kernel, which means that there will always be live kernel stack frames carrying copies of the canary taken when the function was entered)

AArch64 implements -mstack-protector-guard=sysreg for this purpose, as this permits the kernel to use different memory addresses for the stack canary for each CPU, and context switch the chosen system register with the rest of the process, allowing each process to use its own unique value for the stack canary.

This patch implements something similar, but for the 32-bit ARM kernel, which will start using the user space TLS register TPIDRURO to index per-process metadata while running in the kernel. This means we can just add an offset to TPIDRURO to obtain the address from which to load the canary value.

Changes since v5:
- rebase onto latest changes, including .c -> .cc rename
- ensure that tests execute only on targets that can support them

Changes since v4:
- add a couple of test cases
- incorporate feedback received from Qing and Kyrylo

Changes since v3:
- force a reload of the TLS register before performing the stack protector check, so that we never rely on the stack for the address of the canary
Changes since v2:
- fix the template for stack_protect_test_tls so it correctly conveys the fact that it sets the Z flag

Cc Keith Packard <[email protected]>
Cc Qing Zhao <[email protected]>
Cc Richard Sandiford <[email protected]>
Cc Kyrylo Tkachov <[email protected]>
Cc Richard Earnshaw <[email protected]>

Ard Biesheuvel (1):
[ARM] Add support for TLS register based stack protector canary access

 gcc/config/arm/arm-opts.h                        |  6 ++
 gcc/config/arm/arm-protos.h                      |  2 +
 gcc/config/arm/arm.cc                            | 55 +++++++++++++++
 gcc/config/arm/arm.md                            | 71 +++++++++++++++++++-
 gcc/config/arm/arm.opt                           | 22 ++++++
 gcc/doc/invoke.texi                              | 11 +++
 gcc/testsuite/gcc.target/arm/stack-protector-7.c | 12 ++++
 gcc/testsuite/gcc.target/arm/stack-protector-8.c |  7 ++
 8 files changed, 184 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/arm/stack-protector-7.c
 create mode 100644 gcc/testsuite/gcc.target/arm/stack-protector-8.c
Signature · 1 line
2.30.2