Skip to content

Commit

Permalink
time: Zero the upper 32-bits in __kernel_timespec on 32-bit
Browse files Browse the repository at this point in the history
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: 98f7620 ("compat: Cleanup in_compat_syscall() callers")
Reported-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Dmitry Safonov <dima@arista.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20191121000303.126523-1-dima@arista.com
  • Loading branch information
Dmitry Safonov authored and Thomas Gleixner committed Nov 21, 2019
1 parent af42d34 commit 7b84744
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion kernel/time/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7b84744

Please sign in to comment.