Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp123432pxx; Mon, 26 Oct 2020 05:03:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzm0ffxhb3LH4N7cmGr3tXtSzoWUCOd/XvU8hw3s+ENNUEIJofPtjZXtZsODJVPzAqa1/Wx X-Received: by 2002:a17:906:6a8b:: with SMTP id p11mr15737651ejr.470.1603713796544; Mon, 26 Oct 2020 05:03:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603713796; cv=none; d=google.com; s=arc-20160816; b=M1pzJjLdPLCnoQgR8LSrf2t4X8ED+1Ucx2YEvgJbAw5uvkAvsLJCgzf7YilywWwhcq G1+WUJSN6qNeRKuSoD93RTLnaYsrqd1h8Ui20V8ekxJqdmrkatOdd9Rg2m+4yXMTSUI5 5XhTxpEkLBEQHFP7ym7YuyrQFBxO8lcjzbTOOub9rcfvSbp591QhogV+K2Hg6Dv68qS7 a4UW0uM43Nm1BfjuEJrdNHwvCIf1tyAobbIEBHI5nLIodfKJwaQaIu6jxLoK6w0otBdA tQRMscMO7z1cLT7yyf5Jiy6pGyANJaAyS07QzW+z/dl3F7NLo6ZBb8dUyGsL5bNPIPc0 d9/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=qAT90Ww8AO0M+YiJyfFcemR1v6O5CkiPMwWvyQYV/fY=; b=GxdtH9FO+UTm6PTG7xFiyzje4vWq8oKcQsontHROvQ6pkFZW0SnDO6AwhqQd0tOmtx ygJ11h6/waClQPkmLnCN+LXYnfFELI2N6sOikwxGTn3l02TLn6WyVQUhiFuQxU9bWixK 77gYuzQw3wCvRZgr8GIgVyC5ynLScRZbsX8lzTrzBYjyYBpXHA6DFtcBgqCiPeI62ZFP sTucfRsKdX5aADNH5fEQ3ngf/DHSFjIRp4gbZ/IhBaUWBvW/Oc5nLAlTAnVrOE0+j6DP n8r9XuuTG4ecHpf0R3UxkdI4s/IWzKck4dV/w8LyLM72FdQC1SGWrczh2Q7/rhQtvU4T l8rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JI5VgPrl; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d19si7217134ejp.485.2020.10.26.05.02.53; Mon, 26 Oct 2020 05:03:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JI5VgPrl; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1771770AbgJZKvG (ORCPT + 99 others); Mon, 26 Oct 2020 06:51:06 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:39090 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1770960AbgJZKvF (ORCPT ); Mon, 26 Oct 2020 06:51:05 -0400 Date: Mon, 26 Oct 2020 10:51:01 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1603709462; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qAT90Ww8AO0M+YiJyfFcemR1v6O5CkiPMwWvyQYV/fY=; b=JI5VgPrlb2sTVfT/EimV2Coyich9hMADy/nTs8fJ0wSeBt6g6kgFuvS4BrThrly+nihtjQ rhvbypVaCm5OEE3UanpOVdBWg5a+jR9SMCnMfAo59UTRF1I3JcuGZfr4uyhwKVov83tYK+ Ca9XdnPF6wKGgsMbHCcr0R3CXoJdcf3JKcFde/qYrettkSKEoXxMJhROFPWUyujJmIuaM0 /ntZWqhnt0XMxzEm1etYlUxwh3f/kfmNH/Sv9q4PCosTzExDJ8WOE23naogACZpNIb59HU /soV9A73uxCc4Tz9UcDzYPOOF4JA7wsGlYnbpbkuqyXrnC2pKSi6PRuAyAiIMw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1603709462; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qAT90Ww8AO0M+YiJyfFcemR1v6O5CkiPMwWvyQYV/fY=; b=/EyD07S9+m1wwo4b3U5xNZT8cbgDs5As2B7r9hqv9utfobVOpsUCcNFT39wM1fuwc0Ctp3 O0XbT5N76ZQufhAQ== From: "tip-bot2 for Zeng Tao" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/urgent] time: Prevent undefined behaviour in timespec64_to_ns() Cc: Zeng Tao , Thomas Gleixner , Arnd Bergmann , stable@vger.kernel.org, x86 , LKML In-Reply-To: <1598952616-6416-1-git-send-email-prime.zeng@hisilicon.com> References: <1598952616-6416-1-git-send-email-prime.zeng@hisilicon.com> MIME-Version: 1.0 Message-ID: <160370946176.397.12992652264857362737.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the timers/urgent branch of tip: Commit-ID: cb47755725da7b90fecbb2aa82ac3b24a7adb89b Gitweb: https://git.kernel.org/tip/cb47755725da7b90fecbb2aa82ac3b24a7adb89b Author: Zeng Tao AuthorDate: Tue, 01 Sep 2020 17:30:13 +08:00 Committer: Thomas Gleixner CommitterDate: Mon, 26 Oct 2020 11:48:11 +01:00 time: Prevent undefined behaviour in timespec64_to_ns() 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 Signed-off-by: Thomas Gleixner Reviewed-by: Arnd Bergmann Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/1598952616-6416-1-git-send-email-prime.zeng@hisilicon.com --- include/linux/time64.h | 4 ++++ kernel/time/itimer.c | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/linux/time64.h b/include/linux/time64.h index c9dcb3e..5117cb5 100644 --- a/include/linux/time64.h +++ b/include/linux/time64.h @@ -124,6 +124,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 ca4e6d5..00629e6 100644 --- a/kernel/time/itimer.c +++ b/kernel/time/itimer.c @@ -172,10 +172,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 = timespec64_to_ns(&value->it_value); ninterval = timespec64_to_ns(&value->it_interval);