From patchwork Fri Nov 21 19:44:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 41354 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B7B9B2452C for ; Fri, 21 Nov 2014 19:44:39 +0000 (UTC) Received: by mail-wg0-f71.google.com with SMTP id l18sf3369933wgh.6 for ; Fri, 21 Nov 2014 11:44:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=FmRcZjY1G7nyLJ8Bby2p0T7/yMaU+wMkqqV5hARU/ZQ=; b=RAsCE/kh0odhC+IDrtPpyNJ2CKYKp9ndxy7saxDTuFpVlgd6b8o3zf7FBdiRqKZFXh nylEL+bmio7/cSkK1+wFSjpgdmGnH4FUUgsZC37wsstfzs0I1dXUVtSz/zzgBzmk2L98 jBPBun+tm1s/tRtGyAZ5sOShamIuMyZWO9LTGONCSpbWkOfeWpwziz3bzZW2WuhkDlwq 2kphr2TGUfHtagjW0TLQSWI7Gkvp0nLomfU8V/D5/U3/9rmBroKAqXG0Jcj18qkbI0uX AYMiC/0zIPwQ0uA3H/yrCevHNxePH8hYkO9fQ79qwXsPJTFOkInCon+BjJi3r9gmoAm+ YrLA== X-Gm-Message-State: ALoCoQkmcnPassDzQ/nkCgAVVc1RVMCnACKXuwGLDrXAM1yNaNFg/pLqX1QM1YEq3lcGpGfwT6n5 X-Received: by 10.180.94.3 with SMTP id cy3mr5468400wib.7.1416599078965; Fri, 21 Nov 2014 11:44:38 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.19.98 with SMTP id d2ls248956lae.19.gmail; Fri, 21 Nov 2014 11:44:38 -0800 (PST) X-Received: by 10.152.87.42 with SMTP id u10mr7443518laz.0.1416599078700; Fri, 21 Nov 2014 11:44:38 -0800 (PST) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id d9si7000503lbv.98.2014.11.21.11.44.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 21 Nov 2014 11:44:38 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by mail-la0-f44.google.com with SMTP id ge10so4845171lab.31 for ; Fri, 21 Nov 2014 11:44:38 -0800 (PST) X-Received: by 10.152.87.100 with SMTP id w4mr7133305laz.27.1416599078620; Fri, 21 Nov 2014 11:44:38 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp153706lbc; Fri, 21 Nov 2014 11:44:37 -0800 (PST) X-Received: by 10.69.26.98 with SMTP id ix2mr9965725pbd.161.1416599076272; Fri, 21 Nov 2014 11:44:36 -0800 (PST) Received: from mail-pa0-f46.google.com (mail-pa0-f46.google.com. [209.85.220.46]) by mx.google.com with ESMTPS id r11si7530546pdl.210.2014.11.21.11.44.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 21 Nov 2014 11:44:36 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.46 as permitted sender) client-ip=209.85.220.46; Received: by mail-pa0-f46.google.com with SMTP id lj1so5509724pab.33 for ; Fri, 21 Nov 2014 11:44:35 -0800 (PST) X-Received: by 10.68.109.3 with SMTP id ho3mr10639387pbb.74.1416599075558; Fri, 21 Nov 2014 11:44:35 -0800 (PST) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id t9sm5513621pbs.75.2014.11.21.11.44.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 21 Nov 2014 11:44:35 -0800 (PST) From: John Stultz To: lkml Cc: "pang.xunlei" , Thomas Gleixner , Ingo Molnar , Arnd Bergmann , Miroslav Lichvar , Richard Cochran , Prarit Bhargava , Alessandro Zummo , John Stultz Subject: [PATCH 02/12] time: Avoid possible NTP adjustment mult overflow. Date: Fri, 21 Nov 2014 11:44:08 -0800 Message-Id: <1416599058-13836-3-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1416599058-13836-1-git-send-email-john.stultz@linaro.org> References: <1416599058-13836-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: "pang.xunlei" Ideally, __clocksource_updatefreq_scale, selects the largest shift value possible for a clocksource. This results in the mult memember of struct clocksource being particularly large, although not so large that NTP would adjust the clock to cause it to overflow. That said, nothing actually prohibits an overflow from occuring, its just that it "shouldn't" occur. So while very unlikely, and so far never observed, the value of (cs->mult+cs->maxadj) may have a chance to reach very near 0xFFFFFFFF, so there is a possibility it may overflow when doing NTP positive adjustment See the following detail: When NTP slewes the clock, kernel goes through update_wall_time()->...->timekeeping_apply_adjustment(): tk->tkr.mult += mult_adj; Since there is no guard against it, its possible tk->tkr.mult may overflow during this operation. This patch avoids any possible mult overflow by judging the overflow case before adding mult_adj to mult, also adds the WARNING message when capturing such case. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Arnd Bergmann Cc: pang.xunlei Cc: Miroslav Lichvar Cc: Richard Cochran Cc: Prarit Bhargava Cc: Alessandro Zummo Signed-off-by: pang.xunlei [jstultz: Reworded commit message] Signed-off-by: John Stultz --- kernel/time/timekeeping.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index ec1791f..cad61b3 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1332,6 +1332,12 @@ static __always_inline void timekeeping_apply_adjustment(struct timekeeper *tk, * * XXX - TODO: Doc ntp_error calculation. */ + if (tk->tkr.mult + mult_adj < mult_adj) { + /* NTP adjustment caused clocksource mult overflow */ + WARN_ON_ONCE(1); + return; + } + tk->tkr.mult += mult_adj; tk->xtime_interval += interval; tk->tkr.xtime_nsec -= offset;