Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6771774ybi; Mon, 8 Jul 2019 08:24:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqwFoNGlyWTI5Dn8cMxoaWqM0ii3wAXM6hvGtHKxtjbE0lOJ737crgvZ1eQ28JkfWYJNtBjh X-Received: by 2002:a17:902:8a94:: with SMTP id p20mr25446481plo.312.1562599468546; Mon, 08 Jul 2019 08:24:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562599468; cv=none; d=google.com; s=arc-20160816; b=tciLepemr12xq2Uu2v/91aDJHoaphmd+HCZgoOCLeT+8cB2FwSSJDUyfovZcxap8NE vtYOLzwBR5EVjKlrMHhRZubzgRWlxRnqeiWMCjpW0DSv7SYvm5UmTbrUyGmL1H8SY7Fo SSK+aeg6VzRmR7MsfiQTJEOf+Hae99ePdWy8l+hOvOIQIp4I3H8RA6Pbn/I3xgNzcC0Q 4M7OKfMQoADuuUx0A0Sr7k2q7hanMpGuxlnSZL1q4pibwp0mU07Eo1l6j9bCEPGQN6vz WWGqyx+c3jNaC0vhWWkSORgC02ctxYhYh+1S+BLa3g1Xqocla6ugX09wFwrZ7rl1W2Y1 E71Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=MKWX5A7Ay1QLkHFVoKkqfr1CRzJbNqQdxDq7U5Vma0g=; b=YkGUbXG0yFABL+8F68g6uQomsX6venXeVMU57iMYA5Tw4Ps0rsdXp7x8+4hGMx7zTk pRF/3XgIXjmxhivDgn8JX9mAzfNm1DIWvVLv+xS+Ihw6a0HkTcpPHOEAieBuIBlzjyi2 7YDbSsmcwHtjFhgLvck+rNCZbCkydXPKnbiOAyy743FkbCt1BV0vRO72znU5D9jLRd6o anX2NzJL/ycxdm+ChZaioIxlPmpMzRxvb+Y0UK41bmUjKPnqnqH1xTVxz8v4yj3V/+DK mWLqLgIToTEgERZKp4ODzHJ3NK2ojpzNyE4wGQ+KQurhhxv24If+5wIH0HuzDbFmycKK pPNA== 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 s7si17768898plp.66.2019.07.08.08.24.13; Mon, 08 Jul 2019 08:24:28 -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 S1731247AbfGHNeX (ORCPT + 99 others); Mon, 8 Jul 2019 09:34:23 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2239 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729708AbfGHNeX (ORCPT ); Mon, 8 Jul 2019 09:34:23 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 4101690DED667519EBA2; Mon, 8 Jul 2019 21:34:17 +0800 (CST) Received: from [127.0.0.1] (10.184.189.120) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.439.0; Mon, 8 Jul 2019 21:34:15 +0800 Subject: Re: [v2] time: Validate the usec before covert to nsec in do_adjtimex To: Thomas Gleixner CC: , , References: <1562582568-129891-1-git-send-email-zhangxiaoxu5@huawei.com> From: "zhangxiaoxu (A)" Message-ID: <5fcccfec-cd51-02d5-d096-5a14675c2132@huawei.com> Date: Mon, 8 Jul 2019 21:33:50 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.184.189.120] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ?? 2019/7/8 21:04, Thomas Gleixner ะด??: > On Mon, 8 Jul 2019, ZhangXiaoxu wrote: > >> 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. > > Looking deeper before applying it. That change is wrong for two reasons: > > 1) The value is already validated in timekeeping_validate_timex() > > 2) The tv_usec value can legitimately be >= USEC_PER_SEC if the ADJ_NANO > mode bit is set. See timekeeping_validate_timex() and the code you > actually modified: > Yes, you are right. This actually found in an old version, and doesn't check more detail on mainline. Thank you very much. >> 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)) > delta.tv_nsec *= 1000; > > The multiplication is conditional .... > > Thanks, > > tglx > > > > . >