From patchwork Wed Aug 22 00:30:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 10842 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 325AC23F70 for ; Wed, 22 Aug 2012 00:31:44 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id CE642A18C9B for ; Wed, 22 Aug 2012 00:31:33 +0000 (UTC) Received: by ggmi2 with SMTP id i2so366274ggm.11 for ; Tue, 21 Aug 2012 17:31:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-content-scanned:x-cbid:x-gm-message-state; bh=KXCB8u/SLlB/8cJpLfUrsRXCmjpO6uvBo+F4KWxtVZw=; b=WpmGwJmrX3vir2XZZqlhDMbmTt45NNZjvRiCI+YoCYcJbSDUIdQO2DWItzW8W5licE ubiJgg9qXSyGRK3IUQwYU+3RThAzFximyrfUiGgolchQYzWu4KE73s3eiI6r06IeAPJE BKlFHVYrr7FkuYnACA74+/AX+oE69VtQJkUJvenu46MEyv2fy6Cs1fl/CrKMYh7C0Tw2 dJqTnXlEI65+ZeAc+8b+AS8h3URZgPZEw1LEMjPpwtenLJgAO901smW8CHvIqrQuZQ+c Am7n8iTpC63wfWWW1LCfaOWo1MGQDyrayPRQwTbJaWP7eooyRBYWUck4d+vmI0If8PXn VtIw== Received: by 10.50.87.164 with SMTP id az4mr323625igb.43.1345595502796; Tue, 21 Aug 2012 17:31:42 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp173762igc; Tue, 21 Aug 2012 17:31:42 -0700 (PDT) Received: by 10.50.100.137 with SMTP id ey9mr294595igb.61.1345595502266; Tue, 21 Aug 2012 17:31:42 -0700 (PDT) Received: from e8.ny.us.ibm.com (e8.ny.us.ibm.com. [32.97.182.138]) by mx.google.com with ESMTPS id dd8si27724424igb.5.2012.08.21.17.31.42 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 21 Aug 2012 17:31:42 -0700 (PDT) Received-SPF: neutral (google.com: 32.97.182.138 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=32.97.182.138; Authentication-Results: mx.google.com; spf=neutral (google.com: 32.97.182.138 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) smtp.mail=john.stultz@linaro.org Received: from /spool/local by e8.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 21 Aug 2012 20:31:41 -0400 Received: from d01dlp02.pok.ibm.com (9.56.250.167) by e8.ny.us.ibm.com (192.168.1.108) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 21 Aug 2012 20:30:58 -0400 Received: from d01relay05.pok.ibm.com (d01relay05.pok.ibm.com [9.56.227.237]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id 791216E803A; Tue, 21 Aug 2012 20:30:57 -0400 (EDT) Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay05.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q7M0UvMq159294; Tue, 21 Aug 2012 20:30:57 -0400 Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q7M0UvP3024427; Tue, 21 Aug 2012 21:30:57 -0300 Received: from kernel-pok.stglabs.ibm.com (kernel.stglabs.ibm.com [9.114.214.19]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q7M0UuAH024415; Tue, 21 Aug 2012 21:30:57 -0300 From: John Stultz To: linux-kernel Cc: John Stultz , Ingo Molnar , Prarit Bhargava , Thomas Gleixner , Andreas Schwab Subject: [PATCH 3/4] time: Avoid potential shift-overflow with large shift values Date: Tue, 21 Aug 2012 20:30:48 -0400 Message-Id: <1345595449-34965-4-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1345595449-34965-1-git-send-email-john.stultz@linaro.org> References: <1345595449-34965-1-git-send-email-john.stultz@linaro.org> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12082200-9360-0000-0000-000009B13FC4 X-Gm-Message-State: ALoCoQkGDGvDf3zclJz/S0nOlR+1gJvEhbSGmqlv3q8DDMNE3DOFeoCoOpf8oAwduaqBhca1Uku9 Andreas Schwab noted that the 1 << tk->shift could overflow if the shift value was greater then 30, since 1 would be a 32bit long on 32bit architectures. This patch uses 1ULL instead to ensure we don't overflow on the shift. This issue was introduced by 1e75fa8be9fb61e1af46b5b3b176347a4c958ca1 Cc: Ingo Molnar Cc: Prarit Bhargava Cc: Thomas Gleixner Cc: Andreas Schwab Reported-by: Andreas Schwab Signed-off-by: John Stultz --- kernel/time/timekeeping.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 1dbf80e..a5a9389 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1184,9 +1184,9 @@ static void update_wall_time(void) * the vsyscall implementations are converted to use xtime_nsec * (shifted nanoseconds), this can be killed. */ - remainder = tk->xtime_nsec & ((1 << tk->shift) - 1); + remainder = tk->xtime_nsec & ((1ULL << tk->shift) - 1); tk->xtime_nsec -= remainder; - tk->xtime_nsec += 1 << tk->shift; + tk->xtime_nsec += 1ULL << tk->shift; tk->ntp_error += remainder << tk->ntp_error_shift; /*