From patchwork Tue Nov 25 01:16:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "pang.xunlei" X-Patchwork-Id: 41448 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 1391625AEA for ; Tue, 25 Nov 2014 01:16:46 +0000 (UTC) Received: by mail-wg0-f71.google.com with SMTP id l18sf5968053wgh.2 for ; Mon, 24 Nov 2014 17:16:45 -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:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=uB/MGWyy92rr7olv/3B4odB+JNw/P6bESQwQU+Os7+g=; b=k1l4Og1z98zCnIWboRFcl0impv8KQSM9JDfBsA9lKxpEtj07sob2UVf5iwkwrELqmp 6zfBzL9zNHj50TB7OCHpSmblxSALEgn9qg8R8QXcySTHGjwRCHKgmPyZuRQZi4+O/zmQ 1Iq+h16z6++Qn8oOMJhCMpQ0Zt/Y3ddScdz0/7DjHNDZeVyjP1ydX7eQc7UtAPYUsuUW g9H+gSkxDqkdjxRb3O3GIO55nAXM9K/kGcFaif1VocZi2ZzTFpby/GtxM0V7ShLtf0oP W/iHUN9Ollmybcu3EPOcmB6RrQkE6nvKiptrpAcG+/Mz84C8fdICfuKfjwpFyMK06nJB pASg== X-Gm-Message-State: ALoCoQnRQ1V0euDU3lHJWRis56oDfjiCWHAHpXqg2gWkP2N7854vw+CcSqZmYXCMWQwzdNeYurBH X-Received: by 10.180.19.226 with SMTP id i2mr4765333wie.5.1416878205323; Mon, 24 Nov 2014 17:16:45 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.19.200 with SMTP id h8ls69025lae.76.gmail; Mon, 24 Nov 2014 17:16:44 -0800 (PST) X-Received: by 10.112.161.161 with SMTP id xt1mr14656117lbb.9.1416878204898; Mon, 24 Nov 2014 17:16:44 -0800 (PST) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id k9si16835322lam.39.2014.11.24.17.16.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Nov 2014 17:16:44 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by mail-lb0-f178.google.com with SMTP id f15so7624611lbj.37 for ; Mon, 24 Nov 2014 17:16:44 -0800 (PST) X-Received: by 10.153.7.170 with SMTP id dd10mr23134715lad.44.1416878204744; Mon, 24 Nov 2014 17:16:44 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp361768lbc; Mon, 24 Nov 2014 17:16:43 -0800 (PST) X-Received: by 10.68.65.2 with SMTP id t2mr38547688pbs.39.1416878203175; Mon, 24 Nov 2014 17:16:43 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ns6si23862987pbb.93.2014.11.24.17.16.42 for ; Mon, 24 Nov 2014 17:16:43 -0800 (PST) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751486AbaKYBQk (ORCPT + 26 others); Mon, 24 Nov 2014 20:16:40 -0500 Received: from mail-pa0-f41.google.com ([209.85.220.41]:58108 "EHLO mail-pa0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750830AbaKYBQj (ORCPT ); Mon, 24 Nov 2014 20:16:39 -0500 Received: by mail-pa0-f41.google.com with SMTP id rd3so10726065pab.0 for ; Mon, 24 Nov 2014 17:16:39 -0800 (PST) X-Received: by 10.68.183.193 with SMTP id eo1mr37449372pbc.168.1416878199154; Mon, 24 Nov 2014 17:16:39 -0800 (PST) Received: from wangdeqiang.com ([210.21.223.3]) by mx.google.com with ESMTPSA id oa8sm3463919pdb.84.2014.11.24.17.16.36 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Nov 2014 17:16:38 -0800 (PST) From: "pang.xunlei" To: linux-kernel@vger.kernel.org, John Stultz Cc: LKP , "pang.xunlei" Subject: [PATCH] time: Avoid possible NTP adjustment mult overflow Date: Tue, 25 Nov 2014 09:16:20 +0800 Message-Id: <1416878180-25312-1-git-send-email-pang.xunlei@linaro.org> X-Mailer: git-send-email 1.7.9.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: pang.xunlei@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.217.178 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 occurring, 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. Signed-off-by: pang.xunlei --- Fix the problem in the former patch catched by Fengguang's 0day robot: [time] WARNING: CPU: 0 PID: 1 at kernel/time/timekeeping.c:1337 update_wall_time() kernel/time/timekeeping.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 0aef92a..9a1482e 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1390,6 +1390,12 @@ static __always_inline void timekeeping_apply_adjustment(struct timekeeper *tk, * * XXX - TODO: Doc ntp_error calculation. */ + if (mult_adj > 0 && (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;