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,
	Sean Christopherson <sean.j.christopherson@intel.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>
Subject: [PATCH 4.4 26/77] x86/retpoline: Dont clobber RFLAGS during CALL_NOSPEC on i386
Date: Wed,  4 Sep 2019 19:53:13 +0200	[thread overview]
Message-ID: <20190904175306.033475295@linuxfoundation.org> (raw)
In-Reply-To: <20190904175303.317468926@linuxfoundation.org>

From: Sean Christopherson <sean.j.christopherson@intel.com>

commit b63f20a778c88b6a04458ed6ffc69da953d3a109 upstream.

Use 'lea' instead of 'add' when adjusting %rsp in CALL_NOSPEC so as to
avoid clobbering flags.

KVM's emulator makes indirect calls into a jump table of sorts, where
the destination of the CALL_NOSPEC is a small blob of code that performs
fast emulation by executing the target instruction with fixed operands.

  adcb_al_dl:
     0x000339f8 <+0>:   adc    %dl,%al
     0x000339fa <+2>:   ret

A major motiviation for doing fast emulation is to leverage the CPU to
handle consumption and manipulation of arithmetic flags, i.e. RFLAGS is
both an input and output to the target of CALL_NOSPEC.  Clobbering flags
results in all sorts of incorrect emulation, e.g. Jcc instructions often
take the wrong path.  Sans the nops...

  asm("push %[flags]; popf; " CALL_NOSPEC " ; pushf; pop %[flags]\n"
     0x0003595a <+58>:  mov    0xc0(%ebx),%eax
     0x00035960 <+64>:  mov    0x60(%ebx),%edx
     0x00035963 <+67>:  mov    0x90(%ebx),%ecx
     0x00035969 <+73>:  push   %edi
     0x0003596a <+74>:  popf
     0x0003596b <+75>:  call   *%esi
     0x000359a0 <+128>: pushf
     0x000359a1 <+129>: pop    %edi
     0x000359a2 <+130>: mov    %eax,0xc0(%ebx)
     0x000359b1 <+145>: mov    %edx,0x60(%ebx)

  ctxt->eflags = (ctxt->eflags & ~EFLAGS_MASK) | (flags & EFLAGS_MASK);
     0x000359a8 <+136>: mov    -0x10(%ebp),%eax
     0x000359ab <+139>: and    $0x8d5,%edi
     0x000359b4 <+148>: and    $0xfffff72a,%eax
     0x000359b9 <+153>: or     %eax,%edi
     0x000359bd <+157>: mov    %edi,0x4(%ebx)

For the most part this has gone unnoticed as emulation of guest code
that can trigger fast emulation is effectively limited to MMIO when
running on modern hardware, and MMIO is rarely, if ever, accessed by
instructions that affect or consume flags.

Breakage is almost instantaneous when running with unrestricted guest
disabled, in which case KVM must emulate all instructions when the guest
has invalid state, e.g. when the guest is in Big Real Mode during early
BIOS.

Fixes: 776b043848fd2 ("x86/retpoline: Add initial retpoline support")
Fixes: 1a29b5b7f347a ("KVM: x86: Make indirect calls in emulator speculation safe")
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/20190822211122.27579-1-sean.j.christopherson@intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 arch/x86/include/asm/nospec-branch.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -151,7 +151,7 @@
 	"    	lfence;\n"					\
 	"       jmp    902b;\n"					\
 	"       .align 16\n"					\
-	"903:	addl   $4, %%esp;\n"				\
+	"903:	lea    4(%%esp), %%esp;\n"			\
 	"       pushl  %[thunk_target];\n"			\
 	"       ret;\n"						\
 	"       .align 16\n"					\



  parent reply	other threads:[~2019-09-04 17:56 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-04 17:52 [PATCH 4.4 00/77] 4.4.191-stable review Greg Kroah-Hartman
2019-09-04 17:52 ` [PATCH 4.4 01/77] HID: Add 044f:b320 ThrustMaster, Inc. 2 in 1 DT Greg Kroah-Hartman
2019-09-04 17:52 ` [PATCH 4.4 02/77] MIPS: kernel: only use i8253 clocksource with periodic clockevent Greg Kroah-Hartman
2019-09-04 17:52 ` [PATCH 4.4 03/77] netfilter: ebtables: fix a memory leak bug in compat Greg Kroah-Hartman
2019-09-04 17:52 ` [PATCH 4.4 04/77] bonding: Force slave speed check after link state recovery for 802.3ad Greg Kroah-Hartman
2019-09-04 17:52 ` [PATCH 4.4 05/77] can: dev: call netif_carrier_off() in register_candev() Greg Kroah-Hartman
2019-09-04 17:52 ` [PATCH 4.4 06/77] ASoC: Fail card instantiation if DAI format setup fails Greg Kroah-Hartman
2019-09-04 18:09   ` Mark Brown
2019-09-05 18:56     ` Greg Kroah-Hartman
2019-09-06 10:59       ` Mark Brown
2019-09-04 17:52 ` [PATCH 4.4 07/77] st21nfca_connectivity_event_received: null check the allocation Greg Kroah-Hartman
2019-09-04 17:52 ` [PATCH 4.4 08/77] st_nci_hci_connectivity_event_received: " Greg Kroah-Hartman
2019-09-04 17:52 ` [PATCH 4.4 09/77] ASoC: ti: davinci-mcasp: Correct slot_width posed constraint Greg Kroah-Hartman
2019-09-04 17:52 ` [PATCH 4.4 10/77] net: usb: qmi_wwan: Add the BroadMobi BM818 card Greg Kroah-Hartman
2019-09-04 17:52 ` [PATCH 4.4 11/77] isdn: mISDN: hfcsusb: Fix possible null-pointer dereferences in start_isoc_chain() Greg Kroah-Hartman
2019-09-04 17:52 ` [PATCH 4.4 12/77] isdn: hfcsusb: Fix mISDN driver crash caused by transfer buffer on the stack Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 13/77] perf bench numa: Fix cpu0 binding Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 14/77] can: sja1000: force the string buffer NULL-terminated Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 15/77] can: peak_usb: " Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 16/77] NFSv4: Fix a potential sleep while atomic in nfs4_do_reclaim() Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 17/77] net: cxgb3_main: Fix a resource leak in a error path in init_one() Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 18/77] net: hisilicon: make hip04_tx_reclaim non-reentrant Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 19/77] net: hisilicon: fix hip04-xmit never return TX_BUSY Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 20/77] net: hisilicon: Fix dma_map_single failed on arm64 Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 21/77] libata: add SG safety checks in SFF pio transfers Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 22/77] selftests: kvm: Adding config fragments Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 23/77] HID: wacom: correct misreported EKR ring values Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 24/77] Revert "dm bufio: fix deadlock with loop device" Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 25/77] userfaultfd_release: always remove uffd flags and clear vm_userfaultfd_ctx Greg Kroah-Hartman
2019-09-04 17:53 ` Greg Kroah-Hartman [this message]
2019-09-04 17:53 ` [PATCH 4.4 27/77] x86/apic: Handle missing global clockevent gracefully Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 28/77] x86/boot: Save fields explicitly, zero out everything else Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 29/77] x86/boot: Fix boot regression caused by bootparam sanitizing Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 30/77] dm btree: fix order of block initialization in btree_split_beneath Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 31/77] dm space map metadata: fix missing store of apply_bops() return value Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 32/77] dm table: fix invalid memory accesses with too high sector number Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 33/77] cgroup: Disable IRQs while holding css_set_lock Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 34/77] GFS2: dont set rgrp gl_object until its inserted into rgrp tree Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 35/77] net: arc_emac: fix koops caused by sk_buff free Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 36/77] vhost-net: set packet weight of tx polling to 2 * vq size Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 37/77] vhost_net: use packet weight for rx handler, too Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 38/77] vhost_net: introduce vhost_exceeds_weight() Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 39/77] vhost: " Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 40/77] vhost_net: fix possible infinite loop Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 41/77] vhost: scsi: add weight support Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 42/77] siphash: add cryptographically secure PRF Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 43/77] siphash: implement HalfSipHash1-3 for hash tables Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 44/77] inet: switch IP ID generator to siphash Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 45/77] netfilter: ctnetlink: dont use conntrack/expect object addresses as id Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 46/77] netfilter: conntrack: Use consistent ct id hash calculation Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 47/77] Revert "perf test 6: Fix missing kvm module load for s390" Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 48/77] x86/pm: Introduce quirk framework to save/restore extra MSR registers around suspend/resume Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 49/77] x86/CPU/AMD: Clear RDRAND CPUID bit on AMD family 15h/16h Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 50/77] scsi: ufs: Fix NULL pointer dereference in ufshcd_config_vreg_hpm() Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 51/77] dmaengine: ste_dma40: fix unneeded variable warning Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 52/77] usb: gadget: composite: Clear "suspended" on reset/disconnect Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 53/77] usb: host: fotg2: restart hcd after port reset Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 54/77] tools: hv: fix KVP and VSS daemons exit code Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 55/77] watchdog: bcm2835_wdt: Fix module autoload Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 56/77] tcp: fix tcp_rtx_queue_tail in case of empty retransmit queue Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 57/77] ALSA: usb-audio: Fix a stack buffer overflow bug in check_input_term Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 58/77] ALSA: usb-audio: Fix an OOB bug in parse_audio_mixer_unit Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 59/77] tcp: make sure EPOLLOUT wont be missed Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 60/77] ALSA: seq: Fix potential concurrent access to the deleted pool Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 61/77] KVM: x86: Dont update RIP or do single-step on faulting emulation Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 62/77] x86/apic: Do not initialize LDR and DFR for bigsmp Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 63/77] x86/apic: Include the LDR when clearing out APIC registers Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 64/77] usb-storage: Add new JMS567 revision to unusual_devs Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 65/77] USB: cdc-wdm: fix race between write and disconnect due to flag abuse Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 66/77] usb: host: ohci: fix a race condition between shutdown and irq Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 67/77] USB: storage: ums-realtek: Update module parameter description for auto_delink_en Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 68/77] USB: storage: ums-realtek: Whitelist auto-delink support Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 69/77] ptrace,x86: Make user_64bit_mode() available to 32-bit builds Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 70/77] uprobes/x86: Fix detection of 32-bit user mode Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 71/77] mmc: sdhci-of-at91: add quirk for broken HS200 Greg Kroah-Hartman
2019-09-04 17:53 ` [PATCH 4.4 72/77] mmc: core: Fix init of SD cards reporting an invalid VDD range Greg Kroah-Hartman
2019-09-04 17:54 ` [PATCH 4.4 73/77] stm class: Fix a double free of stm_source_device Greg Kroah-Hartman
2019-09-04 17:54 ` [PATCH 4.4 74/77] VMCI: Release resource if the work is already queued Greg Kroah-Hartman
2019-09-04 17:54 ` [PATCH 4.4 75/77] Revert "cfg80211: fix processing world regdomain when non modular" Greg Kroah-Hartman
2019-09-04 17:54 ` [PATCH 4.4 76/77] mac80211: fix possible sta leak Greg Kroah-Hartman
2019-09-04 17:54 ` [PATCH 4.4 77/77] x86/ptrace: fix up botched merge of spectrev1 fix Greg Kroah-Hartman
2019-09-05  1:18 ` [PATCH 4.4 00/77] 4.4.191-stable review kernelci.org bot
2019-09-05 14:22 ` shuah
2019-09-05 16:54 ` Guenter Roeck
2019-09-05 17:24 ` Daniel Díaz
2019-09-05 19:50 ` Kelsey Skunberg
2019-09-06  7:36 ` Jon Hunter
2019-09-06  7:36   ` Jon Hunter

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=20190904175306.033475295@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=sean.j.christopherson@intel.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /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.