• Reinette Chatre's avatar
    x86/sgx: Fix race between reclaimer and page fault handler · e5d38f18
    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
encl.c 22.3 KB