mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Cc: Marc Zyngier <marc.zyngier@arm.com>,
	Tomasz Nowicki <tn@semihalf.com>,
	Christoffer Dall <christoffer.dall@linaro.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	"Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com>
Subject: [PATCH review for 4.9 42/50] hrtimer: Catch invalid clockids again
Date: Mon, 25 Sep 2017 01:12:56 +0000	[thread overview]
Message-ID: <20170925011225.10029-42-alexander.levin@verizon.com> (raw)
In-Reply-To: <20170925011225.10029-1-alexander.levin@verizon.com>

From: Marc Zyngier <marc.zyngier@arm.com>

[ Upstream commit 336a9cde10d641e70bac67d90ae91b3190c3edca ]

commit 82e88ff1ea94 ("hrtimer: Revert CLOCK_MONOTONIC_RAW support") removed
unfortunately a sanity check in the hrtimer code which was part of that
MONOTONIC_RAW patch series.

It would have caught the bogus usage of CLOCK_MONOTONIC_RAW in the wireless
code. So bring it back.

It is way too easy to take any random clockid and feed it to the hrtimer
subsystem. At best, it gets mapped to a monotonic base, but it would be
better to just catch illegal values as early as possible.

Detect invalid clockids, map them to CLOCK_MONOTONIC and emit a warning.

[ tglx: Replaced the BUG by a WARN and gracefully map to CLOCK_MONOTONIC ]

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Cc: Tomasz Nowicki <tn@semihalf.com>
Cc: Christoffer Dall <christoffer.dall@linaro.org>
Link: http://lkml.kernel.org/r/1452879670-16133-3-git-send-email-marc.zyngier@arm.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
---
 kernel/time/hrtimer.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index bb5ec425dfe0..eeb7f2f5698d 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -94,17 +94,15 @@ DEFINE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases) =
 };
 
 static const int hrtimer_clock_to_base_table[MAX_CLOCKS] = {
+	/* Make sure we catch unsupported clockids */
+	[0 ... MAX_CLOCKS - 1]	= HRTIMER_MAX_CLOCK_BASES,
+
 	[CLOCK_REALTIME]	= HRTIMER_BASE_REALTIME,
 	[CLOCK_MONOTONIC]	= HRTIMER_BASE_MONOTONIC,
 	[CLOCK_BOOTTIME]	= HRTIMER_BASE_BOOTTIME,
 	[CLOCK_TAI]		= HRTIMER_BASE_TAI,
 };
 
-static inline int hrtimer_clockid_to_base(clockid_t clock_id)
-{
-	return hrtimer_clock_to_base_table[clock_id];
-}
-
 /*
  * Functions and macros which are different for UP/SMP systems are kept in a
  * single place
@@ -1112,6 +1110,18 @@ u64 hrtimer_get_next_event(void)
 }
 #endif
 
+static inline int hrtimer_clockid_to_base(clockid_t clock_id)
+{
+	if (likely(clock_id < MAX_CLOCKS)) {
+		int base = hrtimer_clock_to_base_table[clock_id];
+
+		if (likely(base != HRTIMER_MAX_CLOCK_BASES))
+			return base;
+	}
+	WARN(1, "Invalid clockid %d. Using MONOTONIC\n", clock_id);
+	return HRTIMER_BASE_MONOTONIC;
+}
+
 static void __hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
 			   enum hrtimer_mode mode)
 {
-- 
2.11.0

  parent reply	other threads:[~2017-09-25  1:29 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-25  1:12 [PATCH review for 4.9 01/50] xen-netback: Use GFP_ATOMIC to allocate hash Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 02/50] locking/lockdep: Add nest_lock integrity test Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 04/50] irqchip/crossbar: Fix incorrect type of local variables Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 03/50] watchdog: kempld: fix gcc-4.3 build Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 06/50] mac80211_hwsim: check HWSIM_ATTR_RADIO_NAME length Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 05/50] initramfs: finish fput() before accessing any binary from initramfs Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 08/50] qed: Don't use attention PTT for configuring BW Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 09/50] mac80211: fix power saving clients handling in iwlwifi Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 07/50] ALSA: hda: Add Geminilake HDMI codec ID Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 10/50] net/mlx4_en: fix overflow in mlx4_en_init_timestamp() Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 12/50] netfilter: nf_ct_expect: Change __nf_ct_expect_check() return value Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 11/50] staging: vchiq_2835_arm: Make cache-line-size a required DT property Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 13/50] iio: adc: xilinx: Fix error handling Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 14/50] f2fs: do SSR for data when there is enough free space Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 17/50] f2fs: do not wait for writeback in write_begin Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 16/50] Btrfs: send, fix failure to rename top level inode due to name collision Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 15/50] sched/fair: Update rq clock before changing a task's CPU affinity Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 18/50] md/linear: shutup lockdep warnning Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 20/50] net/mlx4_core: Fix VF overwrite of module param which disables DMFS on new probed PFs Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 19/50] sparc64: Migrate hvcons irq to panicked cpu Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 21/50] crypto: xts - Add ECB dependency Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 22/50] mm/memory_hotplug: set magic number to page->freelist instead of page->lru.next Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 24/50] slub: do not merge cache if slub_debug contains a never-merge flag Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 23/50] ocfs2/dlmglue: prepare tracking logic to avoid recursive cluster lock Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 27/50] drm/amdgpu: refuse to reserve io mem for split VRAM buffers Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 26/50] ASoC: mediatek: add I2C dependency for CS42XX8 Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 25/50] scsi: scsi_dh_emc: return success in clariion_std_inquiry() Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 28/50] net: mvpp2: release reference to txq_cpu[] entry after unmapping Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 30/50] qed: Reserve doorbell BAR space for present CPUs Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 29/50] qede: Prevent index problems in loopback test Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 33/50] ceph: don't update_dentry_lease unless we actually got one Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 31/50] qed: Read queue state before releasing buffer Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 32/50] i2c: at91: ensure state is restored after suspending Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 36/50] uapi: fix linux/rds.h userspace compilation errors Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 34/50] ceph: fix bogus endianness change in ceph_ioctl_set_layout Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 35/50] ceph: clean up unsafe d_parent accesses in build_dentry_path Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 38/50] ibmvnic: Handle processing of CRQ messages in a tasklet Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 39/50] IB/hfi1: Use static CTLE with Preset 6 for integrated HFIs Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 37/50] uapi: fix linux/mroute6.h userspace compilation errors Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 40/50] IB/hfi1: Allocate context data on memory node Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 41/50] target/iscsi: Fix unsolicited data seq_end_offset calculation Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` Levin, Alexander (Sasha Levin) [this message]
2017-09-25  1:12 ` [PATCH review for 4.9 45/50] drm/nouveau/gr/gf100-: fix ccache error logging Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 43/50] nfsd/callback: Cleanup callback cred on shutdown Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 44/50] powerpc/perf: Add restrictions to PMC5 in power9 DD1 Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 46/50] regulator: core: Resolve supplies before disabling unused regulators Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 48/50] EDAC, mce_amd: Print IPID and Syndrome on a separate line Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 47/50] btmrvl: avoid double-disable_irq() race Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 49/50] genirq: Clarify logic calculating bogus irqreturn_t values Levin, Alexander (Sasha Levin)
2017-09-25  1:12 ` [PATCH review for 4.9 50/50] cpufreq: CPPC: add ACPI_PROCESSOR dependency Levin, Alexander (Sasha Levin)

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=20170925011225.10029-42-alexander.levin@verizon.com \
    --to=alexander.levin@verizon.com \
    --cc=christoffer.dall@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marc.zyngier@arm.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tn@semihalf.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

all inboxes | Powered by JetHome®