[PATCH 1/3] arm64: uapi: Provide correct __BITS_PER_LONG for the compat vDSO

Thomas Weißschuh posted 3 patches 1 month, 1 week ago
[PATCH 1/3] arm64: uapi: Provide correct __BITS_PER_LONG for the compat vDSO
Posted by Thomas Weißschuh 1 month, 1 week ago
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

Re: [PATCH 1/3] arm64: uapi: Provide correct __BITS_PER_LONG for the compat vDSO
Posted by John Stultz 1 month, 1 week ago
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