x86/sgx: Fix race between reclaimer and page fault handler
Reinette Chatre authored
commit af117837 upstream.

Haitao reported encountering a WARN triggered by the ENCLS[ELDU]
instruction faulting with a #GP.

The WARN is encountered when the reclaimer evicts a range of
pages from the enclave when the same pages are faulted back right away.

Consider two enclave pages (ENCLAVE_A and ENCLAVE_B)
sharing a PCMD page (PCMD_AB). ENCLAVE_A is in the
enclave memory and ENCLAVE_B is in the backing store. PCMD_AB contains
just one entry, that of ENCLAVE_B.

Scenario proceeds where ENCLAVE_A is being evicted from the enclave
while ENCLAVE_B is faulted in.

sgx_reclaim_pages() {

  ...

  /*
   * Reclaim ENCLAVE_A
   */
  mutex_lock(&encl->lock);
  /*
   * Get a reference to ENCLAVE_A's
   * shmem page where enclave page
   * encrypted data will be stored
   * as well as a reference to the
   * enclave page's PCMD data page,
   * PCMD_AB.
   * Release mutex before writing
   * any data to the shmem pages.
   ...
e5d38f18
Name Last commit Last update
Documentation random: fix sysctl documentation nits
LICENSES LICENSES/LGPL-2.1: Add LGPL-2.1-or-later as valid identifiers
arch x86/sgx: Fix race between reclaimer and page fault handler
block block/mq-deadline: Set the fifo_time member also if inserting at head
certs certs: Fix build error when CONFIG_MODULE_SIG_KEY is empty
crypto crypto: ecrdsa - Fix incorrect use of vli_cmp
drivers HID: multitouch: add quirks to enable Lenovo X12 trackpoint
fs fs/ntfs3: validate BOOT sectors_per_clusters
include netfilter: conntrack: re-fetch conntrack after insertion
init random: handle latent entropy and command line from random_init()
ipc ipc/sem: do not sleep with a spin lock held
kernel timekeeping: Add raw clock fallback for random_get_entropy()
lib assoc_array: Fix BUG_ON during garbage collect
mm zsmalloc: fix races between asynchronous zspage free and page migration
net netfilter: nf_tables: double hook unregistration in netns path
samples samples/bpf, xdpsock: Fix race when running for fix duration of time
scripts kconfig: add fflush() before ferror() check
security lockdown: also lock down previous kgdb use
sound ALSA: usb-audio: Configure sync endpoints before data
tools tools/memory-model/README: Update klitmus7 compat table
usr kbuild: remove include/linux/cyclades.h from header file check
virt KVM: Free new dirty bitmap if creating a new memslot fails
.clang-format genirq/msi: Make interrupt allocation less convoluted
.cocciconfig scripts: add Linux .cocciconfig for coccinelle
.get_maintainer.ignore Opt out of scripts/get_maintainer.pl
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Linux kernel
============

There are several guides for kernel developers and users. These guides can
be rendered in a number of formats, like HTML and PDF. Please read
Documentation/admin-guide/README.rst first.

In order to build the documentation, use ``make htmldocs`` or
``make pdfdocs``.  The formatted documentation can also be read online at:

    https://www.kernel.org/doc/html/latest/

There are various text files in the Documentation/ subdirectory,
several of them using the Restructured Text markup notation.

Please read the Documentation/process/changes.rst file, as it contains the
requirements for building and running the kernel, and information about
the problems which may result by upgrading your kernel.