Skip to contentSkip to conversation

riscv: Disable STACKPROTECTOR_PER_TASK if GCC_PLUGIN_RANDSTRUCT is enabled

PATCH In review Guenter Roeck 2 participants 5 messages Jul 6, 2021 – Aug 4, 2021 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv: Disable STACKPROTECTOR_PER_TASK if GCC_PLUGIN_RANDSTRUCT is enabled

riscv uses the value of TSK_STACK_CANARY to set stack-protector-guard-offset. With GCC_PLUGIN_RANDSTRUCT enabled, that value is non-deterministic, and with riscv:allmodconfig often results in build errors such as

cc1: error: '8120' is not a valid offset in '-mstack-protector-guard-offset='

Enable STACKPROTECTOR_PER_TASK only if GCC_PLUGIN_RANDSTRUCT is disabled to fix the problem.

Fixes fea2fed201ee5 ("riscv: Enable per-task stack canaries")
Cc Guo Ren <[email protected]>
---
 arch/riscv/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/Kconfig +1 -0
index 469a70bd8da6..3afb84fa2190 100644
@@ -486,6 +486,7 @@ config CC_HAVE_STACKPROTECTOR_TLS
 
 config STACKPROTECTOR_PER_TASK
 	def_bool y
+	depends on !GCC_PLUGIN_RANDSTRUCT
 	depends on STACKPROTECTOR && CC_HAVE_STACKPROTECTOR_TLS
 
 config PHYS_RAM_BASE_FIXED
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 22 lines · On Tue, 06 Jul 2021 09:26:21 PDT (-0700), [email protected] wrote:

riscv uses the value of TSK_STACK_CANARY to set stack-protector-guard-offset. With GCC_PLUGIN_RANDSTRUCT enabled, that value is non-deterministic, and with riscv:allmodconfig often results in build errors such as

cc1: error: '8120' is not a valid offset in '-mstack-protector-guard-offset='

Enable STACKPROTECTOR_PER_TASK only if GCC_PLUGIN_RANDSTRUCT is disabled to fix the problem.

Fixes fea2fed201ee5 ("riscv: Enable per-task stack canaries")
Cc Guo Ren <[email protected]>
---
 arch/riscv/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/Kconfig +0 -0
index 469a70bd8da6..3afb84fa2190 100644

arch/riscv/Kconfig config CC_HAVE_STACKPROTECTOR_TLS · line 492

Quoted 7 lines
arch/riscv/Kconfig +1 -0
@@ -486,6 +486,7 @@ config CC_HAVE_STACKPROTECTOR_TLS
 
 config STACKPROTECTOR_PER_TASK
 	def_bool y
+	depends on !GCC_PLUGIN_RANDSTRUCT
 	depends on STACKPROTECTOR && CC_HAVE_STACKPROTECTOR_TLS
 
 config PHYS_RAM_BASE_FIXED

Thanks, this is on fixes. I do an allmodconfig build and haven't seen these failures, is there something special I need to do to get this working? I know nothing about GCC plugins...

#2 lore raw
Quoted 24 lines · Palmer Dabbelt
Quoted 23 lines · On Tue, 06 Jul 2021 09:26:21 PDT (-0700), [email protected] wrote:

riscv uses the value of TSK_STACK_CANARY to set stack-protector-guard-offset. With GCC_PLUGIN_RANDSTRUCT enabled, that value is non-deterministic, and with riscv:allmodconfig often results in build errors such as

cc1: error: '8120' is not a valid offset in '-mstack-protector-guard-offset='

Enable STACKPROTECTOR_PER_TASK only if GCC_PLUGIN_RANDSTRUCT is disabled to fix the problem.

Fixes fea2fed201ee5 ("riscv: Enable per-task stack canaries")
Cc Guo Ren <[email protected]>

---
 arch/riscv/Kconfig | 1 +

 1 file changed, 1 insertion(+)
arch/riscv/Kconfig +0 -0
index 469a70bd8da6..3afb84fa2190 100644
@@ -486,6 +486,7 @@ config CC_HAVE_STACKPROTECTOR_TLS
 
Quoted 8 lines
Quoted 6 lines

 config STACKPROTECTOR_PER_TASK
     def_bool y
+    depends on !GCC_PLUGIN_RANDSTRUCT
     depends on STACKPROTECTOR && CC_HAVE_STACKPROTECTOR_TLS

 config PHYS_RAM_BASE_FIXED

Thanks, this is on fixes.  I do an allmodconfig build and haven't seen these failures, is there something special I need to do to get this working?  I know nothing about GCC plugins...

The problem is seen only randomly. It depends on the value of TSK_STACK_CANARY in include/generated/asm-offsets.h. That in turn depends on the location of stack_canary in struct task_struct. You may have to try several times from a clean tree to see the problem.

Guenter

maintainer
#3 lore raw
In reply to Palmer Dabbelt
Quoted 29 lines · Palmer Dabbelt
Quoted 28 lines · On Tue, 06 Jul 2021 09:26:21 PDT (-0700), [email protected] wrote:

riscv uses the value of TSK_STACK_CANARY to set stack-protector-guard-offset. With GCC_PLUGIN_RANDSTRUCT enabled, that value is non-deterministic, and with riscv:allmodconfig often results in build errors such as

cc1: error: '8120' is not a valid offset in '-mstack-protector-guard-offset='

Enable STACKPROTECTOR_PER_TASK only if GCC_PLUGIN_RANDSTRUCT is disabled to fix the problem.

Fixes fea2fed201ee5 ("riscv: Enable per-task stack canaries")
Cc Guo Ren <[email protected]>
---
 arch/riscv/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/Kconfig +1 -0
index 469a70bd8da6..3afb84fa2190 100644
@@ -486,6 +486,7 @@ config CC_HAVE_STACKPROTECTOR_TLS
 
 config STACKPROTECTOR_PER_TASK
 	def_bool y
+	depends on !GCC_PLUGIN_RANDSTRUCT
 	depends on STACKPROTECTOR && CC_HAVE_STACKPROTECTOR_TLS
 
Quoted 5 lines

arch/riscv/Kconfig config CC_HAVE_STACKPROTECTOR_TLS · line 492

Quoted 1 line
arch/riscv/Kconfig +0 -0
 config PHYS_RAM_BASE_FIXED

Thanks, this is on fixes. I do an allmodconfig build and haven't seen these failures, is there something special I need to do to get this working? I know nothing about GCC plugins...

Sorry, looks like I screwed something up and I didn't actually merge this onto fixes. Not sure what happened, but this time it should actually be on fixes.

#4 lore raw
Quoted 30 lines · Palmer Dabbelt
Quoted 29 lines · Palmer Dabbelt
Quoted 28 lines · On Tue, 06 Jul 2021 09:26:21 PDT (-0700), [email protected] wrote:

riscv uses the value of TSK_STACK_CANARY to set stack-protector-guard-offset. With GCC_PLUGIN_RANDSTRUCT enabled, that value is non-deterministic, and with riscv:allmodconfig often results in build errors such as

cc1: error: '8120' is not a valid offset in '-mstack-protector-guard-offset='

Enable STACKPROTECTOR_PER_TASK only if GCC_PLUGIN_RANDSTRUCT is disabled to fix the problem.

Fixes fea2fed201ee5 ("riscv: Enable per-task stack canaries")
Cc Guo Ren <[email protected]>

---
 arch/riscv/Kconfig | 1 +

 1 file changed, 1 insertion(+)
arch/riscv/Kconfig +0 -0
index 469a70bd8da6..3afb84fa2190 100644
@@ -486,6 +486,7 @@ config CC_HAVE_STACKPROTECTOR_TLS
 

 config STACKPROTECTOR_PER_TASK
     def_bool y
+    depends on !GCC_PLUGIN_RANDSTRUCT
     depends on STACKPROTECTOR && CC_HAVE_STACKPROTECTOR_TLS

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

 config PHYS_RAM_BASE_FIXED

Thanks, this is on fixes.  I do an allmodconfig build and haven't seen these failures, is there something special I need to do to get this working?  I know nothing about GCC plugins...

Sorry, looks like I screwed something up and I didn't actually merge this onto fixes.  Not sure what happened, but this time it should actually be on fixes.

Ah, I thought you decided not to apply it for some reason. I changed my test scripts to always disable GCC_PLUGIN_RANDSTRUCT for riscv build tests and stopped reporting the problem. I mentioned this a couple of weeks ago in my test reports. Just in case you wondered.

Guenter