stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	Andy Lutomirski <luto@amacapital.net>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>
Subject: [PATCH 4.9 55/87] x86/uaccess, sched/preempt: Verify access_ok() context
Date: Mon, 13 Nov 2017 13:56:12 +0100	[thread overview]
Message-ID: <20171113125620.440096021@linuxfoundation.org> (raw)
In-Reply-To: <20171113125615.304035578@linuxfoundation.org>

4.9-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Peter Zijlstra <peterz@infradead.org>

commit 7c4788950ba5922fde976d80b72baf46f14dee8d upstream.

I recently encountered wreckage because access_ok() was used where it
should not be, add an explicit WARN when access_ok() is used wrongly.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 arch/x86/include/asm/uaccess.h |   13 +++++++++++--
 include/linux/preempt.h        |   21 +++++++++++++--------
 2 files changed, 24 insertions(+), 10 deletions(-)

--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -68,6 +68,12 @@ static inline bool __chk_range_not_ok(un
 	__chk_range_not_ok((unsigned long __force)(addr), size, limit); \
 })
 
+#ifdef CONFIG_DEBUG_ATOMIC_SLEEP
+# define WARN_ON_IN_IRQ()	WARN_ON_ONCE(!in_task())
+#else
+# define WARN_ON_IN_IRQ()
+#endif
+
 /**
  * access_ok: - Checks if a user space pointer is valid
  * @type: Type of access: %VERIFY_READ or %VERIFY_WRITE.  Note that
@@ -88,8 +94,11 @@ static inline bool __chk_range_not_ok(un
  * checks that the pointer is in the user space range - after calling
  * this function, memory access functions may still return -EFAULT.
  */
-#define access_ok(type, addr, size) \
-	likely(!__range_not_ok(addr, size, user_addr_max()))
+#define access_ok(type, addr, size)					\
+({									\
+	WARN_ON_IN_IRQ();						\
+	likely(!__range_not_ok(addr, size, user_addr_max()));		\
+})
 
 /*
  * These are the main single-value transfer routines.  They automatically
--- a/include/linux/preempt.h
+++ b/include/linux/preempt.h
@@ -65,19 +65,24 @@
 
 /*
  * Are we doing bottom half or hardware interrupt processing?
- * Are we in a softirq context? Interrupt context?
- * in_softirq - Are we currently processing softirq or have bh disabled?
- * in_serving_softirq - Are we currently processing softirq?
+ *
+ * in_irq()       - We're in (hard) IRQ context
+ * in_softirq()   - We have BH disabled, or are processing softirqs
+ * in_interrupt() - We're in NMI,IRQ,SoftIRQ context or have BH disabled
+ * in_serving_softirq() - We're in softirq context
+ * in_nmi()       - We're in NMI context
+ * in_task()	  - We're in task context
+ *
+ * Note: due to the BH disabled confusion: in_softirq(),in_interrupt() really
+ *       should not be used in new code.
  */
 #define in_irq()		(hardirq_count())
 #define in_softirq()		(softirq_count())
 #define in_interrupt()		(irq_count())
 #define in_serving_softirq()	(softirq_count() & SOFTIRQ_OFFSET)
-
-/*
- * Are we in NMI context?
- */
-#define in_nmi()	(preempt_count() & NMI_MASK)
+#define in_nmi()		(preempt_count() & NMI_MASK)
+#define in_task()		(!(preempt_count() & \
+				   (NMI_MASK | HARDIRQ_MASK | SOFTIRQ_OFFSET)))
 
 /*
  * The preempt_count offset after preempt_disable();

  parent reply	other threads:[~2017-11-13 13:01 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-13 12:55 [PATCH 4.9 00/87] 4.9.62-stable review Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 02/87] video: fbdev: pmag-ba-fb: Remove bad `__init annotation Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 03/87] PCI: mvebu: Handle changes to the bridge windows while enabled Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 04/87] sched/core: Add missing update_rq_clock() call in sched_move_task() Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 05/87] xen/netback: set default upper limit of tx/rx queues to 8 Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 06/87] ARM: dts: imx53-qsb-common: fix FEC pinmux config Greg Kroah-Hartman
2017-11-16  4:09   ` Patrick Brünn
2017-11-16 13:35     ` Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 07/87] dt-bindings: clockgen: Add compatible string for LS1012A Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 08/87] EDAC, amd64: Add x86cpuid sanity check during init Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 09/87] PM / OPP: Error out on failing to add static OPPs for v1 bindings Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 10/87] clk: samsung: exynos5433: Add IDs for PHYCLK_MIPIDPHY0_* clocks Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 12/87] KVM: PPC: Book 3S: XICS: correct the real mode ICP rejecting counter Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 13/87] iommu/arm-smmu-v3: Clear prior settings when updating STEs Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 14/87] pinctrl: baytrail: Fix debugfs offset output Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 15/87] powerpc/corenet: explicitly disable the SDHC controller on kmcoge4 Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 16/87] cxl: Force psl data-cache flush during device shutdown Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 17/87] ARM: omap2plus_defconfig: Fix probe errors on UARTs 5 and 6 Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 18/87] arm64: dma-mapping: Only swizzle DMA ops for IOMMU_DOMAIN_DMA Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 19/87] crypto: vmx - disable preemption to enable vsx in aes_ctr.c Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 20/87] drm: mali-dp: fix Lx_CONTROL register fields clobber Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 21/87] iio: trigger: free trigger resource correctly Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 22/87] iio: pressure: ms5611: claim direct mode during oversampling changes Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 23/87] iio: magnetometer: mag3110: claim direct mode during raw writes Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 24/87] iio: proximity: sx9500: claim direct mode during raw proximity reads Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 25/87] dt-bindings: Add LEGO MINDSTORMS EV3 compatible specification Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 26/87] dt-bindings: Add vendor prefix for LEGO Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 28/87] serial: sh-sci: Fix register offsets for the IRDA serial port Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 29/87] libertas: fix improper return value Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 30/87] usb: hcd: initialize hcd->flags to 0 when rm hcd Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 31/87] netfilter: nft_meta: deal with PACKET_LOOPBACK in netdev family Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 33/87] rt2800usb: mark tx failure on timeout Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 34/87] apparmor: fix undefined reference to `aa_g_hash_policy Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 35/87] IPsec: do not ignore crypto err in ah4 input Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 36/87] EDAC, amd64: Save and return err code from probe_one_instance() Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 37/87] s390/topology: make "topology=off" parameter work Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 38/87] Input: mpr121 - handle multiple bits change of status register Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 39/87] Input: mpr121 - set missing event capability Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 40/87] sched/cputime, powerpc32: Fix stale scaled stime on context switch Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 41/87] IB/ipoib: Change list_del to list_del_init in the tx object Greg Kroah-Hartman
2017-11-13 12:55 ` [PATCH 4.9 42/87] ARM: dts: STiH410-family: fix wrong parent clock frequency Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 43/87] s390/qeth: fix retrieval of vipa and proxy-arp addresses Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 44/87] s390/qeth: issue STARTLAN as first IPA command Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 45/87] wcn36xx: Dont use the destroyed hal_mutex Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 46/87] IB/rxe: Fix reference leaks in memory key invalidation code Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 47/87] clk: mvebu: adjust AP806 CPU clock frequencies to production chip Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 48/87] net: dsa: select NET_SWITCHDEV Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 51/87] KEYS: trusted: sanitize all key material Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 52/87] KEYS: trusted: fix writing past end of buffer in trusted_read() Greg Kroah-Hartman
2017-11-13 12:56 ` Greg Kroah-Hartman [this message]
2017-11-13 12:56 ` [PATCH 4.9 56/87] workqueue: Fix NULL pointer dereference Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 57/87] crypto: ccm - preserve the IV buffer Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 58/87] crypto: x86/sha1-mb - fix panic due to unaligned access Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 59/87] crypto: x86/sha256-mb " Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 60/87] KEYS: fix NULL pointer dereference during ASN.1 parsing [ver #2] Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 61/87] ARM: 8720/1: ensure dump_instr() checks addr_limit Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 62/87] ALSA: seq: Fix OSS sysex delivery in OSS emulation Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 63/87] ALSA: seq: Avoid invalid lockdep class warning Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 65/87] MIPS: microMIPS: Fix incorrect mask in insn_table_MM Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 66/87] MIPS: Fix CM region target definitions Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 67/87] MIPS: SMP: Use a completion event to signal CPU up Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 68/87] MIPS: Fix race on setting and getting cpu_online_mask Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 69/87] MIPS: SMP: Fix deadlock & online race Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 70/87] selftests: firmware: send expected errors to /dev/null Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 71/87] tools: firmware: check for distro fallback udev cancel rule Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 72/87] ASoC: sun4i-spdif: remove legacy dapm components Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 73/87] MIPS: BMIPS: Fix missing cbr address Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 74/87] MIPS: AR7: Defer registration of GPIO Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 75/87] MIPS: AR7: Ensure that serial ports are properly set up Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 76/87] Input: elan_i2c - add ELAN060C to the ACPI table Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 77/87] rbd: use GFP_NOIO for parent stat and data requests Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 78/87] drm/vmwgfx: Fix Ubuntu 17.10 Wayland black screen issue Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 79/87] drm/bridge: adv7511: Rework adv7511_power_on/off() so they can be reused internally Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 80/87] drm/bridge: adv7511: Reuse __adv7511_power_on/off() when probing EDID Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 81/87] drm/bridge: adv7511: Re-write the i2c address before EDID probing Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 82/87] can: sun4i: handle overrun in RX FIFO Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 83/87] can: ifi: Fix transmitter delay calculation Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 85/87] netfilter: nat: Revert "netfilter: nat: convert nat bysrc hash to rhashtable" Greg Kroah-Hartman
2017-11-14 15:54   ` Pablo Neira Ayuso
2017-11-14 15:55     ` Pablo Neira Ayuso
2017-11-13 12:56 ` [PATCH 4.9 86/87] x86/smpboot: Make optimization of delay calibration work correctly Greg Kroah-Hartman
2017-11-13 12:56 ` [PATCH 4.9 87/87] x86/oprofile/ppro: Do not use __this_cpu*() in preemptible context Greg Kroah-Hartman
2017-11-13 21:51 ` [PATCH 4.9 00/87] 4.9.62-stable review Shuah Khan
2017-11-13 22:28 ` Guenter Roeck
2017-11-14  6:48 ` [PATCH 4.9 00/87] 4.9.62-stable review --> crash Sebastian Gottschall
2017-11-14  7:41   ` Greg Kroah-Hartman
2017-11-14  7:46     ` Sebastian Gottschall
2017-11-14  8:01       ` Greg Kroah-Hartman
2017-11-14 22:20 ` [PATCH 4.9 00/87] 4.9.62-stable review Tom Gall

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=20171113125620.440096021@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /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).