Skip to contentSkip to conversation

purgatory: force PIC/PIE/SSP off

PATCH Superseded Mike Frysinger 3 participants 4 messages Apr 16, 2015 – Apr 30, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 purgatory: force PIC/PIE/SSP off

From: Mike Frysinger <[email protected]>

If the toolchain has these things turned on automatically, then the purgatory code might be miscompiled leading to runtime errors like:
Unhandled rela relocation: R_X86_64_GOTPC64

It might look like the problem is with the kernel when in reality, kexec is complaining about the purgatory module. Force off harden features that don't make sense in kernel space.

---
 purgatory/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
purgatory/Makefile +2 -1
index 2d6b2c0..2b5c061 100644
@@ -49,7 +49,8 @@ $(PURGATORY): CC=$(TARGET_CC)
 $(PURGATORY): CFLAGS+=$(PURGATORY_EXTRA_CFLAGS) \
 		      $($(ARCH)_PURGATORY_EXTRA_CFLAGS) \
 		      -Os -fno-builtin -ffreestanding \
-		      -fno-zero-initialized-in-bss
+		      -fno-zero-initialized-in-bss \
+		      -fno-PIC -fno-PIE -fno-stack-protector
 
 $(PURGATORY): CPPFLAGS=$($(ARCH)_PURGATORY_EXTRA_CFLAGS) \
 			-I$(srcdir)/purgatory/include \
Signature · 7 lines
2.3.5


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#1 lore raw
Quoted 20 lines · Mike Frysinger

From: Mike Frysinger <[email protected]>

If the toolchain has these things turned on automatically, then the purgatory code might be miscompiled leading to runtime errors like:
Unhandled rela relocation: R_X86_64_GOTPC64

It might look like the problem is with the kernel when in reality, kexec is complaining about the purgatory module. Force off harden features that don't make sense in kernel space.

---
 purgatory/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
purgatory/Makefile +0 -0
index 2d6b2c0..2b5c061 100644

purgatory/Makefile $(PURGATORY): CC=$(TARGET_CC) · line 53

Quoted 6 lines
purgatory/Makefile +2 -1
@@ -49,7 +49,8 @@ $(PURGATORY): CC=$(TARGET_CC)
 $(PURGATORY): CFLAGS+=$(PURGATORY_EXTRA_CFLAGS) \
 		      $($(ARCH)_PURGATORY_EXTRA_CFLAGS) \
 		      -Os -fno-builtin -ffreestanding \
-		      -fno-zero-initialized-in-bss
+		      -fno-zero-initialized-in-bss \
+		      -fno-PIC -fno-PIE -fno-stack-protector

Some architectures (ppc64 and s390) are already setting -fno-stack-protector in purgatory/arch/x/Makefile through x_PURGATORY_EXTRA_CFLAGS.

It would be cleaner to remove those per architecture settings if you set it globally.

Cheers,
Laurent.

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#2 lore raw

PATCH v2 1/1 purgatory: force PIC/PIE/SSP off

From: Mike Frysinger <[email protected]>

If the toolchain has these things turned on automatically, then the purgatory code might be miscompiled leading to runtime errors like:
Unhandled rela relocation: R_X86_64_GOTPC64

It might look like the problem is with the kernel when in reality, kexec is complaining about the purgatory module. Force off harden features that don't make sense in kernel space.

---
Note: I suspect this patch fixes a semi-recent report:
http://lists.infradead.org/pipermail/kexec/2015-February/013305.html

v2:
- clean up ssp flags in arch subdirs

 purgatory/Makefile            | 3 ++-
 purgatory/arch/ppc64/Makefile | 2 +-
 purgatory/arch/s390/Makefile  | 1 -
 3 files changed, 3 insertions(+), 3 deletions(-)
purgatory/Makefile +2 -1
index 2d6b2c0..2b5c061 100644
@@ -49,7 +49,8 @@ $(PURGATORY): CC=$(TARGET_CC)
 $(PURGATORY): CFLAGS+=$(PURGATORY_EXTRA_CFLAGS) \
 		      $($(ARCH)_PURGATORY_EXTRA_CFLAGS) \
 		      -Os -fno-builtin -ffreestanding \
-		      -fno-zero-initialized-in-bss
+		      -fno-zero-initialized-in-bss \
+		      -fno-PIC -fno-PIE -fno-stack-protector
 
 $(PURGATORY): CPPFLAGS=$($(ARCH)_PURGATORY_EXTRA_CFLAGS) \
 			-I$(srcdir)/purgatory/include \
purgatory/arch/ppc64/Makefile +1 -1
index 6c58fa2..8ca2719 100644
@@ -9,7 +9,7 @@ ppc64_PURGATORY_SRCS += purgatory/arch/ppc64/console-ppc64.c
 ppc64_PURGATORY_SRCS += purgatory/arch/ppc64/crashdump_backup.c
 ppc64_PURGATORY_SRCS += purgatory/arch/ppc64/misc.S
 
-ppc64_PURGATORY_EXTRA_CFLAGS += -m64 -msoft-float -fno-stack-protector	\
+ppc64_PURGATORY_EXTRA_CFLAGS += -m64 -msoft-float \
 				-fno-exceptions
 ppc64_PURGATORY_EXTRA_ASFLAGS += -m64
 ifeq ($(SUBARCH),BE)
purgatory/arch/s390/Makefile +0 -1
index 09749bd..c94cc3c 100644
@@ -2,7 +2,6 @@
 # Purgatory s390
 #
 
-s390_PURGATORY_EXTRA_CFLAGS += -fno-stack-protector
 s390_PURGATORY_SRCS += purgatory/arch/s390/console-s390.c
 s390_PURGATORY_SRCS += purgatory/arch/s390/setup-s390.S
 s390_PURGATORY_SRCS += purgatory/arch/s390/purgatory-s390.c
Signature · 7 lines
2.3.5


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Applied
#3 lore raw
Quoted 11 lines · Mike Frysinger

From: Mike Frysinger <[email protected]>

If the toolchain has these things turned on automatically, then the purgatory code might be miscompiled leading to runtime errors like:
Unhandled rela relocation: R_X86_64_GOTPC64

It might look like the problem is with the kernel when in reality, kexec is complaining about the purgatory module. Force off harden features that don't make sense in kernel space.

thanks, applied.

Quoted 60 lines

---
Note: I suspect this patch fixes a semi-recent report:
http://lists.infradead.org/pipermail/kexec/2015-February/013305.html

v2:
- clean up ssp flags in arch subdirs

 purgatory/Makefile            | 3 ++-
 purgatory/arch/ppc64/Makefile | 2 +-
 purgatory/arch/s390/Makefile  | 1 -
 3 files changed, 3 insertions(+), 3 deletions(-)
purgatory/Makefile +2 -1
index 2d6b2c0..2b5c061 100644
@@ -49,7 +49,8 @@ $(PURGATORY): CC=$(TARGET_CC)
 $(PURGATORY): CFLAGS+=$(PURGATORY_EXTRA_CFLAGS) \
 		      $($(ARCH)_PURGATORY_EXTRA_CFLAGS) \
 		      -Os -fno-builtin -ffreestanding \
-		      -fno-zero-initialized-in-bss
+		      -fno-zero-initialized-in-bss \
+		      -fno-PIC -fno-PIE -fno-stack-protector
 
 $(PURGATORY): CPPFLAGS=$($(ARCH)_PURGATORY_EXTRA_CFLAGS) \
 			-I$(srcdir)/purgatory/include \
purgatory/arch/ppc64/Makefile +1 -1
index 6c58fa2..8ca2719 100644
@@ -9,7 +9,7 @@ ppc64_PURGATORY_SRCS += purgatory/arch/ppc64/console-ppc64.c
 ppc64_PURGATORY_SRCS += purgatory/arch/ppc64/crashdump_backup.c
 ppc64_PURGATORY_SRCS += purgatory/arch/ppc64/misc.S
 
-ppc64_PURGATORY_EXTRA_CFLAGS += -m64 -msoft-float -fno-stack-protector	\
+ppc64_PURGATORY_EXTRA_CFLAGS += -m64 -msoft-float \
 				-fno-exceptions
 ppc64_PURGATORY_EXTRA_ASFLAGS += -m64
 ifeq ($(SUBARCH),BE)
purgatory/arch/s390/Makefile +0 -1
index 09749bd..c94cc3c 100644
@@ -2,7 +2,6 @@
 # Purgatory s390
 #
 
-s390_PURGATORY_EXTRA_CFLAGS += -fno-stack-protector
 s390_PURGATORY_SRCS += purgatory/arch/s390/console-s390.c
 s390_PURGATORY_SRCS += purgatory/arch/s390/setup-s390.S
 s390_PURGATORY_SRCS += purgatory/arch/s390/purgatory-s390.c
Signature · 7 lines
2.3.5


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec