Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754236AbcKPVUP (ORCPT ); Wed, 16 Nov 2016 16:20:15 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:37286 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753265AbcKPVUO (ORCPT ); Wed, 16 Nov 2016 16:20:14 -0500 From: Chris Metcalf To: John Stultz , Thomas Gleixner , Laurent Vivier , David Gibson , "Christopher S . Hall" , linux-kernel@vger.kernel.org Cc: Chris Metcalf Subject: [PATCH v2] time: Avoid signed overflow in timekeeping_delta_to_ns() Date: Wed, 16 Nov 2016 16:20:03 -0500 Message-Id: <1479331203-10349-1-git-send-email-cmetcalf@mellanox.com> X-Mailer: git-send-email 2.7.2 In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1061 Lines: 29 This bug was originally fixed 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 in a less subtle way by changing the type of "nsec" to unsigned and adding a comment explaining why. Signed-off-by: Chris Metcalf --- v2: just use "u64 nsec" to fix the signed shift problem kernel/time/timekeeping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 37dec7e3db43..8c06a2aa9b5f 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -302,7 +302,7 @@ static inline u32 arch_gettimeoffset(void) { return 0; } static inline s64 timekeeping_delta_to_ns(struct tk_read_base *tkr, cycle_t delta) { - s64 nsec; + u64 nsec; /* Avoid possibility of a negative right shift. */ nsec = delta * tkr->mult + tkr->xtime_nsec; nsec >>= tkr->shift; -- 2.7.2