]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/x86-mm-mem_encrypt-disable-all-instrumentation-for-e.patch
Linux 5.0.19
[thirdparty/kernel/stable-queue.git] / queue-4.19 / x86-mm-mem_encrypt-disable-all-instrumentation-for-e.patch
1 From 47337ab9b2cf39e134f41a50608957307301ec07 Mon Sep 17 00:00:00 2001
2 From: Gary Hook <Gary.Hook@amd.com>
3 Date: Mon, 29 Apr 2019 22:22:58 +0000
4 Subject: x86/mm/mem_encrypt: Disable all instrumentation for early SME setup
5
6 [ Upstream commit b51ce3744f115850166f3d6c292b9c8cb849ad4f ]
7
8 Enablement of AMD's Secure Memory Encryption feature is determined very
9 early after start_kernel() is entered. Part of this procedure involves
10 scanning the command line for the parameter 'mem_encrypt'.
11
12 To determine intended state, the function sme_enable() uses library
13 functions cmdline_find_option() and strncmp(). Their use occurs early
14 enough such that it cannot be assumed that any instrumentation subsystem
15 is initialized.
16
17 For example, making calls to a KASAN-instrumented function before KASAN
18 is set up will result in the use of uninitialized memory and a boot
19 failure.
20
21 When AMD's SME support is enabled, conditionally disable instrumentation
22 of these dependent functions in lib/string.c and arch/x86/lib/cmdline.c.
23
24 [ bp: Get rid of intermediary nostackp var and cleanup whitespace. ]
25
26 Fixes: aca20d546214 ("x86/mm: Add support to make use of Secure Memory Encryption")
27 Reported-by: Li RongQing <lirongqing@baidu.com>
28 Signed-off-by: Gary R Hook <gary.hook@amd.com>
29 Signed-off-by: Borislav Petkov <bp@suse.de>
30 Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
31 Cc: Andrew Morton <akpm@linux-foundation.org>
32 Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
33 Cc: Boris Brezillon <bbrezillon@kernel.org>
34 Cc: Coly Li <colyli@suse.de>
35 Cc: "dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>
36 Cc: "H. Peter Anvin" <hpa@zytor.com>
37 Cc: Ingo Molnar <mingo@redhat.com>
38 Cc: Kees Cook <keescook@chromium.org>
39 Cc: Kent Overstreet <kent.overstreet@gmail.com>
40 Cc: "luto@kernel.org" <luto@kernel.org>
41 Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
42 Cc: Matthew Wilcox <willy@infradead.org>
43 Cc: "mingo@redhat.com" <mingo@redhat.com>
44 Cc: "peterz@infradead.org" <peterz@infradead.org>
45 Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
46 Cc: Thomas Gleixner <tglx@linutronix.de>
47 Cc: x86-ml <x86@kernel.org>
48 Link: https://lkml.kernel.org/r/155657657552.7116.18363762932464011367.stgit@sosrh3.amd.com
49 Signed-off-by: Sasha Levin <sashal@kernel.org>
50 ---
51 arch/x86/lib/Makefile | 12 ++++++++++++
52 lib/Makefile | 11 +++++++++++
53 2 files changed, 23 insertions(+)
54
55 diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile
56 index 25a972c61b0ae..3c19d60316a88 100644
57 --- a/arch/x86/lib/Makefile
58 +++ b/arch/x86/lib/Makefile
59 @@ -6,6 +6,18 @@
60 # Produces uninteresting flaky coverage.
61 KCOV_INSTRUMENT_delay.o := n
62
63 +# Early boot use of cmdline; don't instrument it
64 +ifdef CONFIG_AMD_MEM_ENCRYPT
65 +KCOV_INSTRUMENT_cmdline.o := n
66 +KASAN_SANITIZE_cmdline.o := n
67 +
68 +ifdef CONFIG_FUNCTION_TRACER
69 +CFLAGS_REMOVE_cmdline.o = -pg
70 +endif
71 +
72 +CFLAGS_cmdline.o := $(call cc-option, -fno-stack-protector)
73 +endif
74 +
75 inat_tables_script = $(srctree)/arch/x86/tools/gen-insn-attr-x86.awk
76 inat_tables_maps = $(srctree)/arch/x86/lib/x86-opcode-map.txt
77 quiet_cmd_inat_tables = GEN $@
78 diff --git a/lib/Makefile b/lib/Makefile
79 index 4238764468109..0ab808318202c 100644
80 --- a/lib/Makefile
81 +++ b/lib/Makefile
82 @@ -17,6 +17,17 @@ KCOV_INSTRUMENT_list_debug.o := n
83 KCOV_INSTRUMENT_debugobjects.o := n
84 KCOV_INSTRUMENT_dynamic_debug.o := n
85
86 +# Early boot use of cmdline, don't instrument it
87 +ifdef CONFIG_AMD_MEM_ENCRYPT
88 +KASAN_SANITIZE_string.o := n
89 +
90 +ifdef CONFIG_FUNCTION_TRACER
91 +CFLAGS_REMOVE_string.o = -pg
92 +endif
93 +
94 +CFLAGS_string.o := $(call cc-option, -fno-stack-protector)
95 +endif
96 +
97 lib-y := ctype.o string.o vsprintf.o cmdline.o \
98 rbtree.o radix-tree.o timerqueue.o\
99 idr.o int_sqrt.o extable.o \
100 --
101 2.20.1
102