Skip to contentSkip to conversation

x86/mm/mem_encrypt: Disable all instrumentation for SME early files

PATCH New Hook, Gary 2 participants 2 messages Apr 29, 2019 – Apr 30, 2019

Subsystems (2)
lore
Share & tools
lore

Hook, Gary

author
#0 lore raw

PATCH 1/1 x86/mm/mem_encrypt: Disable all instrumentation for SME early files

Enablement of AMD's Secure Memory Encryption feature is determined very early after start_kernel() is entered. Part of this procedure involves scanning the command line for the parameter 'mem_encrypt'.

To determine intended state, the function sme_enable() uses library functions cmdline_find_option() and strncmp(). Their use occurs early enough such that we can't assume that any instrumentation subsystem is initialized. For example, making calls to a KASAN-instrumented function before KASAN is set up will result in the use of uninitialized memory and a boot failure.

When AMD's SME support is enabled, conditionally disable instrumentation of these dependent functions in lib/string.c and arch/x86/lib/cmdline.c.

Fixes aca20d546214 ("x86/mm: Add support to make use of Secure Memory Encryption")
---
 arch/x86/lib/Makefile |   16 ++++++++++++++++
 lib/Makefile          |   14 ++++++++++++++
 2 files changed, 30 insertions(+)
arch/x86/lib/Makefile +16 -0
index 140e61843a07..b5b932124280 100644
@@ -6,6 +6,22 @@
 # Produces uninteresting flaky coverage.
 KCOV_INSTRUMENT_delay.o	:= n
 
+ifdef CONFIG_AMD_MEM_ENCRYPT
+#
+# Early boot use of cmdline; don't instrument it
+#
+KCOV_INSTRUMENT_cmdline.o              := n
+
+KASAN_SANITIZE_cmdline.o               := n
+
+ifdef CONFIG_FUNCTION_TRACER
+CFLAGS_REMOVE_cmdline.o                        = -pg
+endif
+
+nostackp := $(call cc-option, -fno-stack-protector)
+CFLAGS_cmdline.o               := $(nostackp)
+endif
+
 inat_tables_script = $(srctree)/arch/x86/tools/gen-insn-attr-x86.awk
 inat_tables_maps = $(srctree)/arch/x86/lib/x86-opcode-map.txt
 quiet_cmd_inat_tables = GEN     $@
lib/Makefile +14 -0
index 3b08673e8881..07d71662f6b2 100644
@@ -17,6 +17,20 @@ KCOV_INSTRUMENT_list_debug.o := n
 KCOV_INSTRUMENT_debugobjects.o := n
 KCOV_INSTRUMENT_dynamic_debug.o := n
 
+ifdef CONFIG_AMD_MEM_ENCRYPT
+#
+# Early boot use of cmdline, don't instrument it
+#
+KASAN_SANITIZE_string.o                := n
+
+ifdef CONFIG_FUNCTION_TRACER
+CFLAGS_REMOVE_string.o         = -pg
+endif
+
+nostackp := $(call cc-option, -fno-stack-protector)
+CFLAGS_string.o                        := $(nostackp)
+endif
+
 lib-y := ctype.o string.o vsprintf.o cmdline.o \
 	 rbtree.o radix-tree.o timerqueue.o xarray.o \
 	 idr.o int_sqrt.o extable.o \
#1 lore raw

[tip:x86/urgent] x86/mm/mem_encrypt: Disable all instrumentation for early SME setup

x86/mm/mem_encrypt: Disable all instrumentation for early SME setup
Commit-ID:  b51ce3744f115850166f3d6c292b9c8cb849ad4f
Gitweb:     https://git.kernel.org/tip/b51ce3744f115850166f3d6c292b9c8cb849ad4f
Author:     Gary Hook <[email protected]>
AuthorDate: Mon, 29 Apr 2019 22:22:58 +0000
Committer:  Borislav Petkov <[email protected]>
CommitDate: Tue, 30 Apr 2019 17:59:08 +0200

x86/mm/mem_encrypt: Disable all instrumentation for early SME setup

Enablement of AMD's Secure Memory Encryption feature is determined very early after start_kernel() is entered. Part of this procedure involves scanning the command line for the parameter 'mem_encrypt'.

To determine intended state, the function sme_enable() uses library functions cmdline_find_option() and strncmp(). Their use occurs early enough such that it cannot be assumed that any instrumentation subsystem is initialized.

For example, making calls to a KASAN-instrumented function before KASAN is set up will result in the use of uninitialized memory and a boot failure.

When AMD's SME support is enabled, conditionally disable instrumentation of these dependent functions in lib/string.c and arch/x86/lib/cmdline.c.

[ bp: Get rid of intermediary nostackp var and cleanup whitespace. ]

Fixes aca20d546214 ("x86/mm: Add support to make use of Secure Memory Encryption")
Cc Alexander Shishkin <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Boris Brezillon <[email protected]>
Cc Coly Li <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Kees Cook <[email protected]>
Cc Kent Overstreet <[email protected]>
Cc Masahiro Yamada <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Sebastian Andrzej Siewior <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc x86-ml <[email protected]>
---
 arch/x86/lib/Makefile | 12 ++++++++++++
 lib/Makefile          | 11 +++++++++++
 2 files changed, 23 insertions(+)
arch/x86/lib/Makefile +12 -0
index 140e61843a07..3cb3af51ec89 100644
@@ -6,6 +6,18 @@
 # Produces uninteresting flaky coverage.
 KCOV_INSTRUMENT_delay.o	:= n
 
+# Early boot use of cmdline; don't instrument it
+ifdef CONFIG_AMD_MEM_ENCRYPT
+KCOV_INSTRUMENT_cmdline.o := n
+KASAN_SANITIZE_cmdline.o  := n
+
+ifdef CONFIG_FUNCTION_TRACER
+CFLAGS_REMOVE_cmdline.o = -pg
+endif
+
+CFLAGS_cmdline.o := $(call cc-option, -fno-stack-protector)
+endif
+
 inat_tables_script = $(srctree)/arch/x86/tools/gen-insn-attr-x86.awk
 inat_tables_maps = $(srctree)/arch/x86/lib/x86-opcode-map.txt
 quiet_cmd_inat_tables = GEN     $@
lib/Makefile +11 -0
index 3b08673e8881..18c2be516ab4 100644
@@ -17,6 +17,17 @@ KCOV_INSTRUMENT_list_debug.o := n
 KCOV_INSTRUMENT_debugobjects.o := n
 KCOV_INSTRUMENT_dynamic_debug.o := n
 
+# Early boot use of cmdline, don't instrument it
+ifdef CONFIG_AMD_MEM_ENCRYPT
+KASAN_SANITIZE_string.o := n
+
+ifdef CONFIG_FUNCTION_TRACER
+CFLAGS_REMOVE_string.o = -pg
+endif
+
+CFLAGS_string.o := $(call cc-option, -fno-stack-protector)
+endif
+
 lib-y := ctype.o string.o vsprintf.o cmdline.o \
 	 rbtree.o radix-tree.o timerqueue.o xarray.o \
 	 idr.o int_sqrt.o extable.o \