x86/sgx: Drop racy follow_pfn() check
authorDaniel Vetter <daniel.vetter@ffwll.ch>
Thu, 4 Feb 2021 18:45:19 +0000 (19:45 +0100)
committerBorislav Petkov <bp@suse.de>
Fri, 5 Feb 2021 09:45:11 +0000 (10:45 +0100)
PTE insertion is fundamentally racy, and this check doesn't do anything
useful. Quoting Sean:

  "Yeah, it can be whacked. The original, never-upstreamed code asserted
  that the resolved PFN matched the PFN being installed by the fault
  handler as a sanity check on the SGX driver's EPC management. The
  WARN assertion got dropped for whatever reason, leaving that useless
  chunk."

Jason stumbled over this as a new user of follow_pfn(), and I'm trying
to get rid of unsafe callers of that function so it can be locked down
further.

This is independent prep work for the referenced patch series:

  https://lore.kernel.org/dri-devel/20201127164131.2244124-1-daniel.vetter@ffwll.ch/

Fixes: 947c6e11fa43 ("x86/sgx: Add ptrace() support for the SGX driver")
Reported-by: Jason Gunthorpe <jgg@ziepe.ca>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Link: https://lkml.kernel.org/r/20210204184519.2809313-1-daniel.vetter@ffwll.ch
arch/x86/kernel/cpu/sgx/encl.c

index ee50a501027712f3ede1a7c9bfabd910d2500623..20a2dd5ba2b41b6dede9979ae73a8323bb9b3303 100644 (file)
@@ -141,7 +141,6 @@ static vm_fault_t sgx_vma_fault(struct vm_fault *vmf)
        struct sgx_encl_page *entry;
        unsigned long phys_addr;
        struct sgx_encl *encl;
-       unsigned long pfn;
        vm_fault_t ret;
 
        encl = vma->vm_private_data;
@@ -168,13 +167,6 @@ static vm_fault_t sgx_vma_fault(struct vm_fault *vmf)
 
        phys_addr = sgx_get_epc_phys_addr(entry->epc_page);
 
-       /* Check if another thread got here first to insert the PTE. */
-       if (!follow_pfn(vma, addr, &pfn)) {
-               mutex_unlock(&encl->lock);
-
-               return VM_FAULT_NOPAGE;
-       }
-
        ret = vmf_insert_pfn(vma, addr, PFN_DOWN(phys_addr));
        if (ret != VM_FAULT_NOPAGE) {
                mutex_unlock(&encl->lock);