llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.33k stars 12.13k forks source link

Implement -fzero-call-used-regs #37228

Closed nickdesaulniers closed 2 years ago

nickdesaulniers commented 6 years ago
Bugzilla Link 37880
Version trunk
OS Linux
Blocks llvm/llvm-project#4440
CC @isanbard,@jyknight,@kees,@lalozano,@m-gupta,@stephenhines

Extended Description

GCC has added ways of specifying that certain registers should be zero'd upon function return. I believe this is to help cut down on gadgets used in ROP chains. Is this something that could be added in Clang?

https://github.com/clearlinux-pkgs/gcc/blob/master/zero-regs-gcc8.patch

nickdesaulniers commented 3 years ago

mentioned in issue llvm/llvm-bugzilla-archive#49902

edwintorok commented 3 years ago

mentioned in issue llvm/llvm-project#4440

kees commented 3 years ago

This feature exists in GCC since version 11:

-fzero-call-used-regs=[skip|used-gpr|all-gpr|used|all]

The kernel supports the use of =used-gpr since v5.15 as CONFIG_ZERO_CALL_USED_REGS:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/security/Kconfig.hardening?h=v5.15-rc1#n232

nickdesaulniers commented 3 years ago

Bug llvm/llvm-bugzilla-archive#49902 has been marked as a duplicate of this bug.

nickdesaulniers commented 4 years ago

Bill's RFC: https://lists.llvm.org/pipermail/llvm-dev/2020-August/144082.html

isanbard commented 4 years ago

Here's a better link: https://gcc.gnu.org/legacy-ml/gcc-patches/2018-10/msg02079.html

nickdesaulniers commented 2 years ago

initial support for this will ship for x86_64 in clang-15. We'll pursue enabling more backends, but it's a fair amount of work per arch to get this working. Should be easier now that clang supports the flags and some support is arch agnostic.

https://reviews.llvm.org/rGdeaf22bc0e306bc44c70d2503e9364b5ed312c49