Skip to content

Commit aff6927

Browse files
MaskRayKAGA-KOKO
authored andcommitted
vdso: Improve cmd_vdso_check to check all dynamic relocations
The actual intention is that no dynamic relocation exists in the VDSO. For this the VDSO build validates that the resulting .so file does not have any relocations which are specified via $(ARCH_REL_TYPE_ABS) per architecture, which is fragile as e.g. ARM64 lacks an entry for R_AARCH64_RELATIVE. Aside of that ARCH_REL_TYPE_ABS is a misnomer as it checks for relative relocations too. However, some GNU ld ports produce unneeded R_*_NONE relocation entries. If a port fails to determine the exact .rel[a].dyn size, the trailing zeros become R_*_NONE relocations. E.g. ld's powerpc port recently fixed https://sourceware.org/bugzilla/show_bug.cgi?id=29540). R_*_NONE are generally a no-op in the dynamic loaders. So just ignore them. Remove the ARCH_REL_TYPE_ABS defines and just validate that the resulting .so file does not contain any R_* relocation entries except R_*_NONE. Signed-off-by: Fangrui Song <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Vincenzo Frascino <[email protected]> # for aarch64 Reviewed-by: Christophe Leroy <[email protected]> Reviewed-by: Vincenzo Frascino <[email protected]> # for vDSO, aarch64 Acked-by: Michael Ellerman <[email protected]> (powerpc) Link: https://lore.kernel.org/r/[email protected]
1 parent e8d018d commit aff6927

File tree

12 files changed

+14
-39
lines changed

12 files changed

+14
-39
lines changed

arch/arm/vdso/Makefile

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0
22

3-
# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
4-
# the inclusion of generic Makefile.
5-
ARCH_REL_TYPE_ABS := R_ARM_JUMP_SLOT|R_ARM_GLOB_DAT|R_ARM_ABS32
3+
# Include the generic Makefile to check the built vdso.
64
include $(srctree)/lib/vdso/Makefile
75

86
hostprogs := vdsomunge

arch/arm64/kernel/vdso/Makefile

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
# Heavily based on the vDSO Makefiles for other archs.
77
#
88

9-
# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
10-
# the inclusion of generic Makefile.
11-
ARCH_REL_TYPE_ABS := R_AARCH64_JUMP_SLOT|R_AARCH64_GLOB_DAT|R_AARCH64_ABS64
9+
# Include the generic Makefile to check the built vdso.
1210
include $(srctree)/lib/vdso/Makefile
1311

1412
obj-vdso := vgettimeofday.o note.o sigreturn.o

arch/arm64/kernel/vdso32/Makefile

-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
# Makefile for vdso32
44
#
55

6-
# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
7-
# the inclusion of generic Makefile.
8-
ARCH_REL_TYPE_ABS := R_ARM_JUMP_SLOT|R_ARM_GLOB_DAT|R_ARM_ABS32
96
include $(srctree)/lib/vdso/Makefile
107

118
# Same as cc-*option, but using CC_COMPAT instead of CC

arch/csky/kernel/vdso/Makefile

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22

3-
# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
4-
# the inclusion of generic Makefile.
5-
ARCH_REL_TYPE_ABS := R_CKCORE_ADDR32|R_CKCORE_JUMP_SLOT
3+
# Include the generic Makefile to check the built vdso.
64
include $(srctree)/lib/vdso/Makefile
75

86
# Symbols present in the vdso

arch/loongarch/vdso/Makefile

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0
22
# Objects to go into the VDSO.
33

4-
# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
5-
# the inclusion of generic Makefile.
6-
ARCH_REL_TYPE_ABS := R_LARCH_32|R_LARCH_64|R_LARCH_MARK_LA|R_LARCH_JUMP_SLOT
4+
# Include the generic Makefile to check the built vdso.
75
include $(srctree)/lib/vdso/Makefile
86

97
obj-vdso-y := elf.o vgetcpu.o vgettimeofday.o sigreturn.o

arch/mips/vdso/Makefile

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
# Sanitizer runtimes are unavailable and cannot be linked here.
55
KCSAN_SANITIZE := n
66

7-
# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
8-
# the inclusion of generic Makefile.
9-
ARCH_REL_TYPE_ABS := R_MIPS_JUMP_SLOT|R_MIPS_GLOB_DAT
7+
# Include the generic Makefile to check the built vdso.
108
include $(srctree)/lib/vdso/Makefile
119

1210
obj-vdso-y := elf.o vgettimeofday.o sigreturn.o

arch/powerpc/kernel/vdso/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# List of files in the vdso, has to be asm only for now
44

5-
ARCH_REL_TYPE_ABS := R_PPC_JUMP_SLOT|R_PPC_GLOB_DAT|R_PPC_ADDR32|R_PPC_ADDR24|R_PPC_ADDR16|R_PPC_ADDR16_LO|R_PPC_ADDR16_HI|R_PPC_ADDR16_HA|R_PPC_ADDR14|R_PPC_ADDR14_BRTAKEN|R_PPC_ADDR14_BRNTAKEN|R_PPC_REL24
5+
# Include the generic Makefile to check the built vdso.
66
include $(srctree)/lib/vdso/Makefile
77

88
obj-vdso32 = sigtramp32-32.o gettimeofday-32.o datapage-32.o cacheflush-32.o note-32.o getcpu-32.o

arch/riscv/kernel/vdso/Makefile

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22
# Copied from arch/tile/kernel/vdso/Makefile
33

4-
# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
5-
# the inclusion of generic Makefile.
6-
ARCH_REL_TYPE_ABS := R_RISCV_32|R_RISCV_64|R_RISCV_JUMP_SLOT
4+
# Include the generic Makefile to check the built vdso.
75
include $(srctree)/lib/vdso/Makefile
86
# Symbols present in the vdso
97
vdso-syms = rt_sigreturn

arch/s390/kernel/vdso32/Makefile

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
# List of files in the vdso
33

44
KCOV_INSTRUMENT := n
5-
ARCH_REL_TYPE_ABS := R_390_COPY|R_390_GLOB_DAT|R_390_JMP_SLOT|R_390_RELATIVE
6-
ARCH_REL_TYPE_ABS += R_390_GOT|R_390_PLT
75

6+
# Include the generic Makefile to check the built vdso.
87
include $(srctree)/lib/vdso/Makefile
98
obj-vdso32 = vdso_user_wrapper-32.o note-32.o
109

arch/s390/kernel/vdso64/Makefile

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
# List of files in the vdso
33

44
KCOV_INSTRUMENT := n
5-
ARCH_REL_TYPE_ABS := R_390_COPY|R_390_GLOB_DAT|R_390_JMP_SLOT|R_390_RELATIVE
6-
ARCH_REL_TYPE_ABS += R_390_GOT|R_390_PLT
75

6+
# Include the generic Makefile to check the built vdso.
87
include $(srctree)/lib/vdso/Makefile
98
obj-vdso64 = vdso_user_wrapper.o note.o
109
obj-cvdso64 = vdso64_generic.o getcpu.o

arch/x86/entry/vdso/Makefile

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
# Building vDSO images for x86.
44
#
55

6-
# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
7-
# the inclusion of generic Makefile.
8-
ARCH_REL_TYPE_ABS := R_X86_64_JUMP_SLOT|R_X86_64_GLOB_DAT|R_X86_64_RELATIVE|
9-
ARCH_REL_TYPE_ABS += R_386_GLOB_DAT|R_386_JMP_SLOT|R_386_RELATIVE
6+
# Include the generic Makefile to check the built vdso.
107
include $(srctree)/lib/vdso/Makefile
118

129
# Sanitizer runtimes are unavailable and cannot be linked here.

lib/vdso/Makefile

+4-9
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,13 @@ GENERIC_VDSO_DIR := $(dir $(GENERIC_VDSO_MK_PATH))
55

66
c-gettimeofday-$(CONFIG_GENERIC_GETTIMEOFDAY) := $(addprefix $(GENERIC_VDSO_DIR), gettimeofday.c)
77

8-
# This cmd checks that the vdso library does not contain absolute relocation
8+
# This cmd checks that the vdso library does not contain dynamic relocations.
99
# It has to be called after the linking of the vdso library and requires it
1010
# as a parameter.
1111
#
12-
# $(ARCH_REL_TYPE_ABS) is defined in the arch specific makefile and corresponds
13-
# to the absolute relocation types printed by "objdump -R" and accepted by the
14-
# dynamic linker.
15-
ifndef ARCH_REL_TYPE_ABS
16-
$(error ARCH_REL_TYPE_ABS is not set)
17-
endif
18-
12+
# As a workaround for some GNU ld ports which produce unneeded R_*_NONE
13+
# dynamic relocations, ignore R_*_NONE.
1914
quiet_cmd_vdso_check = VDSOCHK $@
20-
cmd_vdso_check = if $(OBJDUMP) -R $@ | grep -E -h "$(ARCH_REL_TYPE_ABS)"; \
15+
cmd_vdso_check = if $(READELF) -rW $@ | grep -v _NONE | grep -q " R_\w*_"; \
2116
then (echo >&2 "$@: dynamic relocations are not supported"; \
2217
rm -f $@; /bin/false); fi

0 commit comments

Comments
 (0)