From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756693AbbLHACq (ORCPT ); Mon, 7 Dec 2015 19:02:46 -0500 Received: from mail-qk0-f174.google.com ([209.85.220.174]:33481 "EHLO mail-qk0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755309AbbLHACp (ORCPT ); Mon, 7 Dec 2015 19:02:45 -0500 MIME-Version: 1.0 In-Reply-To: <1449175608-1146-1-git-send-email-sasha.levin@oracle.com> References: <1449175608-1146-1-git-send-email-sasha.levin@oracle.com> Date: Mon, 7 Dec 2015 16:02:44 -0800 Message-ID: Subject: Re: [PATCH] ntp: verify offset doesn't overflow in ntp_update_offset From: John Stultz To: Sasha Levin Cc: Thomas Gleixner , lkml Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 3, 2015 at 12:46 PM, Sasha Levin wrote: > We need to make sure that the offset is valid before manipulating it, > otherwise it might overflow on the multiplication. > > Signed-off-by: Sasha Levin > --- > kernel/time/ntp.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c > index 149cc80..36616c3 100644 > --- a/kernel/time/ntp.c > +++ b/kernel/time/ntp.c > @@ -297,6 +297,9 @@ static void ntp_update_offset(long offset) > if (!(time_status & STA_PLL)) > return; > > + /* Make sure the multiplication below won't overflow */ > + offset = clamp(offset, -MAXPHASE, MAXPHASE); > + > if (!(time_status & STA_NANO)) > offset *= NSEC_PER_USEC; So looking at this a bit closer, this bit looks sort of crazy since we clam the offset, do the multiply and then do the exact same clamp. I'd much rather do a more logical clamp(offset, -USEC_PER_SEC, USEC_PER_SEC), but only in the case where we do the multiply. Any objection to that? thanks -john