From 31bf92881714fe9962d43d097b5114a9b4ad0a12 Mon Sep 17 00:00:00 2001 From: Sami Tolvanen Date: Wed, 13 Jan 2021 15:23:11 -0800 Subject: [PATCH 1/4] x86/sgx: Fix the return type of sgx_init() device_initcall() expects a function of type initcall_t, which returns an integer. Change the signature of sgx_init() to match. Fixes: e7e0545299d8c ("x86/sgx: Initialize metadata for Enclave Page Cache (EPC) sections") Signed-off-by: Sami Tolvanen Signed-off-by: Borislav Petkov Reviewed-by: Darren Kenny Reviewed-by: Jarkko Sakkinen Link: https://lkml.kernel.org/r/20210113232311.277302-1-samitolvanen@google.com --- arch/x86/kernel/cpu/sgx/main.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index c519fc5f6948..8df81a3ed945 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -700,25 +700,27 @@ static bool __init sgx_page_cache_init(void) return true; } -static void __init sgx_init(void) +static int __init sgx_init(void) { int ret; int i; if (!cpu_feature_enabled(X86_FEATURE_SGX)) - return; + return -ENODEV; if (!sgx_page_cache_init()) - return; + return -ENOMEM; - if (!sgx_page_reclaimer_init()) + if (!sgx_page_reclaimer_init()) { + ret = -ENOMEM; goto err_page_cache; + } ret = sgx_drv_init(); if (ret) goto err_kthread; - return; + return 0; err_kthread: kthread_stop(ksgxd_tsk); @@ -728,6 +730,8 @@ err_page_cache: vfree(sgx_epc_sections[i].pages); memunmap(sgx_epc_sections[i].virt_addr); } + + return ret; } device_initcall(sgx_init); From 3ac517313b929619dbb7ceae005ec66d0859b23b Mon Sep 17 00:00:00 2001 From: Jarkko Sakkinen Date: Thu, 21 Jan 2021 04:42:56 +0200 Subject: [PATCH 2/4] MAINTAINERS: Fix the tree location for INTEL SGX patches After a discussion with Boris et al, I've come to realize that a disjoint GIT tree for SGX does not make any sense. Instead, follow the pattern of other MAINTAINERS entries, IRQ DOMAINS for instance, and re-define T-entry so that it will reference the pre-existing topic branch for SGX. As Boris explained to me, reviewed patches will be routinely picked to this branch. Fixes: bc4bac2ecef0 ("x86/sgx: Update MAINTAINERS") Signed-off-by: Jarkko Sakkinen Signed-off-by: Borislav Petkov Link: https://lkml.kernel.org/r/20210121024256.54565-1-jarkko@kernel.org --- MAINTAINERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index cc1e6a5ee6e6..5b66de2097d6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9230,7 +9230,7 @@ M: Jarkko Sakkinen L: linux-sgx@vger.kernel.org S: Supported Q: https://patchwork.kernel.org/project/intel-sgx/list/ -T: git git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-sgx.git +T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/sgx F: Documentation/x86/sgx.rst F: arch/x86/entry/vdso/vsgx.S F: arch/x86/include/uapi/asm/sgx.h From dc9b7be557ca94301ea5c06c0d72307e642ffb18 Mon Sep 17 00:00:00 2001 From: Daniel Vetter Date: Thu, 4 Feb 2021 19:45:19 +0100 Subject: [PATCH 3/4] x86/sgx: Drop racy follow_pfn() check 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 Signed-off-by: Daniel Vetter Signed-off-by: Borislav Petkov Reviewed-by: Jarkko Sakkinen Link: https://lkml.kernel.org/r/20210204184519.2809313-1-daniel.vetter@ffwll.ch --- 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); From 848477782bfa2b6aec738045246abd6cd104006c Mon Sep 17 00:00:00 2001 From: Jarkko Sakkinen Date: Fri, 5 Feb 2021 17:15:44 +0200 Subject: [PATCH 4/4] MAINTAINERS: Add Dave Hansen as reviewer for INTEL SGX Add Dave as reviewer for INTEL SGX patches. Signed-off-by: Jarkko Sakkinen Signed-off-by: Borislav Petkov Acked-by: Dave Hansen Link: https://lkml.kernel.org/r/20210205151546.144810-1-jarkko@kernel.org --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 5b66de2097d6..41b78e20bd1f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9227,6 +9227,7 @@ F: include/linux/tboot.h INTEL SGX M: Jarkko Sakkinen +R: Dave Hansen L: linux-sgx@vger.kernel.org S: Supported Q: https://patchwork.kernel.org/project/intel-sgx/list/