Skip to contentSkip to conversation

s390/vdso: Fix GNU_EH_FRAME PHDR

PATCH Superseded Jens Remus 3 participants 9 messages Jul 6 – Jul 13 s390

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jens Remus

author
#0 lore raw

cover s390/vdso: Fix GNU_EH_FRAME PHDR

Patch 1 fixes the empty GNU_EH_FRAME program table header entry to enable unwinders and stacktracers to locate the .eh_frame_hdr section.

Patch 2 uses symbolic constants for the PHDR permission flags to improve readability and explicitly specifies the GNU_EH_FRAME PHDR to be read- only.

Regards,
Jens

Jens Remus (2):
s390/vdso: Pass --eh-frame-hdr to the linker s390/vdso: Use symbolic constants for the PHDR permission flags

 arch/s390/kernel/vdso/Makefile   |  3 ++-
 arch/s390/kernel/vdso/vdso.lds.S | 12 ++++++++----
 2 files changed, 10 insertions(+), 5 deletions(-)

base-commit: 8cdeaa50eae8dad34885515f62559ee83e7e8dda

Signature · 1 line
2.53.0
author
#1 lore raw

PATCH 1/2 s390/vdso: Pass --eh-frame-hdr to the linker

Commit 2b2a25845d53 ("s390/vdso: Use $(LD) instead of $(CC) to link vDSO") accidentally broke the GNU_PTR_EH_FRAME program table entry in the vDSO, causing it to be empty:

  $ readelf --program-headers arch/s390/kernel/vdso/vdso.so
  ...
  Program Headers:
    Type           Offset             VirtAddr           PhysAddr
                   FileSiz            MemSiz              Flags  Align
  ...
    GNU_EH_FRAME   0x0000000000000000 0x0000000000000000 0x0000000000000000
                   0x0000000000000000 0x0000000000000000         0x8
  ...

Originally, the compiler would implicitly add --eh-frame-hdr when invoking the linker, but when this Makefile was converted from invoking the linker via the compiler, to invoking it directly, the option was missed.

This is the s390 variant of x86 commit cd01544a268a ("x86/vdso: Pass --eh-frame-hdr to the linker").

Fixes 2b2a25845d53 ("s390/vdso: Use $(LD) instead of $(CC) to link vDSO")
---
 arch/s390/kernel/vdso/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/s390/kernel/vdso/Makefile +2 -1
index fece5d975eaf..35c834b895ec 100644
@@ -30,7 +30,8 @@ KBUILD_CFLAGS_VDSO := $(filter-out -fno-asynchronous-unwind-tables,$(KBUILD_CFLA
 KBUILD_CFLAGS_VDSO += -fPIC -fno-common -fno-builtin -fasynchronous-unwind-tables
 KBUILD_CFLAGS_VDSO += -fno-stack-protector $(DISABLE_KSTACK_ERASE)
 ldflags-y := -shared -soname=linux-vdso.so.1 \
-	     --hash-style=both --build-id=sha1 -T
+	     --hash-style=both --build-id=sha1 \
+	     $(call ld-option, --eh-frame-hdr) -T
 
 $(targets:%=$(obj)/%.dbg): KBUILD_CFLAGS = $(KBUILD_CFLAGS_VDSO)
 $(targets:%=$(obj)/%.dbg): KBUILD_AFLAGS = $(KBUILD_AFLAGS_VDSO)
Signature · 1 line
2.53.0
author
#2 lore raw

Re: [PATCH 1/2] s390/vdso: Pass --eh-frame-hdr to the linker

Quoted 2 lines · Jens Remus

Commit 2b2a25845d53 ("s390/vdso: Use $(LD) instead of $(CC) to link vDSO") accidentally broke the GNU_PTR_EH_FRAME program table entry in

s/GNU_PTR_EH_FRAME/GNU_EH_FRAME/

Quoted 17 lines

the vDSO, causing it to be empty:

  $ readelf --program-headers arch/s390/kernel/vdso/vdso.so
  ...
  Program Headers:
    Type           Offset             VirtAddr           PhysAddr
                   FileSiz            MemSiz              Flags  Align
  ...
    GNU_EH_FRAME   0x0000000000000000 0x0000000000000000 0x0000000000000000
                   0x0000000000000000 0x0000000000000000         0x8
  ...

Originally, the compiler would implicitly add --eh-frame-hdr when invoking the linker, but when this Makefile was converted from invoking the linker via the compiler, to invoking it directly, the option was missed.

Quoted 5 lines

This is the s390 variant of x86 commit cd01544a268a ("x86/vdso: Pass --eh-frame-hdr to the linker").

Fixes 2b2a25845d53 ("s390/vdso: Use $(LD) instead of $(CC) to link vDSO")

Regards,
Jens

Signature · 6 lines
Jens Remus
Linux on Z Development (D3303)
[email protected] / [email protected]

IBM Deutschland Research & Development GmbH; Vorsitzender des Aufsichtsrats: Wolfgang Wendt; Geschäftsführung: David Faller; Sitz der Gesellschaft: Ehningen; Registergericht: Amtsgericht Stuttgart, HRB 243294
IBM Data Privacy Statement: https://www.ibm.com/privacy/
Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] s390/vdso: Pass --eh-frame-hdr to the linker

In reply to Jens Remus
Quoted 19 lines · Jens Remus

Commit 2b2a25845d53 ("s390/vdso: Use $(LD) instead of $(CC) to link vDSO") accidentally broke the GNU_PTR_EH_FRAME program table entry in the vDSO, causing it to be empty:

   $ readelf --program-headers arch/s390/kernel/vdso/vdso.so
   ...
   Program Headers:
     Type           Offset             VirtAddr           PhysAddr
                    FileSiz            MemSiz              Flags  Align
   ...
     GNU_EH_FRAME   0x0000000000000000 0x0000000000000000 0x0000000000000000
                    0x0000000000000000 0x0000000000000000         0x8
   ...

Originally, the compiler would implicitly add --eh-frame-hdr when invoking the linker, but when this Makefile was converted from invoking the linker via the compiler, to invoking it directly, the option was missed.

Quoted 8 lines

This is the s390 variant of x86 commit cd01544a268a ("x86/vdso: Pass --eh-frame-hdr to the linker").

Fixes 2b2a25845d53 ("s390/vdso: Use $(LD) instead of $(CC) to link vDSO")
---
  arch/s390/kernel/vdso/Makefile | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
author
#4 lore raw

PATCH 2/2 s390/vdso: Use symbolic constants for the PHDR permission flags

In reply to Jens Remus

While at it explicitly specify GNU_EH_FRAME PHDR to be read-only.

Inspired by x86 commit 8717b02b8c03 ("x86/entry/vdso: Include GNU_PROPERTY and GNU_STACK PHDRs").

---
 arch/s390/kernel/vdso/vdso.lds.S | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
arch/s390/kernel/vdso/vdso.lds.S +8 -4
index 7bec4de0e8e0..35ea7ede06c0 100644
@@ -82,12 +82,16 @@ SECTIONS
  * We must supply the ELF program headers explicitly to get just one
  * PT_LOAD segment, and set the flags explicitly to make segments read-only.
  */
+#define PF_R	FLAGS(4)
+#define PF_RW	FLAGS(6)
+#define PF_RX	FLAGS(5)
+
 PHDRS
 {
-	text		PT_LOAD FILEHDR PHDRS FLAGS(5);	/* PF_R|PF_X */
-	dynamic		PT_DYNAMIC FLAGS(4);		/* PF_R */
-	note		PT_NOTE FLAGS(4);		/* PF_R */
-	eh_frame_hdr	PT_GNU_EH_FRAME;
+	text		PT_LOAD		PF_RX FILEHDR PHDRS;
+	dynamic		PT_DYNAMIC	PF_R;
+	note		PT_NOTE		PF_R;
+	eh_frame_hdr	PT_GNU_EH_FRAME	PF_R;
 }
 
 /*
Signature · 1 line
2.53.0
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] s390/vdso: Use symbolic constants for the PHDR permission flags

Quoted 15 lines · Jens Remus

While at it explicitly specify GNU_EH_FRAME PHDR to be read-only.

Inspired by x86 commit 8717b02b8c03 ("x86/entry/vdso: Include GNU_PROPERTY and GNU_STACK PHDRs").

---
  arch/s390/kernel/vdso/vdso.lds.S | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
arch/s390/kernel/vdso/vdso.lds.S +0 -0
index 7bec4de0e8e0..35ea7ede06c0 100644

arch/s390/kernel/vdso/vdso.lds.S SECTIONS · line 86

Quoted 5 lines
arch/s390/kernel/vdso/vdso.lds.S +2 -0
@@ -82,12 +82,16 @@ SECTIONS
   * We must supply the ELF program headers explicitly to get just one
   * PT_LOAD segment, and set the flags explicitly to make segments read-only.
   */
+#define PF_R	FLAGS(4)
+#define PF_RW	FLAGS(6)

PF_RW seems to be unused
Intel uses it for gnu_stack, which we don't seem to have.

Anyway:

author
#6 lore raw

Re: [PATCH 2/2] s390/vdso: Use symbolic constants for the PHDR permission flags

Quoted 11 lines · Ilya Leoshkevich
Quoted 10 lines · Jens Remus

While at it explicitly specify GNU_EH_FRAME PHDR to be read-only.

Inspired by x86 commit 8717b02b8c03 ("x86/entry/vdso: Include GNU_PROPERTY and GNU_STACK PHDRs").

---
  arch/s390/kernel/vdso/vdso.lds.S | 12 ++++++++----

  1 file changed, 8 insertions(+), 4 deletions(-)
Quoted 13 lines

arch/s390/kernel/vdso/vdso.lds.S SECTIONS · line 86

Quoted 10 lines
arch/s390/kernel/vdso/vdso.lds.S +2 -0
index 7bec4de0e8e0..35ea7ede06c0 100644
@@ -82,12 +82,16 @@ SECTIONS
    * We must supply the ELF program headers explicitly to get just one
    * PT_LOAD segment, and set the flags explicitly to make segments read-only.
    */
+#define PF_R    FLAGS(4)
+#define PF_RW    FLAGS(6)

PF_RW seems to be unused
Intel uses it for gnu_stack, which we don't seem to have.

Good catch, that slipped through.

I wondered whether we should also add a GNU_STACK PHDR in a separate patch - similar to x86 and for the same reasons, as some of the .o files linked into vdso.so do have a .note.GNU-stack.

Quoted 3 lines

Anyway:

Thanks!

Regards,
Jens

Signature · 6 lines
Jens Remus
Linux on Z Development (D3303)
[email protected] / [email protected]

IBM Deutschland Research & Development GmbH; Vorsitzender des Aufsichtsrats: Wolfgang Wendt; Geschäftsführung: David Faller; Sitz der Gesellschaft: Ehningen; Registergericht: Amtsgericht Stuttgart, HRB 243294
IBM Data Privacy Statement: https://www.ibm.com/privacy/
maintainer Acked-by on the v1 series
#7 lore raw
In reply to Jens Remus
Quoted 11 lines · Jens Remus

Patch 1 fixes the empty GNU_EH_FRAME program table header entry to enable unwinders and stacktracers to locate the .eh_frame_hdr section.

Patch 2 uses symbolic constants for the PHDR permission flags to improve readability and explicitly specifies the GNU_EH_FRAME PHDR to be read- only.

Regards,
Jens

Quoted 7 lines

Jens Remus (2):
s390/vdso: Pass --eh-frame-hdr to the linker s390/vdso: Use symbolic constants for the PHDR permission flags

 arch/s390/kernel/vdso/Makefile   |  3 ++-
 arch/s390/kernel/vdso/vdso.lds.S | 12 ++++++++----
 2 files changed, 10 insertions(+), 5 deletions(-)

This series is in limbo state. Do you plan to send a new version to address the very minor nits, or should it stay as is?

In any case:

author
#8 lore raw
Quoted 7 lines · Heiko Carstens
Quoted 6 lines · Jens Remus

Patch 1 fixes the empty GNU_EH_FRAME program table header entry to enable unwinders and stacktracers to locate the .eh_frame_hdr section.

Patch 2 uses symbolic constants for the PHDR permission flags to improve readability and explicitly specifies the GNU_EH_FRAME PHDR to be read- only.

...

Quoted 10 lines
Quoted 7 lines

Jens Remus (2):
s390/vdso: Pass --eh-frame-hdr to the linker s390/vdso: Use symbolic constants for the PHDR permission flags

 arch/s390/kernel/vdso/Makefile   |  3 ++-
 arch/s390/kernel/vdso/vdso.lds.S | 12 ++++++++----
 2 files changed, 10 insertions(+), 5 deletions(-)

This series is in limbo state. Do you plan to send a new version to address the very minor nits, or should it stay as is?

Sorry for the delay! I have sent a v2.

I tried hard to figure out whether adding a proper GNU_STACK PHDR with RW in a separate commit (similar to x86 commit 8717b02b8c03 ("x86/entry/vdso: Include GNU_PROPERTY and GNU_STACK PHDRs") would provide any benefit on s390:

Loading executables in the kernel:

- s390, unlike other archs, does not provide an arch-specific elf_read_implies_exec(), therefore the generic from include/linux/elf.h that returns false is used.
- As a consequence fs/binfmt_elf.c, load_elf_binary() does not default executables without GNU_STACK PHDR to executable stack.

Loading shared libraries in Glibc:

- elf/dl-load.c, _dl_map_object_from_fd() does default shared libraries without GNU_STACK PHDR to executable stack (see DEFAULT_STACK_PERMS).

Based on that I performed the following tests, all using an executable with GNU_STACK RW (not RWX):

Library with GNU_STACK RWX loaded at startup: [stack] rwxp (exec=YES) Library with GNU_STACK RW loaded at startup: [stack] rw-p (exec=NO) Library without GNU_STACK loaded at startup: [stack] rwxp (exec=YES)

Library with GNU_STACK RWX loaded via dlopen: fails *1) Library with GNU_STACK RW loaded via dlopen: [stack] rw-p (exec=NO) Library without GNU_STACK loaded via dlopen: fails *1)

vDSO without GNU_STACK loaded via startup: [stack] rw-p (exec=NO) *2) vDSO without GNU_STACK loaded via dlopen : [stack] rw-p (exec=NO) *3)

*1) dlopen fails with cannot enable executable stack as shared object
requires: Invalid argument. Regardless of glibc.rtld.execstack=1 tunable.

*2) Linking against /usr/modules/.../vdso/vdso.so (won't be listed in
ldd output though)

*3) dlopen("linux-vdso.so.1", RTLD_NOW);

Technically adding a GNU_STACK PHDR with RW seems to be the right thing, although I could not construct a use case, where it would really matter.

Quoted 2 lines

In any case:

Thanks!

Regards,
Jens

Signature · 6 lines
Jens Remus
Linux on Z Development (D3303)
[email protected] / [email protected]

IBM Deutschland Research & Development GmbH; Vorsitzender des Aufsichtsrats: Wolfgang Wendt; Geschäftsführung: David Faller; Sitz der Gesellschaft: Ehningen; Registergericht: Amtsgericht Stuttgart, HRB 243294
IBM Data Privacy Statement: https://www.ibm.com/privacy/