Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5bb098df authored by Kees Cook's avatar Kees Cook Committed by Alexander Potapenko
Browse files

BACKPORT: security: Implement Clang's stack initialization

CONFIG_INIT_STACK_ALL turns on stack initialization based on
-ftrivial-auto-var-init in Clang builds, which has greater coverage
than CONFIG_GCC_PLUGINS_STRUCTLEAK_BYREF_ALL.

-ftrivial-auto-var-init Clang option provides trivial initializers for
uninitialized local variables, variable fields and padding.

It has three possible values:
  pattern - uninitialized locals are filled with a fixed pattern
    (mostly 0xAA on 64-bit platforms, see https://reviews.llvm.org/D54604


    for more details, but 0x000000AA for 32-bit pointers) likely to cause
    crashes when uninitialized value is used;
  zero (it's still debated whether this flag makes it to the official
    Clang release) - uninitialized locals are filled with zeroes;
  uninitialized (default) - uninitialized locals are left intact.

This patch uses only the "pattern" mode when CONFIG_INIT_STACK_ALL is
enabled.

Developers have the possibility to opt-out of this feature on a
per-variable basis by using __attribute__((uninitialized)), but such
use should be well justified in comments.

The Android 4.14 backport drops CC_HAS_AUTO_VAR_INIT, because Kconfig
is too old to support compiler feature checks.

Change-Id: I8e990ac3f299be9f6658a881a0518290cdda1157
Co-developed-by: default avatarAlexander Potapenko <glider@google.com>
Signed-off-by: default avatarAlexander Potapenko <glider@google.com>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Tested-by: default avatarAlexander Potapenko <glider@google.com>
Acked-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
(cherry picked from commit 709a972efb01efaeb97cad1adc87fe400119c8ab)
Bug: 133428616
Signed-off-by: default avatarAlexander Potapenko <glider@google.com>
parent 359b9ad4
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -765,6 +765,11 @@ KBUILD_CFLAGS += -fomit-frame-pointer
endif
endif

# Initialize all stack variables with a pattern, if desired.
ifdef CONFIG_INIT_STACK_ALL
KBUILD_CFLAGS	+= -ftrivial-auto-var-init=pattern
endif

KBUILD_CFLAGS   += $(call cc-option, -fno-var-tracking-assignments)

ifdef CONFIG_DEBUG_INFO
+9 −0
Original line number Diff line number Diff line
@@ -25,6 +25,15 @@ choice
		  classes of uninitialized stack variable exploits
		  and information exposures.

	config INIT_STACK_ALL
		bool "0xAA-init everything on the stack (strongest)"
		help
		  Initializes everything on the stack with a 0xAA
		  pattern. This is intended to eliminate all classes
		  of uninitialized stack variable exploits and information
		  exposures, even variables that were warned to have been
		  left uninitialized.

endchoice

endmenu