android_kernel_samsung_msm8976/arch
Marc Zyngier aeea6f0c5d KVM: arm/arm64: Close VMID generation race
commit f0cf47d939d0b4b4f660c5aaa4276fa3488f3391 upstream.

Before entering the guest, we check whether our VMID is still
part of the current generation. In order to avoid taking a lock,
we start with checking that the generation is still current, and
only if not current do we take the lock, recheck, and update the
generation and VMID.

This leaves open a small race: A vcpu can bump up the global
generation number as well as the VM's, but has not updated
the VMID itself yet.

At that point another vcpu from the same VM comes in, checks
the generation (and finds it not needing anything), and jumps
into the guest. At this point, we end-up with two vcpus belonging
to the same VM running with two different VMIDs. Eventually, the
VMID used by the second vcpu will get reassigned, and things will
really go wrong...

A simple solution would be to drop this initial check, and always take
the lock. This is likely to cause performance issues. A middle ground
is to convert the spinlock to a rwlock, and only take the read lock
on the fast path. If the check fails at that point, drop it and
acquire the write lock, rechecking the condition.

This ensures that the above scenario doesn't occur.

Reported-by: Mark Rutland <mark.rutland@arm.com>
Tested-by: Shannon Zhao <zhaoshenglong@huawei.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
[bwh: Backported to 3.16: adjust filename, context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
2019-07-27 21:52:17 +02:00
..
alpha Safer ABI for O_TMPFILE 2018-12-03 11:52:36 +01:00
arc mm: larger stack guard gap, between vmas 2017-07-11 00:00:39 +00:00
arm KVM: arm/arm64: Close VMID generation race 2019-07-27 21:52:17 +02:00
arm64 defconfig: Disable LTE coexistence for wifi only models 2019-07-27 21:51:32 +02:00
avr32
blackfin
c6x
cris
frv mm: larger stack guard gap, between vmas 2017-07-11 00:00:39 +00:00
h8300
hexagon
ia64 Import latest Samsung release 2017-04-18 03:43:52 +02:00
m32r This is the 3.10.98 stable release 2017-04-18 17:17:24 +02:00
m68k Merge remote-tracking branch 'f2fs/linux-3.10.y' into HEAD 2017-04-18 17:02:28 +02:00
metag
microblaze
mips mm: larger stack guard gap, between vmas 2017-07-11 00:00:39 +00:00
mn10300 This is the 3.10.96 stable release 2017-04-18 17:16:02 +02:00
openrisc This is the 3.10.96 stable release 2017-04-18 17:16:02 +02:00
parisc Safer ABI for O_TMPFILE 2018-12-03 11:52:36 +01:00
powerpc mm: larger stack guard gap, between vmas 2017-07-11 00:00:39 +00:00
s390 kernel: make groups_sort calling a responsibility group_info allocators 2019-07-27 21:46:18 +02:00
score
sh mm: larger stack guard gap, between vmas 2017-07-11 00:00:39 +00:00
sparc crypto: hash - annotate algorithms taking optional key 2019-07-27 21:49:17 +02:00
tile mm: larger stack guard gap, between vmas 2017-07-11 00:00:39 +00:00
um This is the 3.10.99 stable release 2017-04-18 17:17:46 +02:00
unicore32
x86 x86/acpi: Prevent out of bound access caused by broken ACPI tables 2019-07-27 21:51:30 +02:00
xtensa mm: larger stack guard gap, between vmas 2017-07-11 00:00:39 +00:00
.gitignore
Kconfig