Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4947147ybi; Sat, 6 Jul 2019 17:46:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqxS/uVYq38Honv9ZJKXSVZ93X6A4XZeuTYV94BXft5e+G6ziV2tWCXisYXZFEhuxIH1Zwvc X-Received: by 2002:a63:d002:: with SMTP id z2mr13850569pgf.364.1562460401713; Sat, 06 Jul 2019 17:46:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562460401; cv=none; d=google.com; s=arc-20160816; b=x0BrXXA2Ee2Gr/2oeqwLH78GHN+17eBgy9XjGpbSDHlIM5dMIWvNgOunBG6mx9HLMt depHHCIGoFN6N/Ee7OYSGIY6Wr3YqG3vd+mmAnRbmk7YhqZZiI9NouOK/yt1gcnUTgmR R0+49skNAbv0vEJXmFJ0ljGyVYn2u9ste0ymVrB4egIAHa9CH2K3L7fuPFd53NfzNX4E UuPBgzEp8SHuNSvRwIE/731Ax3s7mnL5VqlvKnUp8X9MVysBS5hZcTJIEfeya3B2kG// qWBpjejMl5AWLKBf6Hh5rOJ7fkLoYuZ4AkTIVb0Kc8+BWN1xnE4IDPlPWwpbPTDkBvla yllw== 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:cc :to:from; bh=C5MGK+UdIk/JBsZBJSKTgDaN2TE18wkV/C45Xof7koA=; b=RuD/uhxIYWZuNJOsS0AlqjABGJtIMDFcHfTbZ3m8qIKsWQUH/qKq4N0Rg2dUZjoors xMQ4ch12ddYdgNL/MqhLHkTrAHs+roNAN4FGcswDDfeCZANLcxatVKU8U9OmtJk7Xatd WGLD36PjotQbSt8pHXgpEUJq09QJ0lZAmqatZ0wtqud0S1nzo5wBIDBJ4OZvo6J8udv5 R5ltvTldjDQpu8LcZaNr7zQsj+xk/TxQlw5m7NTERffSFkrUNisW+rGKGGT/xHmLzJZZ OkXs3Ui70V/pE+umDVAL4PlzLj8CIMLkTdlXKCRXKRIkXT3U1MUlkgOH2cO2WyExrkgJ SniQ== 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 91si12726554ply.196.2019.07.06.17.46.25; Sat, 06 Jul 2019 17:46:41 -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 S1727071AbfGGAqG (ORCPT + 99 others); Sat, 6 Jul 2019 20:46:06 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2234 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726966AbfGGAqG (ORCPT ); Sat, 6 Jul 2019 20:46:06 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 0E65DD218EFFAD6451C1; Sun, 7 Jul 2019 08:46:04 +0800 (CST) Received: from huawei.com (10.90.53.225) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.439.0; Sun, 7 Jul 2019 08:45:55 +0800 From: zhengbin To: , , , CC: , Subject: [PATCH v2] time: compat settimeofday: Validate the values of tv from user Date: Sun, 7 Jul 2019 08:51:41 +0800 Message-ID: <1562460701-113301-1-git-send-email-zhengbin13@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 Similar to commit 6ada1fc0e1c4 ("time: settimeofday: Validate the values of tv from user"), 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 --- kernel/time/time.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/time/time.c b/kernel/time/time.c index 7f7d691..5c54ca6 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; } -- 2.7.4