Skip to content

Commit dbae0a9

Browse files
committed
x86/cpu: Remove CONFIG_X86_SMAP and "nosmap"
Those were added as part of the SMAP enablement but SMAP is currently an integral part of kernel proper and there's no need to disable it anymore. Rip out that functionality. Leave --uaccess default on for objtool as this is what objtool should do by default anyway. If still needed - clearcpuid=smap. Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Lai Jiangshan <[email protected]> Reviewed-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent c949110 commit dbae0a9

File tree

9 files changed

+10
-71
lines changed

9 files changed

+10
-71
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3461,7 +3461,7 @@
34613461
noexec=on: enable non-executable mappings (default)
34623462
noexec=off: disable non-executable mappings
34633463

3464-
nosmap [X86,PPC]
3464+
nosmap [PPC]
34653465
Disable SMAP (Supervisor Mode Access Prevention)
34663466
even if it is supported by processor.
34673467

Documentation/x86/cpuinfo.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,8 @@ from #define X86_FEATURE_UMIP (16*32 + 2).
140140

141141
In addition, there exists a variety of custom command-line parameters that
142142
disable specific features. The list of parameters includes, but is not limited
143-
to, nofsgsbase, nosmap, and nosmep. 5-level paging can also be disabled using
144-
"no5lvl". SMAP and SMEP are disabled with the aforementioned parameters,
145-
respectively.
143+
to, nofsgsbase, and nosmep. 5-level paging can also be disabled using
144+
"no5lvl". SMEP is disabled with the aforementioned parameter.
146145

147146
e: The feature was known to be non-functional.
148147
----------------------------------------------

arch/x86/Kconfig

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,17 +1816,6 @@ config ARCH_RANDOM
18161816
If supported, this is a high bandwidth, cryptographically
18171817
secure hardware random number generator.
18181818

1819-
config X86_SMAP
1820-
def_bool y
1821-
prompt "Supervisor Mode Access Prevention" if EXPERT
1822-
help
1823-
Supervisor Mode Access Prevention (SMAP) is a security
1824-
feature in newer Intel processors. There is a small
1825-
performance cost if this enabled and turned on; there is
1826-
also a small increase in the kernel size if this is enabled.
1827-
1828-
If unsure, say Y.
1829-
18301819
config X86_UMIP
18311820
def_bool y
18321821
prompt "User Mode Instruction Prevention" if EXPERT

arch/x86/include/asm/disabled-features.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010
* cpu_feature_enabled().
1111
*/
1212

13-
#ifdef CONFIG_X86_SMAP
14-
# define DISABLE_SMAP 0
15-
#else
16-
# define DISABLE_SMAP (1<<(X86_FEATURE_SMAP & 31))
17-
#endif
18-
1913
#ifdef CONFIG_X86_UMIP
2014
# define DISABLE_UMIP 0
2115
#else
@@ -80,7 +74,7 @@
8074
#define DISABLED_MASK6 0
8175
#define DISABLED_MASK7 (DISABLE_PTI)
8276
#define DISABLED_MASK8 0
83-
#define DISABLED_MASK9 (DISABLE_SMAP|DISABLE_SGX)
77+
#define DISABLED_MASK9 (DISABLE_SGX)
8478
#define DISABLED_MASK10 0
8579
#define DISABLED_MASK11 0
8680
#define DISABLED_MASK12 0

arch/x86/include/asm/smap.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,14 @@
1919

2020
#ifdef __ASSEMBLY__
2121

22-
#ifdef CONFIG_X86_SMAP
23-
2422
#define ASM_CLAC \
2523
ALTERNATIVE "", __ASM_CLAC, X86_FEATURE_SMAP
2624

2725
#define ASM_STAC \
2826
ALTERNATIVE "", __ASM_STAC, X86_FEATURE_SMAP
2927

30-
#else /* CONFIG_X86_SMAP */
31-
32-
#define ASM_CLAC
33-
#define ASM_STAC
34-
35-
#endif /* CONFIG_X86_SMAP */
36-
3728
#else /* __ASSEMBLY__ */
3829

39-
#ifdef CONFIG_X86_SMAP
40-
4130
static __always_inline void clac(void)
4231
{
4332
/* Note: a barrier is implicit in alternative() */
@@ -76,19 +65,6 @@ static __always_inline void smap_restore(unsigned long flags)
7665
#define ASM_STAC \
7766
ALTERNATIVE("", __ASM_STAC, X86_FEATURE_SMAP)
7867

79-
#else /* CONFIG_X86_SMAP */
80-
81-
static inline void clac(void) { }
82-
static inline void stac(void) { }
83-
84-
static inline unsigned long smap_save(void) { return 0; }
85-
static inline void smap_restore(unsigned long flags) { }
86-
87-
#define ASM_CLAC
88-
#define ASM_STAC
89-
90-
#endif /* CONFIG_X86_SMAP */
91-
9268
#endif /* __ASSEMBLY__ */
9369

9470
#endif /* _ASM_X86_SMAP_H */

arch/x86/kernel/cpu/common.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -382,28 +382,15 @@ static __always_inline void setup_smep(struct cpuinfo_x86 *c)
382382
cr4_set_bits(X86_CR4_SMEP);
383383
}
384384

385-
static __init int setup_disable_smap(char *arg)
386-
{
387-
setup_clear_cpu_cap(X86_FEATURE_SMAP);
388-
return 1;
389-
}
390-
__setup("nosmap", setup_disable_smap);
391-
392385
static __always_inline void setup_smap(struct cpuinfo_x86 *c)
393386
{
394387
unsigned long eflags = native_save_fl();
395388

396389
/* This should have been cleared long ago */
397390
BUG_ON(eflags & X86_EFLAGS_AC);
398391

399-
if (cpu_has(c, X86_FEATURE_SMAP)) {
400-
#ifdef CONFIG_X86_SMAP
392+
if (cpu_has(c, X86_FEATURE_SMAP))
401393
cr4_set_bits(X86_CR4_SMAP);
402-
#else
403-
clear_cpu_cap(c, X86_FEATURE_SMAP);
404-
cr4_clear_bits(X86_CR4_SMAP);
405-
#endif
406-
}
407394
}
408395

409396
static __always_inline void setup_umip(struct cpuinfo_x86 *c)

scripts/Makefile.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ objtool_args = \
233233
$(if $(CONFIG_FRAME_POINTER),, --no-fp) \
234234
$(if $(CONFIG_GCOV_KERNEL)$(CONFIG_LTO_CLANG), --no-unreachable)\
235235
$(if $(CONFIG_RETPOLINE), --retpoline) \
236-
$(if $(CONFIG_X86_SMAP), --uaccess) \
236+
--uaccess \
237237
$(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \
238238
$(if $(CONFIG_SLS), --sls)
239239

scripts/link-vmlinux.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ objtool_link()
146146
if is_enabled CONFIG_RETPOLINE; then
147147
objtoolopt="${objtoolopt} --retpoline"
148148
fi
149-
if is_enabled CONFIG_X86_SMAP; then
150-
objtoolopt="${objtoolopt} --uaccess"
151-
fi
149+
150+
objtoolopt="${objtoolopt} --uaccess"
151+
152152
if is_enabled CONFIG_SLS; then
153153
objtoolopt="${objtoolopt} --sls"
154154
fi

tools/arch/x86/include/asm/disabled-features.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010
* cpu_feature_enabled().
1111
*/
1212

13-
#ifdef CONFIG_X86_SMAP
14-
# define DISABLE_SMAP 0
15-
#else
16-
# define DISABLE_SMAP (1<<(X86_FEATURE_SMAP & 31))
17-
#endif
18-
1913
#ifdef CONFIG_X86_UMIP
2014
# define DISABLE_UMIP 0
2115
#else
@@ -80,7 +74,7 @@
8074
#define DISABLED_MASK6 0
8175
#define DISABLED_MASK7 (DISABLE_PTI)
8276
#define DISABLED_MASK8 0
83-
#define DISABLED_MASK9 (DISABLE_SMAP|DISABLE_SGX)
77+
#define DISABLED_MASK9 (DISABLE_SGX)
8478
#define DISABLED_MASK10 0
8579
#define DISABLED_MASK11 0
8680
#define DISABLED_MASK12 0

0 commit comments

Comments
 (0)