From patchwork Tue Nov 17 13:04:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 324581 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp4153029ils; Tue, 17 Nov 2020 05:08:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJyBb8XLqtKGchEZlkolhMRzMQJ/53awXmCX0o2GkJC026PEKuDKCc30KEk4H1FtW9QFFApr X-Received: by 2002:a50:8b65:: with SMTP id l92mr20846965edl.132.1605618502024; Tue, 17 Nov 2020 05:08:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605618502; cv=none; d=google.com; s=arc-20160816; b=NggtEpeLkG147nztgxPXFmRbApe3Upc3p+cFkAu7iTS61QXsQcS/cOZjFZcTtWhanG ggXPxZtRUv+/knbp+ooNlvNhksiTVcLW0JRJlNca2/DfXPqNVBC0eB/nULyM04VjviKK digaHKOB9FCVFwTV0UoB6CatlsA4H53jBTytDkTV65dl46zTv9DGOuY3p1+kiCC4q6T7 KU9LuL73MUwxBHtjnJ+QZSGfmKEot9oFm4wqwDT+XIVvnHkGZuju/G+FGAGrqrGKMMoF pmNqMmaTdJDXhpEeAh1zCJhrePOxyFnKQcuWlc673PLETu9WcCzWxgc583sQs1sgUXIE BawA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZDfjViKP3vJnL0vKhkh48T66vyQQrx21vQpt/mQBkIw=; b=L3xgIP/cvrR9vAM+K7DMRIafjphPseyQ6eBaUWneDuB5fhZNstz5UU75JNPgrdFjlh 0DuPN9V7cILZS2m7lfo1v4zoxZffPCCyJw4rlgK/2s3wKkZwUYMgo/hqauiAPvE0CmkB M5R/W9Hq+82+LoWhxHwaPL1K+668/r2QssbOjnH1l0T9AeE5Ev2a021LKkLcxlYfyl5S 0t9g73lWJjbzBLb8lvpqiC/nygoMMhh3xgfWxWpbcH4SmcwdiN0p/Y2Bkh7K5ZjA+sTc 2Fv8ZmfLCIfP2jmKIxE5m4Ww04m1Vppk/a3ejr5lAe5MTRtxB9SJl5eCp5ARFzW+53C3 zGqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=17GCvp9a; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r21si13835360edx.421.2020.11.17.05.08.21; Tue, 17 Nov 2020 05:08:22 -0800 (PST) Received-SPF: pass (google.com: domain of stable-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=@kernel.org header.s=default header.b=17GCvp9a; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729039AbgKQNHJ (ORCPT + 14 others); Tue, 17 Nov 2020 08:07:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:33846 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729034AbgKQNHG (ORCPT ); Tue, 17 Nov 2020 08:07:06 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 89B3E2465E; Tue, 17 Nov 2020 13:07:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605618426; bh=+ik/dmEYMup5DcNgxfoB/2tUIfGLVh9dNRL1JaFZg3s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=17GCvp9aSqail48snOjdLyXXKuX14ddOOMXtFCWGtJPXSaGL5RLjS4Ro8aWzoWgHv aLjAdglXvDXcJkLOkkmsm5YOIzqXH6yyFb3KJeSBSqPpJg1T+biMORuLrcR7ntA4vA f5W4grdzUtF+2IAaNpG1SGWb+W8bWrAj79sq2+wg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zeng Tao , Thomas Gleixner , Arnd Bergmann , Sasha Levin Subject: [PATCH 4.4 04/64] time: Prevent undefined behaviour in timespec64_to_ns() Date: Tue, 17 Nov 2020 14:04:27 +0100 Message-Id: <20201117122106.344550754@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122106.144800239@linuxfoundation.org> References: <20201117122106.144800239@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Zeng Tao [ 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 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 Signed-off-by: Sasha Levin --- include/linux/time64.h | 4 ++++ 1 file changed, 4 insertions(+) -- 2.27.0 diff --git a/include/linux/time64.h b/include/linux/time64.h index 367d5af899e81..10239cffd70f8 100644 --- a/include/linux/time64.h +++ b/include/linux/time64.h @@ -197,6 +197,10 @@ static inline bool timespec64_valid_strict(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; }