* [PATCH v2 0/2] vdso: Work around and reject absolute relocations
@ 2025-04-30 9:20 Thomas Weißschuh
2025-04-30 9:20 ` [PATCH v2 1/2] arm64: vdso: Work around invalid absolute relocations from GCC Thomas Weißschuh
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Thomas Weißschuh @ 2025-04-30 9:20 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon, Nam Cao, Anna-Maria Behnsen,
Thomas Gleixner, Andy Lutomirski, Vincenzo Frascino
Cc: linux-arm-kernel, linux-kernel, Jan Stancek,
Thomas Weißschuh
GCC on arm64 would incorrectly emit absolute relocations in vDSO code.
Work around those and break the build if new ones appear.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
Changes in v2:
- Link to openend (invalid) GCC bug containing more explanations
- Refine commit messages
- Don't fail on commit absolute relocations in debug info
- Link to v1: https://lore.kernel.org/r/20250429-vdso-absolute-reloc-v1-0-987a0afd10b5@linutronix.de
---
Thomas Weißschuh (2):
arm64: vdso: Work around invalid absolute relocations from GCC
vdso: Reject absolute relocations during build
arch/arm64/include/asm/vdso/gettimeofday.h | 13 +++++++++++++
lib/vdso/Makefile.include | 6 ++++++
2 files changed, 19 insertions(+)
---
base-commit: b4432656b36e5cc1d50a1f2dc15357543add530e
change-id: 20250428-vdso-absolute-reloc-a226293c1761
Best regards,
--
Thomas Weißschuh <thomas.weissschuh@linutronix.de>
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v2 1/2] arm64: vdso: Work around invalid absolute relocations from GCC
2025-04-30 9:20 [PATCH v2 0/2] vdso: Work around and reject absolute relocations Thomas Weißschuh
@ 2025-04-30 9:20 ` Thomas Weißschuh
2025-05-02 14:19 ` Catalin Marinas
2025-05-02 19:09 ` [tip: timers/urgent] " tip-bot2 for Thomas Weißschuh
2025-04-30 9:20 ` [PATCH v2 2/2] vdso: Reject absolute relocations during build Thomas Weißschuh
2025-04-30 15:33 ` [PATCH v2 0/2] vdso: Work around and reject absolute relocations Jan Stancek
2 siblings, 2 replies; 7+ messages in thread
From: Thomas Weißschuh @ 2025-04-30 9:20 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon, Nam Cao, Anna-Maria Behnsen,
Thomas Gleixner, Andy Lutomirski, Vincenzo Frascino
Cc: linux-arm-kernel, linux-kernel, Jan Stancek,
Thomas Weißschuh
All vDSO code needs to be completely position independent.
Symbol references are marked as hidden so the compiler emits
PC-relative relocations.
However GCC emits absolute relocations for symbol-relative references with
an offset >= 64KiB. After recent refactorings in the vDSO code this is the
case in __arch_get_vdso_u_timens_data() with a page size of 64KiB.
Work around the issue by preventing the optimizer from seeing the offsets.
Reported-by: Jan Stancek <jstancek@redhat.com>
Closes: https://lore.kernel.org/lkml/aApGPAoctq_eoE2g@t14ultra/
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120002
Fixes: 83a2a6b8cfc5 ("vdso/gettimeofday: Prepare do_hres_timens() for introduction of struct vdso_clock")
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
arch/arm64/include/asm/vdso/gettimeofday.h | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/arch/arm64/include/asm/vdso/gettimeofday.h b/arch/arm64/include/asm/vdso/gettimeofday.h
index 92a2b59a9f3df4d20feb483e6d8ebd1d813b7932..3322c7047d84fecae316a2904f1adec0cb458f6f 100644
--- a/arch/arm64/include/asm/vdso/gettimeofday.h
+++ b/arch/arm64/include/asm/vdso/gettimeofday.h
@@ -99,6 +99,19 @@ static __always_inline u64 __arch_get_hw_counter(s32 clock_mode,
return res;
}
+#if IS_ENABLED(CONFIG_CC_IS_GCC) && IS_ENABLED(CONFIG_PAGE_SIZE_64KB)
+static __always_inline const struct vdso_time_data *__arch_get_vdso_u_time_data(void)
+{
+ const struct vdso_time_data *ret = &vdso_u_time_data;
+
+ /* Work around invalid absolute relocations */
+ OPTIMIZER_HIDE_VAR(ret);
+
+ return ret;
+}
+#define __arch_get_vdso_u_time_data __arch_get_vdso_u_time_data
+#endif /* IS_ENABLED(CONFIG_CC_IS_GCC) && IS_ENABLED(CONFIG_PAGE_SIZE_64KB) */
+
#endif /* !__ASSEMBLY__ */
#endif /* __ASM_VDSO_GETTIMEOFDAY_H */
--
2.49.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v2 1/2] arm64: vdso: Work around invalid absolute relocations from GCC
2025-04-30 9:20 ` [PATCH v2 1/2] arm64: vdso: Work around invalid absolute relocations from GCC Thomas Weißschuh
@ 2025-05-02 14:19 ` Catalin Marinas
2025-05-02 19:09 ` [tip: timers/urgent] " tip-bot2 for Thomas Weißschuh
1 sibling, 0 replies; 7+ messages in thread
From: Catalin Marinas @ 2025-05-02 14:19 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Will Deacon, Nam Cao, Anna-Maria Behnsen, Thomas Gleixner,
Andy Lutomirski, Vincenzo Frascino, linux-arm-kernel,
linux-kernel, Jan Stancek
Hi Thomas,
On Wed, Apr 30, 2025 at 11:20:13AM +0200, Thomas Weißschuh wrote:
> All vDSO code needs to be completely position independent.
> Symbol references are marked as hidden so the compiler emits
> PC-relative relocations.
> However GCC emits absolute relocations for symbol-relative references with
> an offset >= 64KiB. After recent refactorings in the vDSO code this is the
> case in __arch_get_vdso_u_timens_data() with a page size of 64KiB.
>
> Work around the issue by preventing the optimizer from seeing the offsets.
>
> Reported-by: Jan Stancek <jstancek@redhat.com>
> Closes: https://lore.kernel.org/lkml/aApGPAoctq_eoE2g@t14ultra/
> Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120002
> Fixes: 83a2a6b8cfc5 ("vdso/gettimeofday: Prepare do_hres_timens() for introduction of struct vdso_clock")
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> ---
> arch/arm64/include/asm/vdso/gettimeofday.h | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/arch/arm64/include/asm/vdso/gettimeofday.h b/arch/arm64/include/asm/vdso/gettimeofday.h
> index 92a2b59a9f3df4d20feb483e6d8ebd1d813b7932..3322c7047d84fecae316a2904f1adec0cb458f6f 100644
> --- a/arch/arm64/include/asm/vdso/gettimeofday.h
> +++ b/arch/arm64/include/asm/vdso/gettimeofday.h
> @@ -99,6 +99,19 @@ static __always_inline u64 __arch_get_hw_counter(s32 clock_mode,
> return res;
> }
>
> +#if IS_ENABLED(CONFIG_CC_IS_GCC) && IS_ENABLED(CONFIG_PAGE_SIZE_64KB)
> +static __always_inline const struct vdso_time_data *__arch_get_vdso_u_time_data(void)
> +{
> + const struct vdso_time_data *ret = &vdso_u_time_data;
> +
> + /* Work around invalid absolute relocations */
> + OPTIMIZER_HIDE_VAR(ret);
> +
> + return ret;
> +}
> +#define __arch_get_vdso_u_time_data __arch_get_vdso_u_time_data
> +#endif /* IS_ENABLED(CONFIG_CC_IS_GCC) && IS_ENABLED(CONFIG_PAGE_SIZE_64KB) */
Thanks for the fix. We may have to chase other such cases in the future
but I don't have any better suggestion.
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Question for the other Thomas (tglx): what's your preference, do you
plan to take these through tip or shall I queue them via the arm64 tree?
Thanks.
--
Catalin
^ permalink raw reply [flat|nested] 7+ messages in thread* [tip: timers/urgent] arm64: vdso: Work around invalid absolute relocations from GCC
2025-04-30 9:20 ` [PATCH v2 1/2] arm64: vdso: Work around invalid absolute relocations from GCC Thomas Weißschuh
2025-05-02 14:19 ` Catalin Marinas
@ 2025-05-02 19:09 ` tip-bot2 for Thomas Weißschuh
1 sibling, 0 replies; 7+ messages in thread
From: tip-bot2 for Thomas Weißschuh @ 2025-05-02 19:09 UTC (permalink / raw)
To: linux-tip-commits
Cc: Jan Stancek, thomas.weissschuh, Thomas Gleixner, Catalin Marinas,
x86, linux-kernel
The following commit has been merged into the timers/urgent branch of tip:
Commit-ID: 0c314cda93258cd1f0055a278a6576b5d4aeabf5
Gitweb: https://git.kernel.org/tip/0c314cda93258cd1f0055a278a6576b5d4aeabf5
Author: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
AuthorDate: Wed, 30 Apr 2025 11:20:13 +02:00
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Fri, 02 May 2025 20:57:11 +02:00
arm64: vdso: Work around invalid absolute relocations from GCC
All vDSO code needs to be completely position independent. Symbol
references are marked as hidden so the compiler emits PC-relative
relocations.
However GCC emits absolute relocations for symbol-relative references with
an offset >= 64KiB. After recent refactorings in the vDSO code this is the
case in __arch_get_vdso_u_timens_data() with a page size of 64KiB.
Work around the issue by preventing the optimizer from seeing the offsets.
Fixes: 83a2a6b8cfc5 ("vdso/gettimeofday: Prepare do_hres_timens() for introduction of struct vdso_clock")
Reported-by: Jan Stancek <jstancek@redhat.com>
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Link: https://lore.kernel.org/all/20250430-vdso-absolute-reloc-v2-1-5efcc3bc4b26@linutronix.de
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120002
Closes: https://lore.kernel.org/lkml/aApGPAoctq_eoE2g@t14ultra/
---
arch/arm64/include/asm/vdso/gettimeofday.h | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/arch/arm64/include/asm/vdso/gettimeofday.h b/arch/arm64/include/asm/vdso/gettimeofday.h
index 92a2b59..3322c70 100644
--- a/arch/arm64/include/asm/vdso/gettimeofday.h
+++ b/arch/arm64/include/asm/vdso/gettimeofday.h
@@ -99,6 +99,19 @@ static __always_inline u64 __arch_get_hw_counter(s32 clock_mode,
return res;
}
+#if IS_ENABLED(CONFIG_CC_IS_GCC) && IS_ENABLED(CONFIG_PAGE_SIZE_64KB)
+static __always_inline const struct vdso_time_data *__arch_get_vdso_u_time_data(void)
+{
+ const struct vdso_time_data *ret = &vdso_u_time_data;
+
+ /* Work around invalid absolute relocations */
+ OPTIMIZER_HIDE_VAR(ret);
+
+ return ret;
+}
+#define __arch_get_vdso_u_time_data __arch_get_vdso_u_time_data
+#endif /* IS_ENABLED(CONFIG_CC_IS_GCC) && IS_ENABLED(CONFIG_PAGE_SIZE_64KB) */
+
#endif /* !__ASSEMBLY__ */
#endif /* __ASM_VDSO_GETTIMEOFDAY_H */
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 2/2] vdso: Reject absolute relocations during build
2025-04-30 9:20 [PATCH v2 0/2] vdso: Work around and reject absolute relocations Thomas Weißschuh
2025-04-30 9:20 ` [PATCH v2 1/2] arm64: vdso: Work around invalid absolute relocations from GCC Thomas Weißschuh
@ 2025-04-30 9:20 ` Thomas Weißschuh
2025-05-02 19:09 ` [tip: timers/urgent] " tip-bot2 for Thomas Weißschuh
2025-04-30 15:33 ` [PATCH v2 0/2] vdso: Work around and reject absolute relocations Jan Stancek
2 siblings, 1 reply; 7+ messages in thread
From: Thomas Weißschuh @ 2025-04-30 9:20 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon, Nam Cao, Anna-Maria Behnsen,
Thomas Gleixner, Andy Lutomirski, Vincenzo Frascino
Cc: linux-arm-kernel, linux-kernel, Jan Stancek,
Thomas Weißschuh
All vDSO code needs to be completely position independent.
Symbol references are marked as hidden so the compiler emits
PC-relative relocations. However there are cases where the compiler may
still emit absolute relocations, as they are valid in regular PIC DSO code.
These would be resolved by the linker and will break at runtime.
Introduce a build-time check for absolute relocations.
The check is done on the object files as the relocations will not exist
anymore in the final DSO. As there is no extension point for the
compilation of each object file, perform the validation in vdso_check.
Debug information can contain legal absolute relocations and readelf can
not print relocations from the .text section only. Make use of the fact
that all global vDSO symbols follow the naming pattern "vdso_u_".
Link: https://lore.kernel.org/lkml/aApGPAoctq_eoE2g@t14ultra/
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120002
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
lib/vdso/Makefile.include | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lib/vdso/Makefile.include b/lib/vdso/Makefile.include
index cedbf15f80874d4bb27c097244bc5b11272f261c..04257d0f28c0ed324e31adbb68497181085752f8 100644
--- a/lib/vdso/Makefile.include
+++ b/lib/vdso/Makefile.include
@@ -12,7 +12,13 @@ c-getrandom-$(CONFIG_VDSO_GETRANDOM) := $(addprefix $(GENERIC_VDSO_DIR), getrand
#
# As a workaround for some GNU ld ports which produce unneeded R_*_NONE
# dynamic relocations, ignore R_*_NONE.
+#
+# Also validate that no absolute relocations against global symbols are present
+# in the object files.
quiet_cmd_vdso_check = VDSOCHK $@
cmd_vdso_check = if $(READELF) -rW $@ | grep -v _NONE | grep -q " R_\w*_"; \
then (echo >&2 "$@: dynamic relocations are not supported"; \
+ rm -f $@; /bin/false); fi && \
+ if $(READELF) -rW $(filter %.o, $(real-prereqs)) | grep -q " R_\w*_ABS.*vdso_u_"; \
+ then (echo >&2 "$@: absolute relocations are not supported"; \
rm -f $@; /bin/false); fi
--
2.49.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [tip: timers/urgent] vdso: Reject absolute relocations during build
2025-04-30 9:20 ` [PATCH v2 2/2] vdso: Reject absolute relocations during build Thomas Weißschuh
@ 2025-05-02 19:09 ` tip-bot2 for Thomas Weißschuh
0 siblings, 0 replies; 7+ messages in thread
From: tip-bot2 for Thomas Weißschuh @ 2025-05-02 19:09 UTC (permalink / raw)
To: linux-tip-commits; +Cc: thomas.weissschuh, Thomas Gleixner, x86, linux-kernel
The following commit has been merged into the timers/urgent branch of tip:
Commit-ID: 7aeb1538be5df3efa1d799e5428ac3a0ae802293
Gitweb: https://git.kernel.org/tip/7aeb1538be5df3efa1d799e5428ac3a0ae802293
Author: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
AuthorDate: Wed, 30 Apr 2025 11:20:14 +02:00
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Fri, 02 May 2025 20:57:11 +02:00
vdso: Reject absolute relocations during build
All vDSO code needs to be completely position independent.
Symbol references are marked as hidden so the compiler emits
PC-relative relocations. However there are cases where the compiler may
still emit absolute relocations, as they are valid in regular PIC DSO code.
These would be resolved by the linker and will break at runtime.
Introduce a build-time check for absolute relocations.
The check is done on the object files as the relocations will not exist
anymore in the final DSO. As there is no extension point for the
compilation of each object file, perform the validation in vdso_check.
Debug information can contain legal absolute relocations and readelf can
not print relocations from the .text section only. Make use of the fact
that all global vDSO symbols follow the naming pattern "vdso_u_".
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/20250430-vdso-absolute-reloc-v2-2-5efcc3bc4b26@linutronix.de
Link: https://lore.kernel.org/lkml/aApGPAoctq_eoE2g@t14ultra/
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120002
---
lib/vdso/Makefile.include | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lib/vdso/Makefile.include b/lib/vdso/Makefile.include
index cedbf15..04257d0 100644
--- a/lib/vdso/Makefile.include
+++ b/lib/vdso/Makefile.include
@@ -12,7 +12,13 @@ c-getrandom-$(CONFIG_VDSO_GETRANDOM) := $(addprefix $(GENERIC_VDSO_DIR), getrand
#
# As a workaround for some GNU ld ports which produce unneeded R_*_NONE
# dynamic relocations, ignore R_*_NONE.
+#
+# Also validate that no absolute relocations against global symbols are present
+# in the object files.
quiet_cmd_vdso_check = VDSOCHK $@
cmd_vdso_check = if $(READELF) -rW $@ | grep -v _NONE | grep -q " R_\w*_"; \
then (echo >&2 "$@: dynamic relocations are not supported"; \
+ rm -f $@; /bin/false); fi && \
+ if $(READELF) -rW $(filter %.o, $(real-prereqs)) | grep -q " R_\w*_ABS.*vdso_u_"; \
+ then (echo >&2 "$@: absolute relocations are not supported"; \
rm -f $@; /bin/false); fi
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 0/2] vdso: Work around and reject absolute relocations
2025-04-30 9:20 [PATCH v2 0/2] vdso: Work around and reject absolute relocations Thomas Weißschuh
2025-04-30 9:20 ` [PATCH v2 1/2] arm64: vdso: Work around invalid absolute relocations from GCC Thomas Weißschuh
2025-04-30 9:20 ` [PATCH v2 2/2] vdso: Reject absolute relocations during build Thomas Weißschuh
@ 2025-04-30 15:33 ` Jan Stancek
2 siblings, 0 replies; 7+ messages in thread
From: Jan Stancek @ 2025-04-30 15:33 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Catalin Marinas, Will Deacon, Nam Cao, Anna-Maria Behnsen,
Thomas Gleixner, Andy Lutomirski, Vincenzo Frascino,
linux-arm-kernel, linux-kernel
On Wed, Apr 30, 2025 at 11:23 AM Thomas Weißschuh
<thomas.weissschuh@linutronix.de> wrote:
>
> GCC on arm64 would incorrectly emit absolute relocations in vDSO code.
> Work around those and break the build if new ones appear.
>
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> ---
> Changes in v2:
> - Link to openend (invalid) GCC bug containing more explanations
> - Refine commit messages
> - Don't fail on commit absolute relocations in debug info
> - Link to v1: https://lore.kernel.org/r/20250429-vdso-absolute-reloc-v1-0-987a0afd10b5@linutronix.de
Tested-by: Jan Stancek <jstancek@redhat.com>
v2 works for me with both reproducers. LTP syscalls run passed as well.
I did a scratch builds of latest Fedora rawhide and ELN with this
series, both passed on all arches:
https://koji.fedoraproject.org/koji/taskinfo?taskID=132140190
https://koji.fedoraproject.org/koji/taskinfo?taskID=132137468
>
> ---
> Thomas Weißschuh (2):
> arm64: vdso: Work around invalid absolute relocations from GCC
> vdso: Reject absolute relocations during build
>
> arch/arm64/include/asm/vdso/gettimeofday.h | 13 +++++++++++++
> lib/vdso/Makefile.include | 6 ++++++
> 2 files changed, 19 insertions(+)
> ---
> base-commit: b4432656b36e5cc1d50a1f2dc15357543add530e
> change-id: 20250428-vdso-absolute-reloc-a226293c1761
>
> Best regards,
> --
> Thomas Weißschuh <thomas.weissschuh@linutronix.de>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-05-02 19:09 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-30 9:20 [PATCH v2 0/2] vdso: Work around and reject absolute relocations Thomas Weißschuh
2025-04-30 9:20 ` [PATCH v2 1/2] arm64: vdso: Work around invalid absolute relocations from GCC Thomas Weißschuh
2025-05-02 14:19 ` Catalin Marinas
2025-05-02 19:09 ` [tip: timers/urgent] " tip-bot2 for Thomas Weißschuh
2025-04-30 9:20 ` [PATCH v2 2/2] vdso: Reject absolute relocations during build Thomas Weißschuh
2025-05-02 19:09 ` [tip: timers/urgent] " tip-bot2 for Thomas Weißschuh
2025-04-30 15:33 ` [PATCH v2 0/2] vdso: Work around and reject absolute relocations Jan Stancek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox