Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6918943ybi; Mon, 8 Jul 2019 10:52:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqwptMcxaMczFLEjfAKijLMkKzOljCdzHqlRXkKbdf3j2sIJ+mbjSJ9gw5UpKrim8+ExC1Ou X-Received: by 2002:a17:90a:db42:: with SMTP id u2mr27509088pjx.48.1562608320136; Mon, 08 Jul 2019 10:52:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562608320; cv=none; d=google.com; s=arc-20160816; b=nJ5Ms5MZHesofFGA78QUqMrgPeSj0QsYiH/wJwgfZfLXZUMpD/B9fwPxAiVp7b+M+e K0f3wLq//HGU2Tg+8KnUKU8+OvsUeJ+xrKqBF1uS0Q9Vo4QYZSoYgNO57Fxmcvh590Xh Ft+lcdsgBzmTa7p53N3h9TOepuoJdcwLXI+LnkdLvQ0Ao3DrN/Im0r+wi+LBWsU1BaR0 Mtovv3iVL2Ob/UQyyclIcJFebLY49bEYOFsog1HkUnFIsdWW5i/jCN5gY1HlXUfSuhuU 2WZ3w/l2VC1LrCs9uq+bVHRSKFIrwIkkoih2o6sTQ8fjPjDHJStSY6l6GHP62cSqoEQs 0XIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=E5g1+PHjLsfoqJHaO2Ozg9iYoL9YIkExiGzhOWiWNKA=; b=rcj6LMhXGK+oaXcbPMORk9KdWUv4te+1zsmUAJq3wyc+8OlPAKF3QexsHgA7MFRzzG K2REEdQkTJ/U6sV6VqcOzlKVU/mu7fz7fQdYiK1GEWhtCs7FRcE/xUMU7ySvkRm4r8dg 2Z1FgYHGaWVXqB1YrTyIyBvqaXKp8Soj9/i462i2iguxUzAKwVqbIzkgjYA5P9wlaJ9v LtZtrTXBjEgHQPP8lKNaUSGEeDB6whNMvHgky0xTnN7wIdO+ZHALQs5bAUVtR0607hVg P1AKoX/F3aB3uoDWNKyDAieZEs2Eaf8d3a7XzXuyWVzs8vtk44vwmyk85xo55pSAmTSF 6Cxg== 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 b25si19754284pgb.121.2019.07.08.10.51.45; Mon, 08 Jul 2019 10:52:00 -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 S1731149AbfGHNEd (ORCPT + 99 others); Mon, 8 Jul 2019 09:04:33 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:39323 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728800AbfGHNEc (ORCPT ); Mon, 8 Jul 2019 09:04:32 -0400 Received: from [5.158.153.52] (helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1hkTJi-0000A0-Ui; Mon, 08 Jul 2019 15:04:27 +0200 Date: Mon, 8 Jul 2019 15:04:21 +0200 (CEST) From: Thomas Gleixner To: ZhangXiaoxu cc: john.stultz@linaro.org, sboyd@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [v2] time: Validate the usec before covert to nsec in do_adjtimex In-Reply-To: <1562582568-129891-1-git-send-email-zhangxiaoxu5@huawei.com> Message-ID: References: <1562582568-129891-1-git-send-email-zhangxiaoxu5@huawei.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: > 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