linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] time: Zerofy padding in __kernel_timespec on 32-bit
@ 2019-11-21  0:03 Dmitry Safonov
  2019-11-21  0:23 ` [tip: timers/urgent] time: Zero the upper 32-bits " tip-bot2 for Dmitry Safonov
  2019-11-21  9:06 ` [PATCH] time: Zerofy padding " Arnd Bergmann
  0 siblings, 2 replies; 3+ messages in thread
From: Dmitry Safonov @ 2019-11-21  0:03 UTC (permalink / raw)
  To: linux-kernel
  Cc: Dmitry Safonov, Dmitry Safonov, Ben Hutchings, Arnd Bergmann,
	John Stultz, Stephen Boyd, Thomas Gleixner, y2038, stable

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.

Reported-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Fixes: 98f76206b335 ("compat: Cleanup in_compat_syscall() callers")
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Ben Hutchings <ben.hutchings@codethink.co.uk>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Stephen Boyd <sboyd@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: y2038@lists.linaro.org
Cc: stable@vger.kernel.org # v4.20+
Signed-off-by: Dmitry Safonov <dima@arista.com>
---
 kernel/time/time.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/time/time.c b/kernel/time/time.c
index 5c54ca632d08..1cb045c5c97e 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -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;
-- 
2.24.0


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

* [tip: timers/urgent] time: Zero the upper 32-bits in __kernel_timespec on 32-bit
  2019-11-21  0:03 [PATCH] time: Zerofy padding in __kernel_timespec on 32-bit Dmitry Safonov
@ 2019-11-21  0:23 ` tip-bot2 for Dmitry Safonov
  2019-11-21  9:06 ` [PATCH] time: Zerofy padding " Arnd Bergmann
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Dmitry Safonov @ 2019-11-21  0:23 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Ben Hutchings, Dmitry Safonov, Thomas Gleixner, stable, x86, LKML

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 <dima@arista.com>
AuthorDate:    Thu, 21 Nov 2019 00:03:03 
Committer:     Thomas Gleixner <tglx@linutronix.de>
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.

Fixes: 98f76206b335 ("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
---
 kernel/time/time.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/time/time.c b/kernel/time/time.c
index 5c54ca6..83f403e 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -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;

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

* Re: [PATCH] time: Zerofy padding in __kernel_timespec on 32-bit
  2019-11-21  0:03 [PATCH] time: Zerofy padding in __kernel_timespec on 32-bit Dmitry Safonov
  2019-11-21  0:23 ` [tip: timers/urgent] time: Zero the upper 32-bits " tip-bot2 for Dmitry Safonov
@ 2019-11-21  9:06 ` Arnd Bergmann
  1 sibling, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2019-11-21  9:06 UTC (permalink / raw)
  To: Dmitry Safonov
  Cc: linux-kernel, Dmitry Safonov, Ben Hutchings, John Stultz,
	Stephen Boyd, Thomas Gleixner, y2038 Mailman List, # 3.4.x

On Thu, Nov 21, 2019 at 1:03 AM Dmitry Safonov <dima@arista.com> wrote:
>
> 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.
>
> Reported-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
> Fixes: 98f76206b335 ("compat: Cleanup in_compat_syscall() callers")

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

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

end of thread, other threads:[~2019-11-21  9:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-21  0:03 [PATCH] time: Zerofy padding in __kernel_timespec on 32-bit Dmitry Safonov
2019-11-21  0:23 ` [tip: timers/urgent] time: Zero the upper 32-bits " tip-bot2 for Dmitry Safonov
2019-11-21  9:06 ` [PATCH] time: Zerofy padding " Arnd Bergmann

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).