Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp3969293imb; Wed, 6 Mar 2019 01:56:40 -0800 (PST) X-Google-Smtp-Source: APXvYqxGUl7pIHvh8Vr/sEsNw+gbMXMTl5VDSK+PQ8UunEh+zF6dVCyGyIq/gO3zNJi5MjgxDO9p X-Received: by 2002:a63:b14d:: with SMTP id g13mr5593261pgp.270.1551866200228; Wed, 06 Mar 2019 01:56:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551866200; cv=none; d=google.com; s=arc-20160816; b=C6CfCtgctabbZJDG+iYp+3yyPX1/0Fvtbviv9araPFMAh6UZUUgPZlqb1uRJY2W0NI l1i2H8s0e4CBVJu1U238X6eNNbqOtFZU9jbRhBwm40eCYsmPxHYj0EOix0RS8KM3xqiG 9J0rn7WTE7GbI0G3JQbpHqu7jAKaF2Viw057PHl8bcv2/4iw/UXJ0zcDe+HkWBm7r7a8 UdY3FRVkNXhrKMDj7x7Rv6XEjasjLvTw+6tlgmbcei6iTj+NIFrefDmWnZvH5ZgNQpek HrhO1zOQqN82611XuqcjICvskzIyCmpmo2+h1UChZ+X9HcMQMHy2DGghT9047wPSh5Sw i8rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=6BcVeV6Sp2utn9aWCzOGmh8SXt9Pr3Q58KuL3noFWNw=; b=D1GUZxrDWazU0T6POM7XLCabh3ZzPPo3Axa89WOWiGHEuAxt/93wB5dheg3K9CidtY MPNw3jHtOFQx+YoAgbqPg8nJph5/bdQDtZpiCdRiFZOv+eiZvPO1xTv+dru+5m/mN3kh ViawUCLw8CSyeXOLKnIUetqBE0RYOd9mMaSMXSHGCniUq2tYkYDd0yRqdi9WowmOhBbS 0AG4af/ii2K5/V746voRj3O6Hn4qIpWnQwV255VcAbaLzO+rE6YVj2KFIVJpoTNKio89 gLXvKTl511oRtmYx9QWvY/B1Uf1fQARSiRzRimLdMACP5ifYPA0C0UBpFjYFe+NchdKs hqOw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b64si1064199pgc.218.2019.03.06.01.56.24; Wed, 06 Mar 2019 01:56:40 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729791AbfCFJyp (ORCPT + 99 others); Wed, 6 Mar 2019 04:54:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33509 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726596AbfCFJyp (ORCPT ); Wed, 6 Mar 2019 04:54:45 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8B1263091753; Wed, 6 Mar 2019 09:54:45 +0000 (UTC) Received: from localhost (holly.tpb.lab.eng.brq.redhat.com [10.43.134.11]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5772D5D6A9; Wed, 6 Mar 2019 09:54:44 +0000 (UTC) Date: Wed, 6 Mar 2019 10:54:42 +0100 From: Miroslav Lichvar To: John Stultz Cc: Xiongfeng Wang , Thomas Gleixner , Stephen Boyd , lkml Subject: Re: [RFC PATCH] ntp: Avoid undefined behaviour in second_overflow() Message-ID: <20190306095442.GM21520@localhost> References: <1551835710-53773-1-git-send-email-wangxiongfeng2@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 06 Mar 2019 09:54:45 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 05, 2019 at 05:42:25PM -0800, John Stultz wrote: > > --- a/kernel/time/ntp.c > > +++ b/kernel/time/ntp.c > > @@ -677,6 +677,8 @@ static inline void process_adjtimex_modes(const struct timex *txc, s32 *time_tai > > > > if (txc->modes & ADJ_MAXERROR) > > time_maxerror = txc->maxerror; > > + if (time_maxerror > NTP_PHASE_LIMIT) > > + time_maxerror = NTP_PHASE_LIMIT; > > This looks sane to me. > Acked-by: John Stultz > > Though it makes me wonder a bit more about the sanity checking on the > other parameters passed via adjtimex(), tick_usec for instance looks > like it could be similarly problematic. The tick length is checked earlier in timekeeping_validate_timex(), so that should be ok. What I'd like to see clamped is the system time itself. ktime_t overflows on Apr 11 2262. clock_settime() and adjtimex(ADJ_SETOFFSET) can set the time close to the overflow and let everything break. Boot a VM and try this: # date -s 'Apr 11 23:47:15 UTC 2262' There was a patch submitted couple years ago that prevented overflows in 32-bit time_t and ktime_t. http://lkml.iu.edu/hypermail/linux/kernel/1510.0/04719.html -- Miroslav Lichvar