Skip to content

Commit 8960452

Browse files
ardbiesheuvelRussell King
authored andcommitted
ARM: 8961/2: Fix Kbuild issue caused by per-task stack protector GCC plugin
When using plugins, GCC requires that the -fplugin= options precedes any of its plugin arguments appearing on the command line as well. This is usually not a concern, but as it turns out, this requirement is causing some issues with ARM's per-task stack protector plugin and Kbuild's implementation of $(cc-option). When the per-task stack protector plugin is enabled, and we tweak the implementation of cc-option not to pipe the stderr output of GCC to /dev/null, the following output is generated when GCC is executed in the context of cc-option: cc1: error: plugin arm_ssp_per_task_plugin should be specified before \ -fplugin-arg-arm_ssp_per_task_plugin-tso=1 in the command line cc1: error: plugin arm_ssp_per_task_plugin should be specified before \ -fplugin-arg-arm_ssp_per_task_plugin-offset=24 in the command line These errors will cause any option passed to cc-option to be treated as unsupported, which is obviously incorrect. The cause of this issue is the fact that the -fplugin= argument is added to GCC_PLUGINS_CFLAGS, whereas the arguments above are added to KBUILD_CFLAGS, and the contents of the former get filtered out of the latter before being passed to the GCC running the cc-option test, and so the -fplugin= option does not appear at all on the GCC command line. Adding the arguments to GCC_PLUGINS_CFLAGS instead of KBUILD_CFLAGS would be the correct approach here, if it weren't for the fact that we are using $(eval) to defer the moment that they are added until after asm-offsets.h is generated, which is after the point where the contents of GCC_PLUGINS_CFLAGS are added to KBUILD_CFLAGS. So instead, we have to add our plugin arguments to both. For similar reasons, we cannot append DISABLE_ARM_SSP_PER_TASK_PLUGIN to KBUILD_CFLAGS, as it will be passed to GCC when executing in the context of cc-option, whereas the other plugin arguments will have been filtered out, resulting in a similar error and false negative result as above. So add it to ccflags-y instead. Fixes: 189af46 ("ARM: smp: add support for per-task stack canaries") Reported-by: Merlijn Wajer <[email protected]> Tested-by: Tony Lindgren <[email protected]> Acked-by: Kees Cook <[email protected]> Reviewed-by: Masahiro Yamada <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Russell King <[email protected]>
1 parent f87b1c4 commit 8960452

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

arch/arm/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,15 @@ endif
307307
ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
308308
prepare: stack_protector_prepare
309309
stack_protector_prepare: prepare0
310-
$(eval KBUILD_CFLAGS += \
310+
$(eval SSP_PLUGIN_CFLAGS := \
311311
-fplugin-arg-arm_ssp_per_task_plugin-tso=$(shell \
312312
awk '{if ($$2 == "THREAD_SZ_ORDER") print $$3;}'\
313313
include/generated/asm-offsets.h) \
314314
-fplugin-arg-arm_ssp_per_task_plugin-offset=$(shell \
315315
awk '{if ($$2 == "TI_STACK_CANARY") print $$3;}'\
316316
include/generated/asm-offsets.h))
317+
$(eval KBUILD_CFLAGS += $(SSP_PLUGIN_CFLAGS))
318+
$(eval GCC_PLUGINS_CFLAGS += $(SSP_PLUGIN_CFLAGS))
317319
endif
318320

319321
all: $(notdir $(KBUILD_IMAGE))

arch/arm/boot/compressed/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ clean-files += piggy_data lib1funcs.S ashldi3.S bswapsdi2.S \
101101
$(libfdt) $(libfdt_hdrs) hyp-stub.S
102102

103103
KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
104-
KBUILD_CFLAGS += $(DISABLE_ARM_SSP_PER_TASK_PLUGIN)
105104

106105
ifeq ($(CONFIG_FUNCTION_TRACER),y)
107106
ORIG_CFLAGS := $(KBUILD_CFLAGS)
@@ -117,7 +116,8 @@ CFLAGS_fdt_ro.o := $(nossp-flags-y)
117116
CFLAGS_fdt_rw.o := $(nossp-flags-y)
118117
CFLAGS_fdt_wip.o := $(nossp-flags-y)
119118

120-
ccflags-y := -fpic $(call cc-option,-mno-single-pic-base,) -fno-builtin -I$(obj)
119+
ccflags-y := -fpic $(call cc-option,-mno-single-pic-base,) -fno-builtin \
120+
-I$(obj) $(DISABLE_ARM_SSP_PER_TASK_PLUGIN)
121121
asflags-y := -DZIMAGE
122122

123123
# Supply kernel BSS size to the decompressor via a linker symbol.

0 commit comments

Comments
 (0)