Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755574AbcKOH6v (ORCPT ); Tue, 15 Nov 2016 02:58:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48306 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751668AbcKOH6u (ORCPT ); Tue, 15 Nov 2016 02:58:50 -0500 Subject: Re: [PATCH] time: Avoid signed overflow in timekeeping_delta_to_ns() To: Chris Metcalf , John Stultz , Thomas Gleixner , David Gibson , "Christopher S . Hall" , linux-kernel@vger.kernel.org References: <1479152569-16890-1-git-send-email-cmetcalf@mellanox.com> From: Laurent Vivier Message-ID: <631b2a03-967a-94c1-fbab-4d358257545a@redhat.com> Date: Tue, 15 Nov 2016 08:58:46 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <1479152569-16890-1-git-send-email-cmetcalf@mellanox.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 15 Nov 2016 07:58:50 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1220 Lines: 33 On 14/11/2016 20:42, Chris Metcalf wrote: > This bugfix was originally made in commit 35a4933a8959 ("time: > Avoid signed overflow in timekeeping_get_ns()"). When the code was > refactored in commit 6bd58f09e1d8 ("time: Add cycles to nanoseconds > translation") the signed overflow fix was lost. Re-introduce it. > > Signed-off-by: Chris Metcalf > --- > I happened to be looking for an unrelated fix, found this code, > realized the tip code didn't match the fixed code, and > backtracked to where it had gone away. > > kernel/time/timekeeping.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c > index 37dec7e3db43..57926bc7b7f3 100644 > --- a/kernel/time/timekeeping.c > +++ b/kernel/time/timekeeping.c > @@ -304,8 +304,7 @@ static inline s64 timekeeping_delta_to_ns(struct tk_read_base *tkr, > { > s64 nsec; > > - nsec = delta * tkr->mult + tkr->xtime_nsec; > - nsec >>= tkr->shift; > + nsec = (delta * tkr->mult + tkr->xtime_nsec) >> tkr->shift; > > /* If arch requires, add in get_arch_timeoffset() */ > return nsec + arch_gettimeoffset(); > Reviewed-by: Laurent Vivier