Skip to contentSkip to conversation

parisc64: change __kernel_suseconds_t to match glibc

RFC In review Arnd Bergmann 2 participants 4 messages Sep 13, 2018 – Sep 25, 2018 PA-RISC architecture

lore
Share & tools
lore
#0 lore raw

RFC 1/1 parisc64: change __kernel_suseconds_t to match glibc

There are only two 64-bit architecture ports that have a 32-bit
suseconds_t: sparc64 and parisc64. I've encountered a number of problems with this, while trying to get a proper 64-bit time_t working on 32-bit architectures. Having a 32-bit suseconds_t combined with a 64-bit time_t means that we get extra padding in data structures that may leak kernel stack data to user space, and it breaks all code that assumes that timespec and timeval have the same layout.

While we can't change sparc64, it seems that glibc on parisc64 has always set suseconds_t to 'long', and the current version would give incorrect results for gettimeofday() and many other interfaces: timestamps passed from user space into the kernel result in tv_usec being always zero (the lower bits contain the intended value but are ignored) while data passed from the kernel to user space contains either zeroes or random data in tv_usec.

Based on that, it seems best to change the user API in the kernel in an incompatible way to match what glibc expects.

Note that the distros I could find (gentoo and debian) all just have 32-bit user space, which does not suffer from this problem.

---
 arch/parisc/include/uapi/asm/posix_types.h | 3 ---
 1 file changed, 3 deletions(-)
arch/parisc/include/uapi/asm/posix_types.h +0 -3
index 2785632c85e7..8dce56f5dcee 100644
@@ -16,9 +16,6 @@ typedef unsigned short		__kernel_mode_t;
 typedef unsigned short		__kernel_ipc_pid_t;
 #define __kernel_ipc_pid_t __kernel_ipc_pid_t
 
-typedef int			__kernel_suseconds_t;
-#define __kernel_suseconds_t __kernel_suseconds_t
-
 typedef long long		__kernel_off64_t;
 typedef unsigned long long	__kernel_ino64_t;
 
Signature · 1 line
2.18.0
maintainer
#1 lore raw

Hi Arnd,

Quoted 8 lines · Arnd Bergmann

There are only two 64-bit architecture ports that have a 32-bit
suseconds_t: sparc64 and parisc64. I've encountered a number of problems with this, while trying to get a proper 64-bit time_t working on 32-bit architectures. Having a 32-bit suseconds_t combined with a 64-bit time_t means that we get extra padding in data structures that may leak kernel stack data to user space, and it breaks all code that assumes that timespec and timeval have the same layout.

Quoted 7 lines

While we can't change sparc64, it seems that glibc on parisc64 has always set suseconds_t to 'long', and the current version would give incorrect results for gettimeofday() and many other interfaces: timestamps passed from user space into the kernel result in tv_usec being always zero (the lower bits contain the intended value but are ignored) while data passed from the kernel to user space contains either zeroes or random data in tv_usec.

Should this wrong behavior be visible with 32-bit userspace or with 64-bit userspace (or both)?
I didn't noticed such wrong behavior yet.

Can you suggest some test programs to verify?
LTP seems to be correct.

Quoted 2 lines

Based on that, it seems best to change the user API in the kernel in an incompatible way to match what glibc expects.

Basically that sounds the right way to go, but as said before, I didn't see such issues.

Quoted 2 lines

Note that the distros I could find (gentoo and debian) all just have 32-bit user space, which does not suffer from this problem.

That's correct.
Kernel can be 32- or 64-bit, but userspace is currentl 32-bit only.

So, breaking any 64-bit userspace is OK, since we don't have it yet. Breaking 32-bit userspace needs some thoughts...

Helge

Quoted 20 lines
---
 arch/parisc/include/uapi/asm/posix_types.h | 3 ---
 1 file changed, 3 deletions(-)
arch/parisc/include/uapi/asm/posix_types.h +0 -3
index 2785632c85e7..8dce56f5dcee 100644
@@ -16,9 +16,6 @@ typedef unsigned short		__kernel_mode_t;
 typedef unsigned short		__kernel_ipc_pid_t;
 #define __kernel_ipc_pid_t __kernel_ipc_pid_t
 
-typedef int			__kernel_suseconds_t;
-#define __kernel_suseconds_t __kernel_suseconds_t
-
 typedef long long		__kernel_off64_t;
 typedef unsigned long long	__kernel_ino64_t;
 
#2 lore raw
Quoted 9 lines · Helge Deller
Quoted 8 lines · Arnd Bergmann

There are only two 64-bit architecture ports that have a 32-bit
suseconds_t: sparc64 and parisc64. I've encountered a number of problems with this, while trying to get a proper 64-bit time_t working on 32-bit architectures. Having a 32-bit suseconds_t combined with a 64-bit time_t means that we get extra padding in data structures that may leak kernel stack data to user space, and it breaks all code that assumes that timespec and timeval have the same layout.

Quoted 7 lines
Quoted 7 lines

While we can't change sparc64, it seems that glibc on parisc64 has always set suseconds_t to 'long', and the current version would give incorrect results for gettimeofday() and many other interfaces: timestamps passed from user space into the kernel result in tv_usec being always zero (the lower bits contain the intended value but are ignored) while data passed from the kernel to user space contains either zeroes or random data in tv_usec.

[back from traveling now, sorry for the delay in replying]

Quoted 3 lines

Should this wrong behavior be visible with 32-bit userspace or with 64-bit userspace (or both)?
I didn't noticed such wrong behavior yet.

Only 64-bit user space.

Quoted 2 lines

Can you suggest some test programs to verify?
LTP seems to be correct.

A simple 64-bit gettimeofday() should report incorrect nanoseconds using the upstream glibc implementation.

Quoted 6 lines
Quoted 2 lines

Based on that, it seems best to change the user API in the kernel in an incompatible way to match what glibc expects.

Basically that sounds the right way to go, but as said before, I didn't see such issues.

Quoted 8 lines
Quoted 2 lines

Note that the distros I could find (gentoo and debian) all just have 32-bit user space, which does not suffer from this problem.

That's correct.
Kernel can be 32- or 64-bit, but userspace is currentl 32-bit only.

So, breaking any 64-bit userspace is OK, since we don't have it yet. Breaking 32-bit userspace needs some thoughts...

Ok.

Arnd

maintainer
#3 lore raw
Quoted 26 lines · Arnd Bergmann
Quoted 9 lines · Helge Deller
Quoted 8 lines · Arnd Bergmann

There are only two 64-bit architecture ports that have a 32-bit
suseconds_t: sparc64 and parisc64. I've encountered a number of problems with this, while trying to get a proper 64-bit time_t working on 32-bit architectures. Having a 32-bit suseconds_t combined with a 64-bit time_t means that we get extra padding in data structures that may leak kernel stack data to user space, and it breaks all code that assumes that timespec and timeval have the same layout.

Quoted 7 lines
Quoted 7 lines

While we can't change sparc64, it seems that glibc on parisc64 has always set suseconds_t to 'long', and the current version would give incorrect results for gettimeofday() and many other interfaces: timestamps passed from user space into the kernel result in tv_usec being always zero (the lower bits contain the intended value but are ignored) while data passed from the kernel to user space contains either zeroes or random data in tv_usec.

[back from traveling now, sorry for the delay in replying]

Quoted 3 lines

Should this wrong behavior be visible with 32-bit userspace or with 64-bit userspace (or both)?
I didn't noticed such wrong behavior yet.

Only 64-bit user space.

...

Quoted 2 lines

A simple 64-bit gettimeofday() should report incorrect nanoseconds using the upstream glibc implementation.

Yes, you are right.
Since we don't have any 64-bit userspace yet, it's safe to fix it now as you suggested. I've added your patch as is to my for-next tree and tagged it for stable-tree.

Thanks for catching this!

Helge