* [PATCH] x86/sgx: Drop racy follow_pfn check
@ 2021-02-04 18:45 Daniel Vetter
2021-02-05 2:26 ` Jarkko Sakkinen
2021-02-05 2:26 ` Jarkko Sakkinen
0 siblings, 2 replies; 5+ messages in thread
From: Daniel Vetter @ 2021-02-04 18:45 UTC (permalink / raw)
To: LKML
Cc: Daniel Vetter, Jason Gunthorpe, Sean Christopherson,
Jarkko Sakkinen, Borislav Petkov, linux-sgx, Daniel Vetter
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.
References: https://lore.kernel.org/dri-devel/20201127164131.2244124-1-daniel.vetter@ffwll.ch/
Reported-by: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Sean Christopherson <seanjc@google.com>
Fixes: 947c6e11fa43 ("x86/sgx: Add ptrace() support for the SGX driver")
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Cc: Borislav Petkov <bp@suse.de>
Cc: linux-sgx@vger.kernel.org
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
---
arch/x86/kernel/cpu/sgx/encl.c | 8 --------
1 file changed, 8 deletions(-)
diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
index ee50a5010277..20a2dd5ba2b4 100644
--- a/arch/x86/kernel/cpu/sgx/encl.c
+++ b/arch/x86/kernel/cpu/sgx/encl.c
@@ -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);
--
2.30.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] x86/sgx: Drop racy follow_pfn check
2021-02-04 18:45 [PATCH] x86/sgx: Drop racy follow_pfn check Daniel Vetter
@ 2021-02-05 2:26 ` Jarkko Sakkinen
2021-02-05 2:26 ` Jarkko Sakkinen
1 sibling, 0 replies; 5+ messages in thread
From: Jarkko Sakkinen @ 2021-02-05 2:26 UTC (permalink / raw)
To: Daniel Vetter
Cc: LKML, Jason Gunthorpe, Sean Christopherson, Borislav Petkov,
linux-sgx, Daniel Vetter
On Thu, Feb 04, 2021 at 07:45:19PM +0100, Daniel Vetter wrote:
> 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."
Love the "whatever reason" part :-)
Shame, I was *going to* rip this off maybe around iteration v40. I have
no idea why I did not. Even backtraced years old email threads from lore.
Probably just forgot to remove it.
So, yeah, I fully agree removing it.
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
> 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.
Apologies, consider it my bad...
/Jarkko
>
> References: https://lore.kernel.org/dri-devel/20201127164131.2244124-1-daniel.vetter@ffwll.ch/
> Reported-by: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: Sean Christopherson <seanjc@google.com>
> Fixes: 947c6e11fa43 ("x86/sgx: Add ptrace() support for the SGX driver")
> Cc: Jarkko Sakkinen <jarkko@kernel.org>
> Cc: Borislav Petkov <bp@suse.de>
> Cc: linux-sgx@vger.kernel.org
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> ---
> arch/x86/kernel/cpu/sgx/encl.c | 8 --------
> 1 file changed, 8 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
> index ee50a5010277..20a2dd5ba2b4 100644
> --- a/arch/x86/kernel/cpu/sgx/encl.c
> +++ b/arch/x86/kernel/cpu/sgx/encl.c
> @@ -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);
> --
> 2.30.0
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86/sgx: Drop racy follow_pfn check
2021-02-04 18:45 [PATCH] x86/sgx: Drop racy follow_pfn check Daniel Vetter
2021-02-05 2:26 ` Jarkko Sakkinen
@ 2021-02-05 2:26 ` Jarkko Sakkinen
2021-02-05 7:43 ` Daniel Vetter
1 sibling, 1 reply; 5+ messages in thread
From: Jarkko Sakkinen @ 2021-02-05 2:26 UTC (permalink / raw)
To: Daniel Vetter
Cc: LKML, Jason Gunthorpe, Sean Christopherson, Borislav Petkov,
linux-sgx, Daniel Vetter
On Thu, Feb 04, 2021 at 07:45:19PM +0100, Daniel Vetter wrote:
> References: https://lore.kernel.org/dri-devel/20201127164131.2244124-1-daniel.vetter@ffwll.ch/
What is the difference between this and "Link:" anyway?
/Jarkko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86/sgx: Drop racy follow_pfn check
2021-02-05 2:26 ` Jarkko Sakkinen
@ 2021-02-05 7:43 ` Daniel Vetter
2021-02-07 21:16 ` Jarkko Sakkinen
0 siblings, 1 reply; 5+ messages in thread
From: Daniel Vetter @ 2021-02-05 7:43 UTC (permalink / raw)
To: Jarkko Sakkinen
Cc: LKML, Jason Gunthorpe, Sean Christopherson, Borislav Petkov,
linux-sgx, Daniel Vetter
On Fri, Feb 5, 2021 at 3:26 AM Jarkko Sakkinen <jarkko@kernel.org> wrote:
>
> On Thu, Feb 04, 2021 at 07:45:19PM +0100, Daniel Vetter wrote:
> > References: https://lore.kernel.org/dri-devel/20201127164131.2244124-1-daniel.vetter@ffwll.ch/
>
> What is the difference between this and "Link:" anyway?
Afaik References: is for other reading (bug reports, discussions,
other patch series), Link: is for patch submission itself (which I
think some subsystem do an entire chain of, on each revision). My
scripts aren't good enough that they add the Link: before submitting,
I add them when I apply patches (since most patches I get don't have
them anyway).
btw since the final patch to remove follow_pfn won't be ready for 5.12
merge window (kvm and vfio have some work to do) I think it's best if
you just queue this up in your tree?
Thanks, Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86/sgx: Drop racy follow_pfn check
2021-02-05 7:43 ` Daniel Vetter
@ 2021-02-07 21:16 ` Jarkko Sakkinen
0 siblings, 0 replies; 5+ messages in thread
From: Jarkko Sakkinen @ 2021-02-07 21:16 UTC (permalink / raw)
To: Daniel Vetter
Cc: LKML, Jason Gunthorpe, Sean Christopherson, Borislav Petkov,
linux-sgx, Daniel Vetter
On Fri, Feb 05, 2021 at 08:43:24AM +0100, Daniel Vetter wrote:
> On Fri, Feb 5, 2021 at 3:26 AM Jarkko Sakkinen <jarkko@kernel.org> wrote:
> >
> > On Thu, Feb 04, 2021 at 07:45:19PM +0100, Daniel Vetter wrote:
> > > References: https://lore.kernel.org/dri-devel/20201127164131.2244124-1-daniel.vetter@ffwll.ch/
> >
> > What is the difference between this and "Link:" anyway?
>
> Afaik References: is for other reading (bug reports, discussions,
> other patch series), Link: is for patch submission itself (which I
> think some subsystem do an entire chain of, on each revision). My
> scripts aren't good enough that they add the Link: before submitting,
> I add them when I apply patches (since most patches I get don't have
> them anyway).
>
> btw since the final patch to remove follow_pfn won't be ready for 5.12
> merge window (kvm and vfio have some work to do) I think it's best if
> you just queue this up in your tree?
Boris has queued this to tip x86/sgx.
> Thanks, Daniel
> --
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch
>
/Jarkko
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-02-07 21:17 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-04 18:45 [PATCH] x86/sgx: Drop racy follow_pfn check Daniel Vetter
2021-02-05 2:26 ` Jarkko Sakkinen
2021-02-05 2:26 ` Jarkko Sakkinen
2021-02-05 7:43 ` Daniel Vetter
2021-02-07 21:16 ` Jarkko Sakkinen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).