From: Paul Gortmaker <paul.gortmaker@windriver.com>
To: <stable@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: John Stultz <john.stultz@linaro.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Prarit Bhargava <prarit@redhat.com>,
Zhouping Liu <zliu@redhat.com>, Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Paul Gortmaker <paul.gortmaker@windriver.com>
Subject: [v2.6.34-stable 02/77] time: Improve sanity checking of timekeeping inputs
Date: Tue, 8 Jan 2013 18:34:41 -0500 [thread overview]
Message-ID: <1357688156-25387-3-git-send-email-paul.gortmaker@windriver.com> (raw)
In-Reply-To: <1357688156-25387-1-git-send-email-paul.gortmaker@windriver.com>
From: John Stultz <john.stultz@linaro.org>
-------------------
This is a commit scheduled for the next v2.6.34 longterm release.
http://git.kernel.org/?p=linux/kernel/git/paulg/longterm-queue-2.6.34.git
If you see a problem with using this for longterm, please comment.
-------------------
commit 4e8b14526ca7fb046a81c94002c1c43b6fdf0e9b upstream.
Unexpected behavior could occur if the time is set to a value large
enough to overflow a 64bit ktime_t (which is something larger then the
year 2262).
Also unexpected behavior could occur if large negative offsets are
injected via adjtimex.
So this patch improves the sanity check timekeeping inputs by
improving the timespec_valid() check, and then makes better use of
timespec_valid() to make sure we don't set the time to an invalid
negative value or one that overflows ktime_t.
Note: This does not protect from setting the time close to overflowing
ktime_t and then letting natural accumulation cause the overflow.
Reported-by: CAI Qian <caiqian@redhat.com>
Reported-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Zhouping Liu <zliu@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>
Link: http://lkml.kernel.org/r/1344454580-17031-1-git-send-email-john.stultz@linaro.org
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Linux Kernel <linux-kernel@vger.kernel.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
---
include/linux/ktime.h | 7 -------
include/linux/time.h | 22 ++++++++++++++++++++--
kernel/time/timekeeping.c | 15 ++++++++++++++-
3 files changed, 34 insertions(+), 10 deletions(-)
diff --git a/include/linux/ktime.h b/include/linux/ktime.h
index ce59832..ecdf64e 100644
--- a/include/linux/ktime.h
+++ b/include/linux/ktime.h
@@ -58,13 +58,6 @@ union ktime {
typedef union ktime ktime_t; /* Kill this */
-#define KTIME_MAX ((s64)~((u64)1 << 63))
-#if (BITS_PER_LONG == 64)
-# define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC)
-#else
-# define KTIME_SEC_MAX LONG_MAX
-#endif
-
/*
* ktime_t definitions when using the 64-bit scalar representation:
*/
diff --git a/include/linux/time.h b/include/linux/time.h
index 6e026e4..146b6f3 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -91,11 +91,29 @@ static inline struct timespec timespec_sub(struct timespec lhs,
return ts_delta;
}
+#define KTIME_MAX ((s64)~((u64)1 << 63))
+#if (BITS_PER_LONG == 64)
+# define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC)
+#else
+# define KTIME_SEC_MAX LONG_MAX
+#endif
+
/*
* Returns true if the timespec is norm, false if denorm:
*/
-#define timespec_valid(ts) \
- (((ts)->tv_sec >= 0) && (((unsigned long) (ts)->tv_nsec) < NSEC_PER_SEC))
+static inline bool timespec_valid(const struct timespec *ts)
+{
+ /* Dates before 1970 are bogus */
+ if (ts->tv_sec < 0)
+ return false;
+ /* Can't have more nanoseconds then a second */
+ if ((unsigned long)ts->tv_nsec >= NSEC_PER_SEC)
+ return false;
+ /* Disallow values that could overflow ktime_t */
+ if ((unsigned long long)ts->tv_sec >= KTIME_SEC_MAX)
+ return false;
+ return true;
+}
extern struct timespec xtime;
extern struct timespec wall_to_monotonic;
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 156fd67..0d59077 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -343,7 +343,7 @@ int do_settimeofday(struct timespec *tv)
struct timespec ts_delta;
unsigned long flags;
- if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
+ if (!timespec_valid(tv))
return -EINVAL;
write_seqlock_irqsave(&xtime_lock, flags);
@@ -559,7 +559,20 @@ void __init timekeeping_init(void)
struct timespec now, boot;
read_persistent_clock(&now);
+ if (!timespec_valid(&now)) {
+ printk("WARNING: Persistent clock returned invalid value!\n"
+ " Check your CMOS/BIOS settings.\n");
+ now.tv_sec = 0;
+ now.tv_nsec = 0;
+ }
+
read_boot_clock(&boot);
+ if (!timespec_valid(&boot)) {
+ printk("WARNING: Boot clock returned invalid value!\n"
+ " Check your CMOS/BIOS settings.\n");
+ boot.tv_sec = 0;
+ boot.tv_nsec = 0;
+ }
write_seqlock_irqsave(&xtime_lock, flags);
--
1.7.12.1
next prev parent reply other threads:[~2013-01-08 23:34 UTC|newest]
Thread overview: 82+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-08 23:34 [v2.6.34-stable 00/77] v2.6.34.14 longterm review Paul Gortmaker
2013-01-08 23:34 ` [v2.6.34-stable 01/77] net: sock: validate data_len before allocating skb in sock_alloc_send_pskb() Paul Gortmaker
2013-01-08 23:34 ` Paul Gortmaker [this message]
2013-01-08 23:34 ` [v2.6.34-stable 03/77] time: Avoid making adjustments if we haven't accumulated anything Paul Gortmaker
2013-01-08 23:34 ` [v2.6.34-stable 04/77] time: Move ktime_t overflow checking into timespec_valid_strict Paul Gortmaker
2013-01-08 23:34 ` [v2.6.34-stable 05/77] ALSA: hda_intel: ALSA HD Audio patch for Intel Patsburg DeviceIDs Paul Gortmaker
2013-01-08 23:34 ` [v2.6.34-stable 06/77] ALSA: hda: add Vortex86MX PCI ids Paul Gortmaker
2013-01-08 23:34 ` [v2.6.34-stable 07/77] ALSA: hda - Add support for VMware controller Paul Gortmaker
2013-01-08 23:34 ` [v2.6.34-stable 08/77] ALSA: hda - Reduce pci id list for Intel with class id Paul Gortmaker
2013-01-08 23:34 ` [v2.6.34-stable 09/77] ALSA: hda - ALSA HD Audio patch for Intel Panther Point DeviceIDs Paul Gortmaker
2013-01-08 23:34 ` [v2.6.34-stable 10/77] ALSA: hda: Use position_fix=1 for Acer Aspire 5538 to enable capture on internal mic Paul Gortmaker
2013-01-08 23:34 ` [v2.6.34-stable 11/77] cifs: fix cifs stable patch cifs-fix-oplock-break-handling-try-2.patch Paul Gortmaker
2013-01-08 23:34 ` [v2.6.34-stable 12/77] gro: reset vlan_tci on reuse Paul Gortmaker
2013-01-08 23:34 ` [v2.6.34-stable 13/77] md: Fix handling for devices from 2TB to 4TB in 0.90 metadata Paul Gortmaker
2013-01-08 23:34 ` [v2.6.34-stable 14/77] md: Don't truncate size at 4TB for RAID0 and Linear Paul Gortmaker
2013-01-08 23:34 ` [v2.6.34-stable 15/77] genalloc: stop crashing the system when destroying a pool Paul Gortmaker
2013-01-08 23:34 ` [v2.6.34-stable 16/77] inotify: stop kernel memory leak on file creation failure Paul Gortmaker
2013-01-08 23:34 ` [v2.6.34-stable 17/77] xfs: validate acl count Paul Gortmaker
2013-01-08 23:34 ` [v2.6.34-stable 18/77] xfs: fix acl count validation in xfs_acl_from_disk() Paul Gortmaker
2013-01-08 23:34 ` [v2.6.34-stable 19/77] x86, ioapic: initialize nr_ioapic_registers early in mp_register_ioapic() Paul Gortmaker
2013-01-08 23:34 ` [v2.6.34-stable 20/77] i2c-algo-bit: Generate correct i2c address sequence for 10-bit target Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 21/77] eCryptfs: Extend array bounds for all filename chars Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 22/77] PCI hotplug: shpchp: don't blindly claim non-AMD 0x7450 device IDs Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 23/77] ARM: 7161/1: errata: no automatic store buffer drain Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 24/77] ALSA: lx6464es - fix device communication via command bus Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 25/77] SUNRPC: Ensure we return EAGAIN in xs_nospace if congestion is cleared Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 26/77] timekeeping: add arch_offset hook to ktime_get functions Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 27/77] p54spi: Add missing spin_lock_init Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 28/77] p54spi: Fix workqueue deadlock Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 29/77] nl80211: fix MAC address validation Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 30/77] staging: usbip: bugfix for deadlock Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 31/77] staging: comedi: fix oops for USB DAQ devices Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 32/77] Staging: comedi: fix signal handling in read and write Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 33/77] USB: whci-hcd: fix endian conversion in qset_clear() Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 34/77] usb: ftdi_sio: add PID for Propox ISPcable III Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 35/77] usb: option: add SIMCom SIM5218 Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 36/77] USB: usb-storage: unusual_devs entry for Kingston DT 101 G2 Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 37/77] Silencing 'killing requests for dead queue' Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 38/77] sched, x86: Avoid unnecessary overflow in sched_clock Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 39/77] x86/mpparse: Account for bus types other than ISA and PCI Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 40/77] oprofile, x86: Fix crash when unloading module (nmi timer mode) Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 41/77] genirq: Fix race condition when stopping the irq thread Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 42/77] tick-broadcast: Stop active broadcast device when replacing it Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 43/77] ALSA: sis7019 - give slow codecs more time to reset Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 44/77] ALSA: hda/realtek - Fix Oops in alc_mux_select() Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 45/77] ARM: davinci: dm646x evm: wrong register used in setup_vpif_input_channel_mode Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 46/77] oprofile: Free potentially owned tasks in case of errors Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 47/77] oprofile: Fix locking dependency in sync_start() Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 48/77] percpu: fix first chunk match in per_cpu_ptr_to_phys() Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 49/77] percpu: fix chunk range calculation Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 50/77] xfrm: Fix key lengths for rfc3686(ctr(aes)) Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 51/77] linux/log2.h: Fix rounddown_pow_of_two(1) Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 52/77] jbd/jbd2: validate sb->s_first in journal_get_superblock() Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 53/77] Make TASKSTATS require root access Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 54/77] hfs: fix hfs_find_init() sb->ext_tree NULL ptr oops Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 55/77] export __get_user_pages_fast() function Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 56/77] oprofile, x86: Fix nmi-unsafe callgraph support Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 57/77] ext4: avoid hangs in ext4_da_should_update_i_disksize() Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 58/77] USB: cdc-acm: add IDs for Motorola H24 HSPA USB module Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 59/77] udf: Fortify loading of sparing table Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 60/77] udf: Avoid run away loop when partition table length is corrupted Paul Gortmaker
2013-01-10 14:43 ` Ben Hutchings
2013-01-10 17:03 ` Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 61/77] sctp: malloc enough room for asconf-ack chunk Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 62/77] sctp: Fix list corruption resulting from freeing an association on a list Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 63/77] sctp: ABORT if receive, reassmbly, or reodering queue is not empty while closing socket Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 64/77] sctp: Enforce retransmission limit during shutdown Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 65/77] SCTP: fix race between sctp_bind_addr_free() and sctp_bind_addr_conflict() Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 66/77] KVM: x86: Prevent starting PIT timers in the absence of irqchip support Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 67/77] perf_events: Fix races in group composition Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 68/77] perf: Fix tear-down of inherited group events Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 69/77] sched: fix divide by zero at {thread_group,task}_times Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 70/77] mutex: Place lock in contended state after fastpath_lock failure Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 71/77] crypto: ghash - Avoid null pointer dereference if no key is set Paul Gortmaker
2013-01-09 2:56 ` Nick Bowler
2013-01-09 14:56 ` Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 72/77] net: Fix ip link add netns oops Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 73/77] sched/rt: Fix task stack corruption under __ARCH_WANT_INTERRUPTS_ON_CTXSW Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 74/77] rwsem: Remove redundant asmregparm annotation Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 75/77] um: Use RWSEM_GENERIC_SPINLOCK on x86 Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 76/77] x86: Get rid of asmregparm Paul Gortmaker
2013-01-08 23:35 ` [v2.6.34-stable 77/77] x86: Don't use the EFI reboot method by default Paul Gortmaker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1357688156-25387-3-git-send-email-paul.gortmaker@windriver.com \
--to=paul.gortmaker@windriver.com \
--cc=a.p.zijlstra@chello.nl \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=prarit@redhat.com \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=zliu@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).