All of lore.kernel.org
 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,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Andi Kleen <ak@linux.intel.com>, Ingo Molnar <mingo@redhat.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	linux-arch@vger.kernel.org,
	Tom Lendacky <thomas.lendacky@amd.com>,
	Kees Cook <keescook@chromium.org>,
	kernel-hardening@lists.openwall.com,
	Al Viro <viro@zeniv.linux.org.uk>,
	alan@linux.intel.com, David Woodhouse <dwmw@amazon.co.uk>
Subject: [PATCH 4.9 60/92] x86: Introduce __uaccess_begin_nospec() and uaccess_try_nospec
Date: Fri,  9 Feb 2018 14:39:29 +0100	[thread overview]
Message-ID: <20180209133935.579350557@linuxfoundation.org> (raw)
In-Reply-To: <20180209133931.211869118@linuxfoundation.org>

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

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

From: Dan Williams <dan.j.williams@intel.com>


(cherry picked from commit b3bbfb3fb5d25776b8e3f361d2eedaabb0b496cd)

For __get_user() paths, do not allow the kernel to speculate on the value
of a user controlled pointer. In addition to the 'stac' instruction for
Supervisor Mode Access Protection (SMAP), a barrier_nospec() causes the
access_ok() result to resolve in the pipeline before the CPU might take any
speculative action on the pointer value. Given the cost of 'stac' the
speculation barrier is placed after 'stac' to hopefully overlap the cost of
disabling SMAP with the cost of flushing the instruction pipeline.

Since __get_user is a major kernel interface that deals with user
controlled pointers, the __uaccess_begin_nospec() mechanism will prevent
speculative execution past an access_ok() permission check. While
speculative execution past access_ok() is not enough to lead to a kernel
memory leak, it is a necessary precondition.

To be clear, __uaccess_begin_nospec() is addressing a class of potential
problems near __get_user() usages.

Note, that while the barrier_nospec() in __uaccess_begin_nospec() is used
to protect __get_user(), pointer masking similar to array_index_nospec()
will be used for get_user() since it incorporates a bounds check near the
usage.

uaccess_try_nospec provides the same mechanism for get_user_try.

No functional changes.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Suggested-by: Andi Kleen <ak@linux.intel.com>
Suggested-by: Ingo Molnar <mingo@redhat.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-arch@vger.kernel.org
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: kernel-hardening@lists.openwall.com
Cc: gregkh@linuxfoundation.org
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: alan@linux.intel.com
Link: https://lkml.kernel.org/r/151727415922.33451.5796614273104346583.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 arch/x86/include/asm/uaccess.h |    9 +++++++++
 1 file changed, 9 insertions(+)

--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -123,6 +123,11 @@ extern int __get_user_bad(void);
 
 #define __uaccess_begin() stac()
 #define __uaccess_end()   clac()
+#define __uaccess_begin_nospec()	\
+({					\
+	stac();				\
+	barrier_nospec();		\
+})
 
 /*
  * This is a type: either unsigned long, if the argument fits into
@@ -474,6 +479,10 @@ struct __large_struct { unsigned long bu
 	__uaccess_begin();						\
 	barrier();
 
+#define uaccess_try_nospec do {						\
+	current->thread.uaccess_err = 0;				\
+	__uaccess_begin_nospec();					\
+
 #define uaccess_catch(err)						\
 	__uaccess_end();						\
 	(err) |= (current->thread.uaccess_err ? -EFAULT : 0);		\

  parent reply	other threads:[~2018-02-09 13:43 UTC|newest]

Thread overview: 127+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-09 13:38 [PATCH 4.9 00/92] 4.9.81-stable review Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 01/92] powerpc/pseries: Add H_GET_CPU_CHARACTERISTICS flags & wrapper Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 02/92] powerpc/64: Add macros for annotating the destination of rfid/hrfid Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 03/92] powerpc/64: Convert fast_exception_return to use RFI_TO_USER/KERNEL Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 04/92] powerpc/64: Convert the syscall exit path " Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 05/92] powerpc/64s: Convert slb_miss_common " Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 06/92] powerpc/64s: Add support for RFI flush of L1-D cache Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 07/92] powerpc/64s: Support disabling RFI flush with no_rfi_flush and nopti Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 08/92] powerpc/pseries: Query hypervisor for RFI flush settings Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 09/92] powerpc/powernv: Check device-tree " Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 10/92] powerpc/64s: Wire up cpu_show_meltdown() Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 11/92] powerpc/64s: Allow control of RFI flush via debugfs Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 12/92] auxdisplay: img-ascii-lcd: add missing MODULE_DESCRIPTION/AUTHOR/LICENSE Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 13/92] pinctrl: pxa: pxa2xx: " Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 14/92] ASoC: pcm512x: " Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 15/92] kaiser: fix intel_bts perf crashes Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 16/92] x86/pti: Make unpoison of pgd for trusted boot work for real Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 17/92] kaiser: allocate pgd with order 0 when pti=off Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 18/92] serial: core: mark port as initialized after successful IRQ change Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 19/92] ip6mr: fix stale iterator Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 20/92] net: igmp: add a missing rcu locking section Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 21/92] qlcnic: fix deadlock bug Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 22/92] qmi_wwan: Add support for Quectel EP06 Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 23/92] r8169: fix RTL8168EP take too long to complete driver initialization Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 24/92] tcp: release sk_frag.page in tcp_disconnect Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 25/92] vhost_net: stop device during reset owner Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 26/92] tcp_bbr: fix pacing_gain to always be unity when using lt_bw Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 27/92] cls_u32: add missing RCU annotation Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 28/92] ipv6: Fix SO_REUSEPORT UDP socket with implicit sk_ipv6only Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 29/92] soreuseport: fix mem leak in reuseport_add_sock() Greg Kroah-Hartman
2018-02-09 13:38 ` [PATCH 4.9 30/92] x86/asm: Fix inline asm call constraints for GCC 4.4 Greg Kroah-Hartman
2018-02-09 13:38   ` Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 31/92] x86/microcode/AMD: Do not load when running on a hypervisor Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 32/92] media: soc_camera: soc_scale_crop: add missing MODULE_DESCRIPTION/AUTHOR/LICENSE Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 33/92] b43: Add missing MODULE_FIRMWARE() Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 34/92] KEYS: encrypted: fix buffer overread in valid_master_desc() Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 35/92] x86/retpoline: Remove the esp/rsp thunk Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 36/92] KVM: x86: Make indirect calls in emulator speculation safe Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 37/92] KVM: VMX: Make indirect call " Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 38/92] module/retpoline: Warn about missing retpoline in module Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 39/92] x86/cpufeatures: Add CPUID_7_EDX CPUID leaf Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 40/92] x86/cpufeatures: Add Intel feature bits for Speculation Control Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 41/92] x86/cpufeatures: Add AMD " Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 42/92] x86/msr: Add definitions for new speculation control MSRs Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 43/92] x86/pti: Do not enable PTI on CPUs which are not vulnerable to Meltdown Greg Kroah-Hartman
2018-02-13 13:34   ` Nick Lowe
2018-02-13 15:00     ` Greg Kroah-Hartman
2018-02-13 15:09       ` Arjan van de Ven
2018-02-13 15:27         ` Nick Lowe
2018-02-13 16:32           ` Greg Kroah-Hartman
2018-02-16 13:15             ` Nick Lowe
2018-02-16 16:56               ` Nick Lowe
2018-02-13 15:56         ` Andi Kleen
2018-02-13 16:02           ` Thomas Gleixner
2018-02-13 16:10             ` Borislav Petkov
2018-02-13 16:18           ` Dave Hansen
2018-02-09 13:39 ` [PATCH 4.9 44/92] x86/cpufeature: Blacklist SPEC_CTRL/PRED_CMD on early Spectre v2 microcodes Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 45/92] x86/speculation: Add basic IBPB (Indirect Branch Prediction Barrier) support Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 46/92] x86/alternative: Print unadorned pointers Greg Kroah-Hartman
2018-02-09 22:01   ` Kees Cook
2018-02-10  7:23     ` Greg Kroah-Hartman
2018-02-10 19:14       ` Kees Cook
2018-02-10 19:21         ` Borislav Petkov
2018-02-13  9:16           ` Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 47/92] x86/nospec: Fix header guards names Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 48/92] x86/bugs: Drop one "mitigation" from dmesg Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 49/92] x86/cpu/bugs: Make retpoline module warning conditional Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 50/92] x86/cpufeatures: Clean up Spectre v2 related CPUID flags Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 51/92] x86/retpoline: Simplify vmexit_fill_RSB() Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 52/92] x86/spectre: Check CONFIG_RETPOLINE in command line parser Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 53/92] x86/entry/64: Remove the SYSCALL64 fast path Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 54/92] x86/entry/64: Push extra regs right away Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 55/92] x86/asm: Move status from thread_struct to thread_info Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 56/92] Documentation: Document array_index_nospec Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 57/92] array_index_nospec: Sanitize speculative array de-references Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 58/92] x86: Implement array_index_mask_nospec Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 59/92] x86: Introduce barrier_nospec Greg Kroah-Hartman
2018-02-09 13:39 ` Greg Kroah-Hartman [this message]
2018-02-09 13:39 ` [PATCH 4.9 61/92] x86/usercopy: Replace open coded stac/clac with __uaccess_{begin, end} Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 62/92] x86/uaccess: Use __uaccess_begin_nospec() and uaccess_try_nospec Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 63/92] x86/get_user: Use pointer masking to limit speculation Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 64/92] x86/syscall: Sanitize syscall table de-references under speculation Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 65/92] vfs, fdtable: Prevent bounds-check bypass via speculative execution Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 66/92] nl80211: Sanitize array index in parse_txq_params Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 67/92] x86/spectre: Report get_user mitigation for spectre_v1 Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 68/92] x86/spectre: Fix spelling mistake: "vunerable"-> "vulnerable" Greg Kroah-Hartman
2018-02-09 13:39   ` Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 69/92] x86/cpuid: Fix up "virtual" IBRS/IBPB/STIBP feature bits on Intel Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 70/92] x86/paravirt: Remove noreplace-paravirt cmdline option Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 71/92] x86/kvm: Update spectre-v1 mitigation Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 72/92] x86/retpoline: Avoid retpolines for built-in __init functions Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 73/92] x86/spectre: Simplify spectre_v2 command line parsing Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 74/92] x86/pti: Mark constant arrays as __initconst Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 75/92] x86/speculation: Fix typo IBRS_ATT, which should be IBRS_ALL Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 76/92] KVM: nVMX: kmap() cant fail Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 77/92] KVM: nVMX: vmx_complete_nested_posted_interrupt() " Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 78/92] KVM: nVMX: mark vmcs12 pages dirty on L2 exit Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 79/92] KVM: nVMX: Eliminate vmcs02 pool Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 80/92] KVM: VMX: introduce alloc_loaded_vmcs Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 81/92] KVM: VMX: make MSR bitmaps per-VCPU Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 82/92] KVM/x86: Add IBPB support Greg Kroah-Hartman
2018-02-09 13:39   ` Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 83/92] KVM/VMX: Emulate MSR_IA32_ARCH_CAPABILITIES Greg Kroah-Hartman
2018-02-09 13:39   ` Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 84/92] KVM/VMX: Allow direct access to MSR_IA32_SPEC_CTRL Greg Kroah-Hartman
2018-02-09 13:39   ` Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 85/92] KVM/SVM: " Greg Kroah-Hartman
2018-02-09 13:39   ` Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 86/92] crypto: tcrypt - fix S/G table for test_aead_speed() Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 87/92] ASoC: simple-card: Fix misleading error message Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 88/92] ASoC: rsnd: dont call free_irq() on Parent SSI Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 89/92] ASoC: rsnd: avoid duplicate free_irq() Greg Kroah-Hartman
2018-02-09 13:39 ` [PATCH 4.9 90/92] drm: rcar-du: Use the VBK interrupt for vblank events Greg Kroah-Hartman
2018-02-09 13:40 ` [PATCH 4.9 91/92] drm: rcar-du: Fix race condition when disabling planes at CRTC stop Greg Kroah-Hartman
2018-02-09 13:40 ` [PATCH 4.9 92/92] x86/microcode: Do the family check first Greg Kroah-Hartman
2018-02-09 17:36 ` [PATCH 4.9 00/92] 4.9.81-stable review kernelci.org bot
2018-02-09 20:18 ` Shuah Khan
2018-02-09 21:32 ` Dan Rue
2018-02-10 15:46 ` Guenter Roeck
2018-02-13  9:36   ` Greg Kroah-Hartman
2018-02-13 14:30     ` Guenter Roeck
2018-02-13 15:29       ` Greg Kroah-Hartman
2018-02-17 13:31         ` Yves-Alexis Perez
2018-02-17 13:45           ` Greg Kroah-Hartman
2018-02-17 17:35             ` Guenter Roeck
2018-02-18 17:25               ` Yves-Alexis Perez
2018-02-20 10:40               ` Greg Kroah-Hartman

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=20180209133935.579350557@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=ak@linux.intel.com \
    --cc=alan@linux.intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dwmw@amazon.co.uk \
    --cc=keescook@chromium.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.