From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752982AbbLFJH4 (ORCPT ); Sun, 6 Dec 2015 04:07:56 -0500 Received: from www.linutronix.de ([62.245.132.108]:54545 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752480AbbLFJHu (ORCPT ); Sun, 6 Dec 2015 04:07:50 -0500 Date: Sun, 6 Dec 2015 10:07:01 +0100 (CET) From: Thomas Gleixner To: Sasha Levin cc: john.stultz@linaro.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] time: verify time values in adjtimex ADJ_SETOFFSET to avoid overflow In-Reply-To: <56637E2D.1040603@oracle.com> Message-ID: References: <1449198571-21133-1-git-send-email-sasha.levin@oracle.com> <56637E2D.1040603@oracle.com> User-Agent: Alpine 2.11 (DEB 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 5 Dec 2015, Sasha Levin wrote: > On 12/05/2015 12:10 PM, Thomas Gleixner wrote: > > On Thu, 3 Dec 2015, Sasha Levin wrote: > > > >> Make sure the tv_usec makes sense. We might multiply them later which can > >> cause an overflow and undefined behavior. > >> > >> Signed-off-by: Sasha Levin > >> --- > >> kernel/time/timekeeping.c | 4 ++++ > >> 1 file changed, 4 insertions(+) > >> > >> diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c > >> index d563c19..aa3c1c2 100644 > >> --- a/kernel/time/timekeeping.c > >> +++ b/kernel/time/timekeeping.c > >> @@ -1987,6 +1987,10 @@ int do_adjtimex(struct timex *txc) > >> > >> if (txc->modes & ADJ_SETOFFSET) { > >> struct timespec delta; > >> + > >> + if (txc->time.tv_usec >= USEC_PER_SEC || txc->time.tv_usec <= -USEC_PER_SEC) > >> + return -EINVAL; > > > > That's not a canonical timeval. timeval_valid() is what you want to > > check it. Or has adjtimex some magic exception here? > > Nope, it looks like timeval_valid() is indeed what I've needed to use. > > Is there a reason ntp_validate_timex() doesn't do timeval_valid() too > for at least the ADJ_SETOFFSET case? If not, I'll add it in. Not that I know, but John might have some opinion on that. Thanks, tglx