Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6468335ybi; Mon, 8 Jul 2019 03:33:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqwZanU02eGwn+r6qBJzVqC8bS8M1qFX3NBqZB6uEh9HK51gKesBZtR7sz+EzNRa6xCMzqTY X-Received: by 2002:a17:90a:9a83:: with SMTP id e3mr23967398pjp.105.1562582015942; Mon, 08 Jul 2019 03:33:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562582015; cv=none; d=google.com; s=arc-20160816; b=fs8Vtyfw+GxYMEnQB4AQ6qVZij74EKQyP3oC4f2FXwO+2CDTXoGYZIRZlh8sohI6MI /opBgVselNdv6xOKXHWbGAf9203kMzTTSsYWehaQyL87z1DG6Aaczzks+LJW+9MDfZJC wzpNpAh8su/FancqCtK2sG0A2PpmntGyJlZdXwYf7zr+Cgf7hvbaP7GCWF1E06kUbODl Z8ynnkOUJF/2HJbow8KinmWbHxsxWFRHWPVv2MTZnpwofFhfZZYRhuF81jK78OnDNAPZ Hul9JKFugBmVcviDraa1ngs/9TAyNGMHEAWb6y/MXKRAxa2vMZUzwa9wOJxIe7rdEND0 7OKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:to :from; bh=iwX6J9f512HkMf7TWafqSKFli5QPOpKSHLNtfTyPVIw=; b=v74HM5tpllzeYxsqMs65C5+0d8F3YtadGTOf2c6c3PEhG2tmCmJaUuanslhPTFXaXw mv7PzWuHtHv7FZtMxgoIJT36qBlUwosS2OiWBadIIVzMyXoBhposljwsTYtE/tFDf7bl dS8U8y3lZKm5JnB8718Qpi7UQsaLgDvc3ctebe8oaE9OoWrghPBsrbP7yNSRBVw6MQRd q8K8JijEy9nZS+uKNXRTnHvsexJPw3ncjBA5801iTKOI5IkD6s/1PI36DHgk56CoAQaX 2jYNp67NrQhrLrYAKvnMZjw5+hTBW/s9A7kYvByZ7qA9wU+PMJFXwC6/fOj+pSbpg5Ml 6iIQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b5si19100993pfd.273.2019.07.08.03.33.20; Mon, 08 Jul 2019 03:33:35 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729502AbfGHHtf (ORCPT + 99 others); Mon, 8 Jul 2019 03:49:35 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:35484 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725872AbfGHHtf (ORCPT ); Mon, 8 Jul 2019 03:49:35 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id DAE34D9C0EAD6C991DD0; Mon, 8 Jul 2019 15:49:32 +0800 (CST) Received: from RH5885H-V3.huawei.com (10.90.53.225) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.439.0; Mon, 8 Jul 2019 15:49:22 +0800 From: ZhangXiaoxu To: , , , , Subject: [PATCH] time: Validate the usec before covert to nsec in do_adjtimex Date: Mon, 8 Jul 2019 15:55:04 +0800 Message-ID: <1562572504-142115-1-git-send-email-zhangxiaoxu5@huawei.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.90.53.225] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When covert the usec to nsec, it will multiple 1000, it maybe overflow and lead an undefined behavior. For example, users may input an negative tv_usec values when call adjtimex syscall, then multiple 1000 maybe overflow it to a positive and legal number. So, we should validate the usec before coverted it to nsec. Signed-off-by: ZhangXiaoxu --- kernel/time/timekeeping.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 44b726b..e5c1d00 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1272,9 +1272,6 @@ static int timekeeping_inject_offset(const struct timespec64 *ts) struct timespec64 tmp; int ret = 0; - if (ts->tv_nsec < 0 || ts->tv_nsec >= NSEC_PER_SEC) - return -EINVAL; - raw_spin_lock_irqsave(&timekeeper_lock, flags); write_seqcount_begin(&tk_core.seq); @@ -2321,6 +2318,9 @@ int do_adjtimex(struct __kernel_timex *txc) if (txc->modes & ADJ_SETOFFSET) { struct timespec64 delta; + + if (txc->time.tv_usec < 0 || txc->time.tv_usec >= USEC_PER_SEC) + return -EINVAL; delta.tv_sec = txc->time.tv_sec; delta.tv_nsec = txc->time.tv_usec; if (!(txc->modes & ADJ_NANO)) -- 2.7.4