Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6756872ybi; Mon, 8 Jul 2019 08:09:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqyT6NBqSFF4wCN9jn4b29i2e4D0YFo9HjbY8KSGA2mKg/tBXoNhogMTl+Ec6DFdv0zq/Cmz X-Received: by 2002:a17:90a:db44:: with SMTP id u4mr26278019pjx.52.1562598590427; Mon, 08 Jul 2019 08:09:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562598590; cv=none; d=google.com; s=arc-20160816; b=SMdHljQDoJS/0yUvZ//U6A37mFCFP9Fv9K1dhlWnJ/eM79IDE5UKTqGAA8OIPWIY9O QvtjHlkMQaEb4xIrJY9VGNAg0vv15tisD05F8s8RWk6nvIvcKPgRNxUbR1e1z5xsclX9 m5enXE1S0mZ0/90Ma30FdYKCXg1JfngUcCpe4BUYI1kOL6qBV1Bt06Y6T3xY3I1ur/I5 pxP2bkSd/qF+21R83sM38hCjsERvxD609VVfze81lm11NTpa6NXIGDWtzGrt7OYglyw0 0isSq5vitiHeTrmUpcmS0iZnyP5J5n7ZVCO8PrQmut8WhGPVIOLK2F+bYSszgPmRmTKT /ggw== 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=hjINrR7+D/PactNLlW2FUtivaqhsKemhzK1ixC04x8U=; b=sFzODt1LXphZDmKKXJXzAVpGRzcrRNuLznDUUJxiQDDwblJBlPL3VYuGW+jGnpmpIF 5YZ1aFOScSpc2hfGG9h9UNhc9GRuvZ3T7kVfMcWemNOMOyah1ObIcZN0D9xr3eUlmL3l 3SWvBo3n7g2Y3cQRu5MRySB8CoxxOpecjlB80th3hx8qdP4VAd/6eTCVR7R25iBvJZjQ QBUkhPckLmn+uDDJ7MMlgEh/zT5i/CzoIb3DWjxyxWLgTS1B3czTQ2WM03jX+o85Z1wp J9WxNaFzTCHq0XJQclyiuhEfqGMMbAcO0NTPEnBuCbE+u3/j8GiY3pXMyL3bN20NE8e5 G+9w== 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 j63si18300966pgc.185.2019.07.08.08.09.29; Mon, 08 Jul 2019 08:09:50 -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 S1730074AbfGHKhT (ORCPT + 99 others); Mon, 8 Jul 2019 06:37:19 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2176 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725836AbfGHKhT (ORCPT ); Mon, 8 Jul 2019 06:37:19 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id CBFA153E121B75549102; Mon, 8 Jul 2019 18:37:16 +0800 (CST) Received: from RH5885H-V3.huawei.com (10.90.53.225) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.439.0; Mon, 8 Jul 2019 18:37:07 +0800 From: ZhangXiaoxu To: , , , , Subject: [v2] time: Validate the usec before covert to nsec in do_adjtimex Date: Mon, 8 Jul 2019 18:42:48 +0800 Message-ID: <1562582568-129891-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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 44b726b..778796d 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -2321,6 +2321,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