mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	stackleak: Split KSTACK_ERASE_CFLAGS from GCC_PLUGINS_CFLAGS
In preparation for Clang stack depth tracking for KSTACK_ERASE, split the stackleak-specific cflags out of GCC_PLUGINS_CFLAGS into KSTACK_ERASE_CFLAGS. Link: https://lore.kernel.org/r/20250717232519.2984886-3-kees@kernel.org Signed-off-by: Kees Cook <kees@kernel.org>
This commit is contained in:
		
							parent
							
								
									9ea1e8d28a
								
							
						
					
					
						commit
						76261fc7d1
					
				
					 8 changed files with 27 additions and 18 deletions
				
			
		| 
						 | 
					@ -13094,6 +13094,8 @@ F:	kernel/kstack_erase.c
 | 
				
			||||||
F:	lib/tests/randstruct_kunit.c
 | 
					F:	lib/tests/randstruct_kunit.c
 | 
				
			||||||
F:	lib/tests/usercopy_kunit.c
 | 
					F:	lib/tests/usercopy_kunit.c
 | 
				
			||||||
F:	mm/usercopy.c
 | 
					F:	mm/usercopy.c
 | 
				
			||||||
 | 
					F:	scripts/Makefile.kstack_erase
 | 
				
			||||||
 | 
					F:	scripts/Makefile.randstruct
 | 
				
			||||||
F:	security/Kconfig.hardening
 | 
					F:	security/Kconfig.hardening
 | 
				
			||||||
K:	\b(add|choose)_random_kstack_offset\b
 | 
					K:	\b(add|choose)_random_kstack_offset\b
 | 
				
			||||||
K:	\b__check_(object_size|heap_object)\b
 | 
					K:	\b__check_(object_size|heap_object)\b
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										1
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								Makefile
									
									
									
									
									
								
							| 
						 | 
					@ -1086,6 +1086,7 @@ include-$(CONFIG_KMSAN)		+= scripts/Makefile.kmsan
 | 
				
			||||||
include-$(CONFIG_UBSAN)		+= scripts/Makefile.ubsan
 | 
					include-$(CONFIG_UBSAN)		+= scripts/Makefile.ubsan
 | 
				
			||||||
include-$(CONFIG_KCOV)		+= scripts/Makefile.kcov
 | 
					include-$(CONFIG_KCOV)		+= scripts/Makefile.kcov
 | 
				
			||||||
include-$(CONFIG_RANDSTRUCT)	+= scripts/Makefile.randstruct
 | 
					include-$(CONFIG_RANDSTRUCT)	+= scripts/Makefile.randstruct
 | 
				
			||||||
 | 
					include-$(CONFIG_KSTACK_ERASE)	+= scripts/Makefile.kstack_erase
 | 
				
			||||||
include-$(CONFIG_AUTOFDO_CLANG)	+= scripts/Makefile.autofdo
 | 
					include-$(CONFIG_AUTOFDO_CLANG)	+= scripts/Makefile.autofdo
 | 
				
			||||||
include-$(CONFIG_PROPELLER_CLANG)	+= scripts/Makefile.propeller
 | 
					include-$(CONFIG_PROPELLER_CLANG)	+= scripts/Makefile.propeller
 | 
				
			||||||
include-$(CONFIG_GCC_PLUGINS)	+= scripts/Makefile.gcc-plugins
 | 
					include-$(CONFIG_GCC_PLUGINS)	+= scripts/Makefile.gcc-plugins
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,7 +26,7 @@ CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
 | 
				
			||||||
CFLAGS_REMOVE_vdso.o = -pg
 | 
					CFLAGS_REMOVE_vdso.o = -pg
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Force -O2 to avoid libgcc dependencies
 | 
					# Force -O2 to avoid libgcc dependencies
 | 
				
			||||||
CFLAGS_REMOVE_vgettimeofday.o = -pg -Os $(RANDSTRUCT_CFLAGS) $(GCC_PLUGINS_CFLAGS)
 | 
					CFLAGS_REMOVE_vgettimeofday.o = -pg -Os $(RANDSTRUCT_CFLAGS) $(KSTACK_ERASE_CFLAGS) $(GCC_PLUGINS_CFLAGS)
 | 
				
			||||||
ifeq ($(c-gettimeofday-y),)
 | 
					ifeq ($(c-gettimeofday-y),)
 | 
				
			||||||
CFLAGS_vgettimeofday.o = -O2
 | 
					CFLAGS_vgettimeofday.o = -O2
 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -36,7 +36,8 @@ ccflags-y += -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO
 | 
				
			||||||
# -Wmissing-prototypes and -Wmissing-declarations are removed from
 | 
					# -Wmissing-prototypes and -Wmissing-declarations are removed from
 | 
				
			||||||
# the CFLAGS to make possible to build the kernel with CONFIG_WERROR enabled.
 | 
					# the CFLAGS to make possible to build the kernel with CONFIG_WERROR enabled.
 | 
				
			||||||
CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \
 | 
					CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \
 | 
				
			||||||
			$(RANDSTRUCT_CFLAGS) $(GCC_PLUGINS_CFLAGS) \
 | 
								$(RANDSTRUCT_CFLAGS) $(KSTACK_ERASE_CFLAGS) \
 | 
				
			||||||
 | 
								$(GCC_PLUGINS_CFLAGS) \
 | 
				
			||||||
			$(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \
 | 
								$(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \
 | 
				
			||||||
			-Wmissing-prototypes -Wmissing-declarations
 | 
								-Wmissing-prototypes -Wmissing-declarations
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -48,7 +48,7 @@ CFL := $(PROFILING) -mcmodel=medlow -fPIC -O2 -fasynchronous-unwind-tables -m64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SPARC_REG_CFLAGS = -ffixed-g4 -ffixed-g5 $(call cc-option,-fcall-used-g5) $(call cc-option,-fcall-used-g7)
 | 
					SPARC_REG_CFLAGS = -ffixed-g4 -ffixed-g5 $(call cc-option,-fcall-used-g5) $(call cc-option,-fcall-used-g7)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$(vobjs): KBUILD_CFLAGS := $(filter-out $(RANDSTRUCT_CFLAGS) $(GCC_PLUGINS_CFLAGS) $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS)) $(CFL)
 | 
					$(vobjs): KBUILD_CFLAGS := $(filter-out $(RANDSTRUCT_CFLAGS) $(KSTACK_ERASE_CFLAGS) $(GCC_PLUGINS_CFLAGS) $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS)) $(CFL)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
# vDSO code runs in userspace and -pg doesn't help with profiling anyway.
 | 
					# vDSO code runs in userspace and -pg doesn't help with profiling anyway.
 | 
				
			||||||
| 
						 | 
					@ -79,6 +79,7 @@ KBUILD_CFLAGS_32 := $(filter-out -m64,$(KBUILD_CFLAGS))
 | 
				
			||||||
KBUILD_CFLAGS_32 := $(filter-out -mcmodel=medlow,$(KBUILD_CFLAGS_32))
 | 
					KBUILD_CFLAGS_32 := $(filter-out -mcmodel=medlow,$(KBUILD_CFLAGS_32))
 | 
				
			||||||
KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32))
 | 
					KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32))
 | 
				
			||||||
KBUILD_CFLAGS_32 := $(filter-out $(RANDSTRUCT_CFLAGS),$(KBUILD_CFLAGS_32))
 | 
					KBUILD_CFLAGS_32 := $(filter-out $(RANDSTRUCT_CFLAGS),$(KBUILD_CFLAGS_32))
 | 
				
			||||||
 | 
					KBUILD_CFLAGS_32 := $(filter-out $(KSTACK_ERASE_CFLAGS),$(KBUILD_CFLAGS_32))
 | 
				
			||||||
KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32))
 | 
					KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32))
 | 
				
			||||||
KBUILD_CFLAGS_32 := $(filter-out $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS_32))
 | 
					KBUILD_CFLAGS_32 := $(filter-out $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS_32))
 | 
				
			||||||
KBUILD_CFLAGS_32 += -m32 -msoft-float -fpic
 | 
					KBUILD_CFLAGS_32 += -m32 -msoft-float -fpic
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -62,7 +62,7 @@ ifneq ($(RETPOLINE_VDSO_CFLAGS),)
 | 
				
			||||||
endif
 | 
					endif
 | 
				
			||||||
endif
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$(vobjs): KBUILD_CFLAGS := $(filter-out $(PADDING_CFLAGS) $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) $(RANDSTRUCT_CFLAGS) $(GCC_PLUGINS_CFLAGS) $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS)) $(CFL)
 | 
					$(vobjs): KBUILD_CFLAGS := $(filter-out $(PADDING_CFLAGS) $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) $(RANDSTRUCT_CFLAGS) $(KSTACK_ERASE_CFLAGS) $(GCC_PLUGINS_CFLAGS) $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS)) $(CFL)
 | 
				
			||||||
$(vobjs): KBUILD_AFLAGS += -DBUILD_VDSO
 | 
					$(vobjs): KBUILD_AFLAGS += -DBUILD_VDSO
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
| 
						 | 
					@ -123,6 +123,7 @@ KBUILD_CFLAGS_32 := $(filter-out -mcmodel=kernel,$(KBUILD_CFLAGS_32))
 | 
				
			||||||
KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32))
 | 
					KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32))
 | 
				
			||||||
KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32))
 | 
					KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32))
 | 
				
			||||||
KBUILD_CFLAGS_32 := $(filter-out $(RANDSTRUCT_CFLAGS),$(KBUILD_CFLAGS_32))
 | 
					KBUILD_CFLAGS_32 := $(filter-out $(RANDSTRUCT_CFLAGS),$(KBUILD_CFLAGS_32))
 | 
				
			||||||
 | 
					KBUILD_CFLAGS_32 := $(filter-out $(KSTACK_ERASE_CFLAGS),$(KBUILD_CFLAGS_32))
 | 
				
			||||||
KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32))
 | 
					KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32))
 | 
				
			||||||
KBUILD_CFLAGS_32 := $(filter-out $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS_32))
 | 
					KBUILD_CFLAGS_32 := $(filter-out $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS_32))
 | 
				
			||||||
KBUILD_CFLAGS_32 := $(filter-out $(CC_FLAGS_LTO),$(KBUILD_CFLAGS_32))
 | 
					KBUILD_CFLAGS_32 := $(filter-out $(CC_FLAGS_LTO),$(KBUILD_CFLAGS_32))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,20 +8,6 @@ ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY
 | 
				
			||||||
endif
 | 
					endif
 | 
				
			||||||
export DISABLE_LATENT_ENTROPY_PLUGIN
 | 
					export DISABLE_LATENT_ENTROPY_PLUGIN
 | 
				
			||||||
 | 
					
 | 
				
			||||||
gcc-plugin-$(CONFIG_GCC_PLUGIN_STACKLEAK)	+= stackleak_plugin.so
 | 
					 | 
				
			||||||
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK)		\
 | 
					 | 
				
			||||||
		+= -DSTACKLEAK_PLUGIN
 | 
					 | 
				
			||||||
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK)		\
 | 
					 | 
				
			||||||
		+= -fplugin-arg-stackleak_plugin-track-min-size=$(CONFIG_KSTACK_ERASE_TRACK_MIN_SIZE)
 | 
					 | 
				
			||||||
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK)		\
 | 
					 | 
				
			||||||
		+= -fplugin-arg-stackleak_plugin-arch=$(SRCARCH)
 | 
					 | 
				
			||||||
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK_VERBOSE)	\
 | 
					 | 
				
			||||||
		+= -fplugin-arg-stackleak_plugin-verbose
 | 
					 | 
				
			||||||
ifdef CONFIG_GCC_PLUGIN_STACKLEAK
 | 
					 | 
				
			||||||
    DISABLE_KSTACK_ERASE += -fplugin-arg-stackleak_plugin-disable
 | 
					 | 
				
			||||||
endif
 | 
					 | 
				
			||||||
export DISABLE_KSTACK_ERASE
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# All the plugin CFLAGS are collected here in case a build target needs to
 | 
					# All the plugin CFLAGS are collected here in case a build target needs to
 | 
				
			||||||
# filter them out of the KBUILD_CFLAGS.
 | 
					# filter them out of the KBUILD_CFLAGS.
 | 
				
			||||||
GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y)) -DGCC_PLUGINS
 | 
					GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y)) -DGCC_PLUGINS
 | 
				
			||||||
| 
						 | 
					@ -34,6 +20,8 @@ KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
 | 
				
			||||||
# be included in GCC_PLUGIN so they can get built.
 | 
					# be included in GCC_PLUGIN so they can get built.
 | 
				
			||||||
gcc-plugin-external-$(CONFIG_GCC_PLUGIN_RANDSTRUCT)		\
 | 
					gcc-plugin-external-$(CONFIG_GCC_PLUGIN_RANDSTRUCT)		\
 | 
				
			||||||
	+= randomize_layout_plugin.so
 | 
						+= randomize_layout_plugin.so
 | 
				
			||||||
 | 
					gcc-plugin-external-$(CONFIG_GCC_PLUGIN_STACKLEAK)		\
 | 
				
			||||||
 | 
						+= stackleak_plugin.so
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# All enabled GCC plugins are collected here for building in
 | 
					# All enabled GCC plugins are collected here for building in
 | 
				
			||||||
# scripts/gcc-scripts/Makefile.
 | 
					# scripts/gcc-scripts/Makefile.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										15
									
								
								scripts/Makefile.kstack_erase
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								scripts/Makefile.kstack_erase
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,15 @@
 | 
				
			||||||
 | 
					# SPDX-License-Identifier: GPL-2.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ifdef CONFIG_GCC_PLUGIN_STACKLEAK
 | 
				
			||||||
 | 
					kstack-erase-cflags-y += -fplugin=$(objtree)/scripts/gcc-plugins/stackleak_plugin.so
 | 
				
			||||||
 | 
					kstack-erase-cflags-y += -fplugin-arg-stackleak_plugin-track-min-size=$(CONFIG_KSTACK_ERASE_TRACK_MIN_SIZE)
 | 
				
			||||||
 | 
					kstack-erase-cflags-y += -fplugin-arg-stackleak_plugin-arch=$(SRCARCH)
 | 
				
			||||||
 | 
					kstack-erase-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK_VERBOSE) += -fplugin-arg-stackleak_plugin-verbose
 | 
				
			||||||
 | 
					DISABLE_KSTACK_ERASE := -fplugin-arg-stackleak_plugin-disable
 | 
				
			||||||
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					KSTACK_ERASE_CFLAGS   := $(kstack-erase-cflags-y)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export STACKLEAK_CFLAGS DISABLE_KSTACK_ERASE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					KBUILD_CFLAGS += $(KSTACK_ERASE_CFLAGS)
 | 
				
			||||||
		Loading…
	
		Reference in a new issue