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, Dan Williams <dan.j.williams@intel.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	linux-arch@vger.kernel.org, Kees Cook <keescook@chromium.org>,
	kernel-hardening@lists.openwall.com,
	Al Viro <viro@zeniv.linux.org.uk>,
	Andy Lutomirski <luto@kernel.org>,
	torvalds@linux-foundation.org, alan@linux.intel.com,
	David Woodhouse <dwmw@amazon.co.uk>
Subject: [PATCH 4.9 63/92] x86/get_user: Use pointer masking to limit speculation
Date: Fri,  9 Feb 2018 14:39:32 +0100	[thread overview]
Message-ID: <20180209133935.811950747@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 c7f631cb07e7da06ac1d231ca178452339e32a94)

Quoting Linus:

    I do think that it would be a good idea to very expressly document
    the fact that it's not that the user access itself is unsafe. I do
    agree that things like "get_user()" want to be protected, but not
    because of any direct bugs or problems with get_user() and friends,
    but simply because get_user() is an excellent source of a pointer
    that is obviously controlled from a potentially attacking user
    space. So it's a prime candidate for then finding _subsequent_
    accesses that can then be used to perturb the cache.

Unlike the __get_user() case get_user() includes the address limit check
near the pointer de-reference. With that locality the speculation can be
mitigated with pointer narrowing rather than a barrier, i.e.
array_index_nospec(). Where the narrowing is performed by:

	cmp %limit, %ptr
	sbb %mask, %mask
	and %mask, %ptr

With respect to speculation the value of %ptr is either less than %limit
or NULL.

Co-developed-by: Linus Torvalds <torvalds@linux-foundation.org>
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: Kees Cook <keescook@chromium.org>
Cc: kernel-hardening@lists.openwall.com
Cc: gregkh@linuxfoundation.org
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: torvalds@linux-foundation.org
Cc: alan@linux.intel.com
Link: https://lkml.kernel.org/r/151727417469.33451.11804043010080838495.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/lib/getuser.S |   10 ++++++++++
 1 file changed, 10 insertions(+)

--- a/arch/x86/lib/getuser.S
+++ b/arch/x86/lib/getuser.S
@@ -39,6 +39,8 @@ ENTRY(__get_user_1)
 	mov PER_CPU_VAR(current_task), %_ASM_DX
 	cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX
 	jae bad_get_user
+	sbb %_ASM_DX, %_ASM_DX		/* array_index_mask_nospec() */
+	and %_ASM_DX, %_ASM_AX
 	ASM_STAC
 1:	movzbl (%_ASM_AX),%edx
 	xor %eax,%eax
@@ -53,6 +55,8 @@ ENTRY(__get_user_2)
 	mov PER_CPU_VAR(current_task), %_ASM_DX
 	cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX
 	jae bad_get_user
+	sbb %_ASM_DX, %_ASM_DX		/* array_index_mask_nospec() */
+	and %_ASM_DX, %_ASM_AX
 	ASM_STAC
 2:	movzwl -1(%_ASM_AX),%edx
 	xor %eax,%eax
@@ -67,6 +71,8 @@ ENTRY(__get_user_4)
 	mov PER_CPU_VAR(current_task), %_ASM_DX
 	cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX
 	jae bad_get_user
+	sbb %_ASM_DX, %_ASM_DX		/* array_index_mask_nospec() */
+	and %_ASM_DX, %_ASM_AX
 	ASM_STAC
 3:	movl -3(%_ASM_AX),%edx
 	xor %eax,%eax
@@ -82,6 +88,8 @@ ENTRY(__get_user_8)
 	mov PER_CPU_VAR(current_task), %_ASM_DX
 	cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX
 	jae bad_get_user
+	sbb %_ASM_DX, %_ASM_DX		/* array_index_mask_nospec() */
+	and %_ASM_DX, %_ASM_AX
 	ASM_STAC
 4:	movq -7(%_ASM_AX),%rdx
 	xor %eax,%eax
@@ -93,6 +101,8 @@ ENTRY(__get_user_8)
 	mov PER_CPU_VAR(current_task), %_ASM_DX
 	cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX
 	jae bad_get_user_8
+	sbb %_ASM_DX, %_ASM_DX		/* array_index_mask_nospec() */
+	and %_ASM_DX, %_ASM_AX
 	ASM_STAC
 4:	movl -7(%_ASM_AX),%edx
 5:	movl -3(%_ASM_AX),%ecx

  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 ` [PATCH 4.9 60/92] x86: Introduce __uaccess_begin_nospec() and uaccess_try_nospec Greg Kroah-Hartman
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 ` Greg Kroah-Hartman [this message]
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.811950747@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --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=luto@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --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.