From patchwork Wed Sep 12 00:49:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 11338 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 1DB9C23E29 for ; Wed, 12 Sep 2012 00:50:02 +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 801723D18DAC for ; Wed, 12 Sep 2012 00:50:01 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id k11so1938803iea.11 for ; Tue, 11 Sep 2012 17:50:01 -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=sXJCbM1eMp6kJfb+hvngYKyBB1RJ9xFLSO7WIIxhHJ8=; b=bGWY1yMPuVqUfEUOMDSve0w8ylqhI9+pgVflR5HhJBYYzf80QC+gf6kb/WDQiqTgy+ A/j4He3ydqnS7KBPEcejl3t2YIe4maL5JQ14NEQuNGLqWKzTqADJ+10GQJO4iPc8jupR HLt79CvVjdwRQNOrshA+61qQ3wMEgd3Q6f0LAA87v75f8RHxCyiD4iDvkexnJsOgkh0y S7E9t9yNTHq5m6Bo84FgIFFMnbC4oCPD0ejB8iwRe9qR2a/AEAJABkVaDkraOkZ+M20L 395Bvzv8G64o3lFTLIqFexLNLiB1Gaz3RyzaU87HLyrpr2mYPN529eosCUuuquQ4vwcT xuVQ== Received: by 10.42.109.194 with SMTP id m2mr23322005icp.48.1347411001174; Tue, 11 Sep 2012 17:50:01 -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 ex8csp42593igc; Tue, 11 Sep 2012 17:50:00 -0700 (PDT) Received: by 10.182.111.74 with SMTP id ig10mr20906894obb.14.1347411000277; Tue, 11 Sep 2012 17:50:00 -0700 (PDT) Received: from e1.ny.us.ibm.com (e1.ny.us.ibm.com. [32.97.182.141]) by mx.google.com with ESMTPS id s9si24180071oea.49.2012.09.11.17.49.59 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 11 Sep 2012 17:50:00 -0700 (PDT) Received-SPF: neutral (google.com: 32.97.182.141 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=32.97.182.141; Authentication-Results: mx.google.com; spf=neutral (google.com: 32.97.182.141 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 e1.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 11 Sep 2012 20:49:59 -0400 Received: from d01dlp02.pok.ibm.com (9.56.250.167) by e1.ny.us.ibm.com (192.168.1.101) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 11 Sep 2012 20:49:57 -0400 Received: from d01relay03.pok.ibm.com (d01relay03.pok.ibm.com [9.56.227.235]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id AFCE96E803A; Tue, 11 Sep 2012 20:49:56 -0400 (EDT) Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by d01relay03.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q8C0nu7L067428; Tue, 11 Sep 2012 20:49:56 -0400 Received: from d01av01.pok.ibm.com (loopback [127.0.0.1]) by d01av01.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q8C0nu5C002582; Tue, 11 Sep 2012 20:49:56 -0400 Received: from kernel-pok.stglabs.ibm.com (kernel.stglabs.ibm.com [9.114.214.19]) by d01av01.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q8C0nu3U002562; Tue, 11 Sep 2012 20:49:56 -0400 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] 3.0.y: time: Move ktime_t overflow checking into timespec_valid_strict Date: Tue, 11 Sep 2012 20:49:53 -0400 Message-Id: <1347410993-19004-4-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1347410993-19004-1-git-send-email-john.stultz@linaro.org> References: <1347410993-19004-1-git-send-email-john.stultz@linaro.org> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12091200-6078-0000-0000-00000F614F0F X-Gm-Message-State: ALoCoQkye0ahU6XFtE3bseROa4AZewNiQGYBTKX0bMAPmiPaeI8/FQmLgSzC0Qc4mPZu0kdzL3JH 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 | 14 ++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/linux/time.h b/include/linux/time.h index c8f7233..8c0216e 100644 --- a/include/linux/time.h +++ b/include/linux/time.h @@ -125,6 +125,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 3bbaf2d0..c3cbd8c 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -382,7 +382,7 @@ int do_settimeofday(const 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); @@ -428,7 +428,7 @@ int timekeeping_inject_offset(struct timespec *ts) timekeeping_forward_now(); tmp = timespec_add(xtime, *ts); - if (!timespec_valid(&tmp)) { + if (!timespec_valid_strict(&tmp)) { ret = -EINVAL; goto error; } @@ -591,7 +591,7 @@ void __init timekeeping_init(void) struct timespec now, boot; read_persistent_clock(&now); - if (!timespec_valid(&now)) { + if (!timespec_valid_strict(&now)) { pr_warn("WARNING: Persistent clock returned invalid value!\n" " Check your CMOS/BIOS settings.\n"); now.tv_sec = 0; @@ -599,7 +599,7 @@ void __init timekeeping_init(void) } read_boot_clock(&boot); - if (!timespec_valid(&boot)) { + if (!timespec_valid_strict(&boot)) { pr_warn("WARNING: Boot clock returned invalid value!\n" " Check your CMOS/BIOS settings.\n"); boot.tv_sec = 0; @@ -649,6 +649,12 @@ static void update_sleep_time(struct timespec t) */ static void __timekeeping_inject_sleeptime(struct timespec *delta) { + if (!timespec_valid_strict(delta)) { + printk(KERN_WARNING "__timekeeping_inject_sleeptime: Invalid " + "sleep delta value!\n"); + return; + } + xtime = timespec_add(xtime, *delta); wall_to_monotonic = timespec_sub(wall_to_monotonic, *delta); update_sleep_time(timespec_add(total_sleep_time, *delta));