Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5370114ybi; Sun, 7 Jul 2019 03:46:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqx/NUmxWvV6xUQFd3IFygr48puon8sQ62/WLHHzCRnPxKsVVdqfrNFHoKUmXWukDe5aPsHW X-Received: by 2002:a65:5202:: with SMTP id o2mr14693313pgp.199.1562496387875; Sun, 07 Jul 2019 03:46:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562496387; cv=none; d=google.com; s=arc-20160816; b=ZxOiYDsy36CQ7+pkA0y7hdb46CXHLCJns28CMOQWut1l7QXcmuF74g4go4OT4Uj2yj kiqg+eyzzLwNymUElXmM7LJoxYJWau0xzGw5MOC64x9AgxeAYq7V/vfCakUYKCX71IQH lBnv46FXRccRHz/3T502sWQJ3FnMQe2zBt8E7OMX+HDt5em8BnTAwy8sHUGFTZDLB/BT q9VbPph+SejLP0vl/IhALRTxf7S9tZHfeLiHSGJRthh5BQq+VM7TtyV1mOBY+qUTWLNf M/p25pYaahjyJ7e4x0uKD5rld8D5vmtx3P2ZzZH4rdWKIHSoid49ZoiVEbXCxiRaPlg0 DpZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:dkim-signature:dkim-filter; bh=h6AxCnF8Cy9JvxbrLLPGcxIHpYIAsA8NGwjX/2T0TCA=; b=ZZmEqeACVCHPJsDOOg5s79Sb8Qf3Z8MpFW0uMdO4ipdMR5ceyErdjCp2GGV8IEqvDO WAB6WbisTJd1Dl7hqKScjq1OTml3sOJRxZZVwVKnceXO3grJxnZJEGeql3I2enhjG/TR 6/+MD0LYzt2Xj5sW/63RnzLHwzICBI8JNGFws7L4QR2LxrXZb5nu80XR4rVEoFxYadfI cyusBs/ADU8eoyTLZmuJWF4mGhXXNyKAqxmQY2Rek3KqgMNBVWj5Ba6ajrl6IEzxka1M pg02mcUT/JaIRJVRcLyRnzgsCnUiXi9wNDFGjJ4cD/evPZjP78rTk7X1aPYXVCfFcjN9 1j7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019061801 header.b="ZocZeRO/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w16si13779350plp.329.2019.07.07.03.46.00; Sun, 07 Jul 2019 03:46:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@zytor.com header.s=2019061801 header.b="ZocZeRO/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727322AbfGGKKN (ORCPT + 99 others); Sun, 7 Jul 2019 06:10:13 -0400 Received: from terminus.zytor.com ([198.137.202.136]:58753 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727141AbfGGKKM (ORCPT ); Sun, 7 Jul 2019 06:10:12 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x67AA0Wu879360 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sun, 7 Jul 2019 03:10:01 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x67AA0Wu879360 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019061801; t=1562494201; bh=h6AxCnF8Cy9JvxbrLLPGcxIHpYIAsA8NGwjX/2T0TCA=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=ZocZeRO/C5/UqyHn+1CMBh4ddZ9hqA1l97JNRwkfeyw/m7mgxJ0CzoP1DuUrL1CUL dQxCAduNUMfmQxZb1OERSxf9fRQQa6fOhEuQN3pzRSD5Ly7qUkmgS7gO9WiJyOD81m ErFEMFfTSvk3bVkGiVQm8wYT5NhBeAIddM9fuxpDSQdWK7M/knc5az2Zxuebiwg9fI J6/zsVm/Jo+fqqPsq4GWYZ8s07QWY/E+vtuPbtrhvtoSzWn2K9prbSKuMt2shaE0qB AkyYskedAr5VrTSeZ60Y1RMYLOsaWWcw1yG7pfnJ3sYz/SB+9+snH2VCloDtWEDJyg E9h5QsOSojJAg== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x67AA07K879357; Sun, 7 Jul 2019 03:10:00 -0700 Date: Sun, 7 Jul 2019 03:10:00 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for zhengbin Message-ID: Cc: mingo@kernel.org, tglx@linutronix.de, hpa@zytor.com, linux-kernel@vger.kernel.org, zhengbin13@huawei.com Reply-To: mingo@kernel.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, hpa@zytor.com, zhengbin13@huawei.com In-Reply-To: <1562460701-113301-1-git-send-email-zhengbin13@huawei.com> References: <1562460701-113301-1-git-send-email-zhengbin13@huawei.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:timers/core] time: Validate user input in compat_settimeofday() Git-Commit-ID: 9176ab1b848059a0cd9caf39f0cebaa1b7ec5ec2 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=0.1 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_12_24,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU, DKIM_VALID_EF autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 9176ab1b848059a0cd9caf39f0cebaa1b7ec5ec2 Gitweb: https://git.kernel.org/tip/9176ab1b848059a0cd9caf39f0cebaa1b7ec5ec2 Author: zhengbin AuthorDate: Sun, 7 Jul 2019 08:51:41 +0800 Committer: Thomas Gleixner CommitDate: Sun, 7 Jul 2019 12:05:40 +0200 time: Validate user input in compat_settimeofday() The user value is validated after converting the timeval to a timespec, but for a wide range of negative tv_usec values the multiplication overflow turns them in positive numbers. So the 'validated later' is not catching the invalid input. Signed-off-by: zhengbin Signed-off-by: Thomas Gleixner Link: https://lkml.kernel.org/r/1562460701-113301-1-git-send-email-zhengbin13@huawei.com --- kernel/time/time.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/time/time.c b/kernel/time/time.c index 7f7d6914ddd5..5c54ca632d08 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c @@ -251,6 +251,10 @@ COMPAT_SYSCALL_DEFINE2(settimeofday, struct old_timeval32 __user *, tv, if (tv) { if (compat_get_timeval(&user_tv, tv)) return -EFAULT; + + if (!timeval_valid(&user_tv)) + return -EINVAL; + new_ts.tv_sec = user_tv.tv_sec; new_ts.tv_nsec = user_tv.tv_usec * NSEC_PER_USEC; }