Patch "time: Prevent undefined behaviour in timespec64_to_ns()" has been added to the 5.4-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    time: Prevent undefined behaviour in timespec64_to_ns()

to the 5.4-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     time-prevent-undefined-behaviour-in-timespec64_to_ns.patch
and it can be found in the queue-5.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 1576034634512ab27c2c2fefccd454a66ef4b9c1
Author: Zeng Tao <prime.zeng@xxxxxxxxxxxxx>
Date:   Tue Sep 1 17:30:13 2020 +0800

    time: Prevent undefined behaviour in timespec64_to_ns()
    
    [ Upstream commit cb47755725da7b90fecbb2aa82ac3b24a7adb89b ]
    
    UBSAN reports:
    
    Undefined behaviour in ./include/linux/time64.h:127:27
    signed integer overflow:
    17179869187 * 1000000000 cannot be represented in type 'long long int'
    Call Trace:
     timespec64_to_ns include/linux/time64.h:127 [inline]
     set_cpu_itimer+0x65c/0x880 kernel/time/itimer.c:180
     do_setitimer+0x8e/0x740 kernel/time/itimer.c:245
     __x64_sys_setitimer+0x14c/0x2c0 kernel/time/itimer.c:336
     do_syscall_64+0xa1/0x540 arch/x86/entry/common.c:295
    
    Commit bd40a175769d ("y2038: itimer: change implementation to timespec64")
    replaced the original conversion which handled time clamping correctly with
    timespec64_to_ns() which has no overflow protection.
    
    Fix it in timespec64_to_ns() as this is not necessarily limited to the
    usage in itimers.
    
    [ tglx: Added comment and adjusted the fixes tag ]
    
    Fixes: 361a3bf00582 ("time64: Add time64.h header and define struct timespec64")
    Signed-off-by: Zeng Tao <prime.zeng@xxxxxxxxxxxxx>
    Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
    Reviewed-by: Arnd Bergmann <arnd@xxxxxxxx>
    Cc: stable@xxxxxxxxxxxxxxx
    Link: https://lore.kernel.org/r/1598952616-6416-1-git-send-email-prime.zeng@xxxxxxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/include/linux/time64.h b/include/linux/time64.h
index 19125489ae948..5eab3f2635186 100644
--- a/include/linux/time64.h
+++ b/include/linux/time64.h
@@ -132,6 +132,10 @@ static inline bool timespec64_valid_settod(const struct timespec64 *ts)
  */
 static inline s64 timespec64_to_ns(const struct timespec64 *ts)
 {
+	/* Prevent multiplication overflow */
+	if ((unsigned long long)ts->tv_sec >= KTIME_SEC_MAX)
+		return KTIME_MAX;
+
 	return ((s64) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec;
 }
 
diff --git a/kernel/time/itimer.c b/kernel/time/itimer.c
index 77f1e5635cc18..62dc9757118c6 100644
--- a/kernel/time/itimer.c
+++ b/kernel/time/itimer.c
@@ -147,10 +147,6 @@ static void set_cpu_itimer(struct task_struct *tsk, unsigned int clock_id,
 	u64 oval, nval, ointerval, ninterval;
 	struct cpu_itimer *it = &tsk->signal->it[clock_id];
 
-	/*
-	 * Use the to_ktime conversion because that clamps the maximum
-	 * value to KTIME_MAX and avoid multiplication overflows.
-	 */
 	nval = ktime_to_ns(timeval_to_ktime(value->it_value));
 	ninterval = ktime_to_ns(timeval_to_ktime(value->it_interval));
 



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux