From patchwork Tue Sep 18 02:32:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 11485 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 A0C2523E29 for ; Tue, 18 Sep 2012 02:32:23 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id C8C003D032CF for ; Tue, 18 Sep 2012 02:32:22 +0000 (UTC) Received: by ieak11 with SMTP id k11so10188650iea.11 for ; Mon, 17 Sep 2012 19:32:22 -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-cbid :x-gm-message-state; bh=2XwGXmcQcuzmxW2PF0NMlOEopypY/fwBuNZEmEp7WOA=; b=DhFUGcNHfoa0lGPp/mVh5xeXVyyliF7BSUzMWhCHUvFqi0q7Pfnv3vvcslfF1un7Xy eDRLSXdA2Jesc3XFDKkiZnmNdIVFMbh+uEYEV11uzspQuMLS+63MSIoesd843jmqz/tY syjCmg7dRElUsp7MpcOD3QHnhL0SiJTF678m31MmGJw0G0r67x0eknUd1jrDTS/f90yv 2xJ1oxFdCwPDC86a2I5tJykS22A7+TwLSqszXldWvLNDfUIZiGM+U5JJA1SWa1oGQy/6 zVzb1DTDQyLOBXH/amJOEW2hxHnPwLLZiEx31vqmzQyziq5/lnu0ysaEPJqGsW9BzNX8 hkkQ== Received: by 10.50.237.41 with SMTP id uz9mr8821560igc.43.1347935541977; Mon, 17 Sep 2012 19:32:21 -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 ex8csp349574igc; Mon, 17 Sep 2012 19:32:21 -0700 (PDT) Received: by 10.50.236.6 with SMTP id uq6mr8957299igc.50.1347935541342; Mon, 17 Sep 2012 19:32:21 -0700 (PDT) Received: from e7.ny.us.ibm.com (e7.ny.us.ibm.com. [32.97.182.137]) by mx.google.com with ESMTPS id fa8si12872865igb.12.2012.09.17.19.32.21 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 17 Sep 2012 19:32:21 -0700 (PDT) Received-SPF: neutral (google.com: 32.97.182.137 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=32.97.182.137; Authentication-Results: mx.google.com; spf=neutral (google.com: 32.97.182.137 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 e7.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 17 Sep 2012 22:32:20 -0400 Received: from d01relay01.pok.ibm.com (9.56.227.233) by e7.ny.us.ibm.com (192.168.1.107) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 17 Sep 2012 22:32:18 -0400 Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay01.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q8I2WH6k133846; Mon, 17 Sep 2012 22:32:17 -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 q8I2WHu4008780; Mon, 17 Sep 2012 23:32:17 -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 q8I2WDhI008571; Mon, 17 Sep 2012 23:32:17 -0300 From: John Stultz To: stable@vger.kernel.org Cc: John Stultz , Zhouping Liu , Ingo Molnar , Prarit Bhargava , Thomas Gleixner , Linus Torvalds , Linux Kernel Subject: [PATCH 3/3] 2.6.32.y: time: Move ktime_t overflow checking into timespec_valid_strict Date: Mon, 17 Sep 2012 22:32:10 -0400 Message-Id: <1347935530-33767-4-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1347935530-33767-1-git-send-email-john.stultz@linaro.org> References: <1347935530-33767-1-git-send-email-john.stultz@linaro.org> x-cbid: 12091802-5806-0000-0000-000019B54C47 X-Gm-Message-State: ALoCoQmZTRw6avSiIuY2brE3YhaX5HU8qk/hpPfpFJowUZ3D8HyZ5Ob358ecyE0625piatiXY1uJ This is a -stable backport of cee58483cf56e0ba355fdd97ff5e8925329aa936 Andreas Bombe reported that the added ktime_t overflow checking added to timespec_valid in commit 4e8b14526ca7 ("time: Improve sanity checking of timekeeping inputs") was causing problems with X.org because it caused timeouts larger then KTIME_T to be invalid. Previously, these large timeouts would be clamped to KTIME_MAX and would never expire, which is valid. This patch splits the ktime_t overflow checking into a new timespec_valid_strict function, and converts the timekeeping codes internal checking to use this more strict function. Reported-and-tested-by: Andreas Bombe Cc: Zhouping Liu Cc: Ingo Molnar Cc: Prarit Bhargava Cc: Thomas Gleixner Cc: stable@vger.kernel.org Signed-off-by: John Stultz Signed-off-by: Linus Torvalds Cc: Linux Kernel Signed-off-by: John Stultz --- include/linux/time.h | 7 +++++++ kernel/time/timekeeping.c | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/linux/time.h b/include/linux/time.h index 146b6f3..bc93987 100644 --- a/include/linux/time.h +++ b/include/linux/time.h @@ -109,6 +109,13 @@ static inline bool timespec_valid(const struct timespec *ts) /* Can't have more nanoseconds then a second */ if ((unsigned long)ts->tv_nsec >= NSEC_PER_SEC) return false; + return true; +} + +static inline bool timespec_valid_strict(const struct timespec *ts) +{ + if (!timespec_valid(ts)) + return false; /* Disallow values that could overflow ktime_t */ if ((unsigned long long)ts->tv_sec >= KTIME_SEC_MAX) return false; diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index b451c93..3d35af3 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -354,7 +354,7 @@ int do_settimeofday(struct timespec *tv) struct timespec ts_delta; unsigned long flags; - if (!timespec_valid(tv)) + if (!timespec_valid_strict(tv)) return -EINVAL; write_seqlock_irqsave(&xtime_lock, flags); @@ -570,7 +570,7 @@ void __init timekeeping_init(void) struct timespec now, boot; read_persistent_clock(&now); - if (!timespec_valid(&now)) { + if (!timespec_valid_strict(&now)) { printk("WARNING: Persistent clock returned invalid value!\n" " Check your CMOS/BIOS settings.\n"); now.tv_sec = 0; @@ -578,7 +578,7 @@ void __init timekeeping_init(void) } read_boot_clock(&boot); - if (!timespec_valid(&boot)) { + if (!timespec_valid_strict(&boot)) { printk("WARNING: Boot clock returned invalid value!\n" " Check your CMOS/BIOS settings.\n"); boot.tv_sec = 0;