Skip to contentSkip to conversation

time: Zerofy padding in __kernel_timespec on 32-bit

PATCH Applied Dmitry Safonov 3 participants 3 messages Nov 21, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 time: Zerofy padding in __kernel_timespec on 32-bit

On compat interfaces, the high order bits of nanoseconds should be zeroed out. This is because the application code or the libc do not guarantee zeroing of these. If used without zeroing, kernel might be at risk of using timespec values incorrectly.

Originally it was handled correctly, but lost during is_compat_syscall() cleanup. Revert the condition back to check CONFIG_64BIT.

Fixes 98f76206b335 ("compat: Cleanup in_compat_syscall() callers")
Cc Arnd Bergmann <[email protected]>
Cc Ben Hutchings <[email protected]>
Cc John Stultz <[email protected]>
Cc Stephen Boyd <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc [email protected] # v4.20+
---
 kernel/time/time.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/time.c +1 -1
index 5c54ca632d08..1cb045c5c97e 100644
@@ -881,7 +881,7 @@ int get_timespec64(struct timespec64 *ts,
 	ts->tv_sec = kts.tv_sec;
 
 	/* Zero out the padding for 32 bit systems or in compat mode */
-	if (IS_ENABLED(CONFIG_64BIT_TIME) && in_compat_syscall())
+	if (IS_ENABLED(CONFIG_64BIT_TIME) && (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall()))
 		kts.tv_nsec &= 0xFFFFFFFFUL;
 
 	ts->tv_nsec = kts.tv_nsec;
Signature · 1 line
2.24.0
merge bot Applied
#1 lore raw

[tip: timers/urgent] time: Zero the upper 32-bits in __kernel_timespec on 32-bit

The following commit has been merged into the timers/urgent branch of tip:

The following commit has been merged into the timers/urgent branch of tip:

Commit-ID:     7b8474466ed97be458c825f34a85f2c2b84c3f95
Gitweb:        https://git.kernel.org/tip/7b8474466ed97be458c825f34a85f2c2b84c3f95
Author:        Dmitry Safonov <[email protected]>
AuthorDate:    Thu, 21 Nov 2019 00:03:03 
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Thu, 21 Nov 2019 01:17:58 +01:00

time: Zero the upper 32-bits in __kernel_timespec on 32-bit

On compat interfaces, the high order bits of nanoseconds should be zeroed out. This is because the application code or the libc do not guarantee zeroing of these. If used without zeroing, kernel might be at risk of using timespec values incorrectly.

Originally it was handled correctly, but lost during is_compat_syscall() cleanup. Revert the condition back to check CONFIG_64BIT.

---
 kernel/time/time.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/time/time.c +2 -1
index 5c54ca6..83f403e 100644
@@ -881,7 +881,8 @@ int get_timespec64(struct timespec64 *ts,
 	ts->tv_sec = kts.tv_sec;
 
 	/* Zero out the padding for 32 bit systems or in compat mode */
-	if (IS_ENABLED(CONFIG_64BIT_TIME) && in_compat_syscall())
+	if (IS_ENABLED(CONFIG_64BIT_TIME) && (!IS_ENABLED(CONFIG_64BIT) ||
+					      in_compat_syscall()))
 		kts.tv_nsec &= 0xFFFFFFFFUL;
 
 	ts->tv_nsec = kts.tv_nsec;
Reviewed-by on v1 1/1
#2 lore raw
In reply to Dmitry Safonov
Quoted 11 lines · Dmitry Safonov

On compat interfaces, the high order bits of nanoseconds should be zeroed out. This is because the application code or the libc do not guarantee zeroing of these. If used without zeroing, kernel might be at risk of using timespec values incorrectly.

Originally it was handled correctly, but lost during is_compat_syscall() cleanup. Revert the condition back to check CONFIG_64BIT.

Fixes 98f76206b335 ("compat: Cleanup in_compat_syscall() callers")