linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] arm64: uapi: Provide correct __BITS_PER_LONG for the compat vDSO
@ 2025-08-21  7:56 Thomas Weißschuh
  2025-08-21  7:56 ` [PATCH 1/3] " Thomas Weißschuh
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2025-08-21  7:56 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Thomas Gleixner, Arnd Bergmann,
	Andy Lutomirski, Vincenzo Frascino
  Cc: John Stultz, linux-arm-kernel, linux-kernel,
	Thomas Weißschuh

The generic vDSO library uses the UAPI headers. On arm64 __BITS_PER_LONG is
always '64' even when used from the compat vDSO. In that case __GENMASK()
does an illegal bitshift, invoking undefined behaviour.

The first patch should go into the 6.17 tree.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
Thomas Weißschuh (3):
      arm64: uapi: Provide correct __BITS_PER_LONG for the compat vDSO
      arm64: vdso32: Stop suppressing warnings
      arm64: vdso32: Respect -Werror from kbuild

 arch/arm64/include/uapi/asm/bitsperlong.h |  5 +++++
 arch/arm64/kernel/vdso32/Makefile         | 13 +------------
 2 files changed, 6 insertions(+), 12 deletions(-)
---
base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
change-id: 20250820-vdso-arm64-compat-bitsperlong-4f59ae7ef6e7

Best regards,
-- 
Thomas Weißschuh <thomas.weissschuh@linutronix.de>



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/3] arm64: uapi: Provide correct __BITS_PER_LONG for the compat vDSO
  2025-08-21  7:56 [PATCH 0/3] arm64: uapi: Provide correct __BITS_PER_LONG for the compat vDSO Thomas Weißschuh
@ 2025-08-21  7:56 ` Thomas Weißschuh
  2025-08-21 17:09   ` John Stultz
  2025-08-21 17:33   ` Arnd Bergmann
  2025-08-21  7:56 ` [PATCH 2/3] arm64: vdso32: Stop suppressing warnings Thomas Weißschuh
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2025-08-21  7:56 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Thomas Gleixner, Arnd Bergmann,
	Andy Lutomirski, Vincenzo Frascino
  Cc: John Stultz, linux-arm-kernel, linux-kernel,
	Thomas Weißschuh

The generic vDSO library uses the UAPI headers. On arm64 __BITS_PER_LONG is
always '64' even when used from the compat vDSO. In that case __GENMASK()
does an illegal bitshift, invoking undefined behaviour.

Change __BITS_PER_LONG to also work when used from the comapt vDSO.
To not confuse real userspace, only do this when building the kernel.

Reported-by: John Stultz <jstultz@google.com>
Closes: https://lore.kernel.org/lkml/CANDhNCqvKOc9JgphQwr0eDyJiyG4oLFS9R8rSFvU0fpurrJFDg@mail.gmail.com/
Fixes: cd3557a7618b ("vdso/gettimeofday: Add support for auxiliary clocks")
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 arch/arm64/include/uapi/asm/bitsperlong.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/arm64/include/uapi/asm/bitsperlong.h b/arch/arm64/include/uapi/asm/bitsperlong.h
index 485d60bee26ca313ad15797f230efe10072befc9..d59730975f30c0764577ec20dfafa33373311e21 100644
--- a/arch/arm64/include/uapi/asm/bitsperlong.h
+++ b/arch/arm64/include/uapi/asm/bitsperlong.h
@@ -17,7 +17,12 @@
 #ifndef __ASM_BITSPERLONG_H
 #define __ASM_BITSPERLONG_H
 
+#if defined(__KERNEL__) && !defined(__aarch64__)
+/* Used by the compat vDSO */
+#define __BITS_PER_LONG 32
+#else
 #define __BITS_PER_LONG 64
+#endif
 
 #include <asm-generic/bitsperlong.h>
 

-- 
2.50.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] arm64: vdso32: Stop suppressing warnings
  2025-08-21  7:56 [PATCH 0/3] arm64: uapi: Provide correct __BITS_PER_LONG for the compat vDSO Thomas Weißschuh
  2025-08-21  7:56 ` [PATCH 1/3] " Thomas Weißschuh
@ 2025-08-21  7:56 ` Thomas Weißschuh
  2025-08-21  7:56 ` [PATCH 3/3] arm64: vdso32: Respect -Werror from kbuild Thomas Weißschuh
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2025-08-21  7:56 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Thomas Gleixner, Arnd Bergmann,
	Andy Lutomirski, Vincenzo Frascino
  Cc: John Stultz, linux-arm-kernel, linux-kernel,
	Thomas Weißschuh

These warnings don't seem to trigger anymore. Probably due to the
introduction of the vdso/ header namespace. Nowadays these suppression
only hide real problems.

Re-enable the warnings.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 arch/arm64/kernel/vdso32/Makefile | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
index f2dfdc7dc8185bc045907283b68ab18fed980312..fd80123bc8e620d868040a61244e83575d855e35 100644
--- a/arch/arm64/kernel/vdso32/Makefile
+++ b/arch/arm64/kernel/vdso32/Makefile
@@ -21,8 +21,6 @@ endif
 
 cc32-option = $(call try-run,\
         $(CC_COMPAT) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
-cc32-disable-warning = $(call try-run,\
-	$(CC_COMPAT) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
 
 # We cannot use the global flags to compile the vDSO files, the main reason
 # being that the 32-bit compiler may be older than the main (64-bit) compiler
@@ -74,16 +72,6 @@ VDSO_CFLAGS += $(call cc32-option,-Werror=strict-prototypes)
 VDSO_CFLAGS += -Werror=date-time
 VDSO_CFLAGS += $(call cc32-option,-Werror=incompatible-pointer-types)
 
-# The 32-bit compiler does not provide 128-bit integers, which are used in
-# some headers that are indirectly included from the vDSO code.
-# This hack makes the compiler happy and should trigger a warning/error if
-# variables of such type are referenced.
-VDSO_CFLAGS += -D__uint128_t='void*'
-# Silence some warnings coming from headers that operate on long's
-# (on GCC 4.8 or older, there is unfortunately no way to silence this warning)
-VDSO_CFLAGS += $(call cc32-disable-warning,shift-count-overflow)
-VDSO_CFLAGS += -Wno-int-to-pointer-cast
-
 # Compile as THUMB2 or ARM. Unwinding via frame-pointers in THUMB2 is
 # unreliable.
 ifeq ($(CONFIG_THUMB2_COMPAT_VDSO), y)

-- 
2.50.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] arm64: vdso32: Respect -Werror from kbuild
  2025-08-21  7:56 [PATCH 0/3] arm64: uapi: Provide correct __BITS_PER_LONG for the compat vDSO Thomas Weißschuh
  2025-08-21  7:56 ` [PATCH 1/3] " Thomas Weißschuh
  2025-08-21  7:56 ` [PATCH 2/3] arm64: vdso32: Stop suppressing warnings Thomas Weißschuh
@ 2025-08-21  7:56 ` Thomas Weißschuh
  2025-09-03 10:49 ` [PATCH 0/3] arm64: uapi: Provide correct __BITS_PER_LONG for the compat vDSO Thomas Weißschuh
  2025-09-03 11:21 ` (subset) " Catalin Marinas
  4 siblings, 0 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2025-08-21  7:56 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Thomas Gleixner, Arnd Bergmann,
	Andy Lutomirski, Vincenzo Frascino
  Cc: John Stultz, linux-arm-kernel, linux-kernel,
	Thomas Weißschuh

The compiler flags for the compat vDSO are built manually as they are not
compatible with the ones from kbuild. CONFIG_WERROR is not respected.

Explicitly inherit -Werror from kbuild.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 arch/arm64/kernel/vdso32/Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
index fd80123bc8e620d868040a61244e83575d855e35..5de4deaf42992046463963df193de47cd07ec1ae 100644
--- a/arch/arm64/kernel/vdso32/Makefile
+++ b/arch/arm64/kernel/vdso32/Makefile
@@ -61,6 +61,7 @@ VDSO_CFLAGS += -DENABLE_COMPAT_VDSO=1
 # KBUILD_CFLAGS from top-level Makefile
 VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
                -fno-strict-aliasing -fno-common \
+               $(filter -Werror,$(KBUILD_CPPFLAGS)) \
                -Werror-implicit-function-declaration \
                -Wno-format-security \
                -std=gnu11

-- 
2.50.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] arm64: uapi: Provide correct __BITS_PER_LONG for the compat vDSO
  2025-08-21  7:56 ` [PATCH 1/3] " Thomas Weißschuh
@ 2025-08-21 17:09   ` John Stultz
  2025-08-21 17:33   ` Arnd Bergmann
  1 sibling, 0 replies; 8+ messages in thread
From: John Stultz @ 2025-08-21 17:09 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Catalin Marinas, Will Deacon, Thomas Gleixner, Arnd Bergmann,
	Andy Lutomirski, Vincenzo Frascino, linux-arm-kernel,
	linux-kernel

On Thu, Aug 21, 2025 at 12:56 AM Thomas Weißschuh
<thomas.weissschuh@linutronix.de> wrote:
>
> The generic vDSO library uses the UAPI headers. On arm64 __BITS_PER_LONG is
> always '64' even when used from the compat vDSO. In that case __GENMASK()
> does an illegal bitshift, invoking undefined behaviour.
>
> Change __BITS_PER_LONG to also work when used from the comapt vDSO.
> To not confuse real userspace, only do this when building the kernel.
>
> Reported-by: John Stultz <jstultz@google.com>
> Closes: https://lore.kernel.org/lkml/CANDhNCqvKOc9JgphQwr0eDyJiyG4oLFS9R8rSFvU0fpurrJFDg@mail.gmail.com/
> Fixes: cd3557a7618b ("vdso/gettimeofday: Add support for auxiliary clocks")
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>

Tested-by: John Stultz <jstultz@google.com>

Thank you so much for the quick fix!
-john


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] arm64: uapi: Provide correct __BITS_PER_LONG for the compat vDSO
  2025-08-21  7:56 ` [PATCH 1/3] " Thomas Weißschuh
  2025-08-21 17:09   ` John Stultz
@ 2025-08-21 17:33   ` Arnd Bergmann
  1 sibling, 0 replies; 8+ messages in thread
From: Arnd Bergmann @ 2025-08-21 17:33 UTC (permalink / raw)
  To: Thomas Weißschuh, Catalin Marinas, Will Deacon,
	Thomas Gleixner, Andy Lutomirski, Vincenzo Frascino
  Cc: John Stultz, linux-arm-kernel, linux-kernel

On Thu, Aug 21, 2025, at 09:56, Thomas Weißschuh wrote:
> The generic vDSO library uses the UAPI headers. On arm64 __BITS_PER_LONG is
> always '64' even when used from the compat vDSO. In that case __GENMASK()
> does an illegal bitshift, invoking undefined behaviour.
>
> Change __BITS_PER_LONG to also work when used from the comapt vDSO.
> To not confuse real userspace, only do this when building the kernel.
>
> Reported-by: John Stultz <jstultz@google.com>
> Closes: 
> https://lore.kernel.org/lkml/CANDhNCqvKOc9JgphQwr0eDyJiyG4oLFS9R8rSFvU0fpurrJFDg@mail.gmail.com/
> Fixes: cd3557a7618b ("vdso/gettimeofday: Add support for auxiliary 
> clocks")
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>

Acked-by: Arnd Bergmann <arnd@arndb.de>

> +#if defined(__KERNEL__) && !defined(__aarch64__)
> +/* Used by the compat vDSO */
> +#define __BITS_PER_LONG 32
> +#else
>  #define __BITS_PER_LONG 64
> +#endif

This should be fine as a hotfix, but I'm worried about this
coming back since there is not enough isolation between
uapi/asm/ headers and the vdso. We've had problems here
before, and arm64 more likely to be affected here than others
because the asm/ headers are not meant to be included from
32-bit compilation units.

A better approach might be either to build the arm64 compat vdso
against the arm32 headers, or to change the vdso code enough
that it only needs headers from the vdso namespace and not
include the uapi/asm/ namespace at all.

Unfortunately both of those require a substantial amount of
work, and are not an option for the current release.

     Arnd


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/3] arm64: uapi: Provide correct __BITS_PER_LONG for the compat vDSO
  2025-08-21  7:56 [PATCH 0/3] arm64: uapi: Provide correct __BITS_PER_LONG for the compat vDSO Thomas Weißschuh
                   ` (2 preceding siblings ...)
  2025-08-21  7:56 ` [PATCH 3/3] arm64: vdso32: Respect -Werror from kbuild Thomas Weißschuh
@ 2025-09-03 10:49 ` Thomas Weißschuh
  2025-09-03 11:21 ` (subset) " Catalin Marinas
  4 siblings, 0 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2025-09-03 10:49 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Vincenzo Frascino
  Cc: Thomas Gleixner, Arnd Bergmann, Andy Lutomirski, John Stultz,
	linux-arm-kernel, linux-kernel

Hi arm64 folks,

On Thu, Aug 21, 2025 at 09:56:43AM +0200, Thomas Weißschuh wrote:
> The generic vDSO library uses the UAPI headers. On arm64 __BITS_PER_LONG is
> always '64' even when used from the compat vDSO. In that case __GENMASK()
> does an illegal bitshift, invoking undefined behaviour.
> 
> The first patch should go into the 6.17 tree.

Could you take this series?


Thanks,

> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> ---
> Thomas Weißschuh (3):
>       arm64: uapi: Provide correct __BITS_PER_LONG for the compat vDSO
>       arm64: vdso32: Stop suppressing warnings
>       arm64: vdso32: Respect -Werror from kbuild
> 
>  arch/arm64/include/uapi/asm/bitsperlong.h |  5 +++++
>  arch/arm64/kernel/vdso32/Makefile         | 13 +------------
>  2 files changed, 6 insertions(+), 12 deletions(-)
> ---
> base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
> change-id: 20250820-vdso-arm64-compat-bitsperlong-4f59ae7ef6e7
> 
> Best regards,
> -- 
> Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: (subset) [PATCH 0/3] arm64: uapi: Provide correct __BITS_PER_LONG for the compat vDSO
  2025-08-21  7:56 [PATCH 0/3] arm64: uapi: Provide correct __BITS_PER_LONG for the compat vDSO Thomas Weißschuh
                   ` (3 preceding siblings ...)
  2025-09-03 10:49 ` [PATCH 0/3] arm64: uapi: Provide correct __BITS_PER_LONG for the compat vDSO Thomas Weißschuh
@ 2025-09-03 11:21 ` Catalin Marinas
  4 siblings, 0 replies; 8+ messages in thread
From: Catalin Marinas @ 2025-09-03 11:21 UTC (permalink / raw)
  To: Will Deacon, Thomas Gleixner, Arnd Bergmann, Andy Lutomirski,
	Vincenzo Frascino, Thomas Weißschuh
  Cc: John Stultz, linux-arm-kernel, linux-kernel

On Thu, 21 Aug 2025 09:56:43 +0200, Thomas Weißschuh wrote:
> The generic vDSO library uses the UAPI headers. On arm64 __BITS_PER_LONG is
> always '64' even when used from the compat vDSO. In that case __GENMASK()
> does an illegal bitshift, invoking undefined behaviour.
> 
> The first patch should go into the 6.17 tree.
> 
> 
> [...]

Applied to arm64 (for-next/fixes), thanks! And sorry for the delay,
missed it due to holidays.

[1/3] arm64: uapi: Provide correct __BITS_PER_LONG for the compat vDSO
      https://git.kernel.org/arm64/c/9a6d3ff10f7f

I'll leave the other two patches to Will for the upcoming merging
window.

-- 
Catalin



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-09-03 12:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-21  7:56 [PATCH 0/3] arm64: uapi: Provide correct __BITS_PER_LONG for the compat vDSO Thomas Weißschuh
2025-08-21  7:56 ` [PATCH 1/3] " Thomas Weißschuh
2025-08-21 17:09   ` John Stultz
2025-08-21 17:33   ` Arnd Bergmann
2025-08-21  7:56 ` [PATCH 2/3] arm64: vdso32: Stop suppressing warnings Thomas Weißschuh
2025-08-21  7:56 ` [PATCH 3/3] arm64: vdso32: Respect -Werror from kbuild Thomas Weißschuh
2025-09-03 10:49 ` [PATCH 0/3] arm64: uapi: Provide correct __BITS_PER_LONG for the compat vDSO Thomas Weißschuh
2025-09-03 11:21 ` (subset) " Catalin Marinas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).