[for_v21] x86/sgx: Flush work if and only if the work struct has been init'd
diff mbox series

Message ID 20190712035606.6056-1-sean.j.christopherson@intel.com
State New
Headers show
Series
  • [for_v21] x86/sgx: Flush work if and only if the work struct has been init'd
Related show

Commit Message

Sean Christopherson July 12, 2019, 3:56 a.m. UTC
flush_work() complains if it is invoked with a null work function, and
the enclave's work function isn't initialized until the create ioctl().

WARNING: CPU: 10 PID: 1619 at linux/kernel/workqueue.c:3031 __flush_work+0x198/0x1b0
Modules linked in:
CPU: 10 PID: 1619 Comm: lsdt Tainted: G        W         5.2.0-rc2+ #651
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/2015
RIP: 0010:__flush_work+0x198/0x1b0
Code: <0f> 0b 31 c0 eb b7 e8 4d fa fd ff 0f 1f 00 66 2e 0f 1f 84 00 00 00
RSP: 0018:ffffc900011b7c60 EFLAGS: 00010246
RAX: 0000000000000000 RBX: ffff88846c79a020 RCX: 0000000000000000
RDX: ffff888465cc8000 RSI: 0000000000000000 RDI: ffff88846c79a240
RBP: ffff88846c79a240 R08: 0000000000000000 R09: 0000000000000000
R10: ffff8884683aba10 R11: 0000000000000001 R12: ffff88846c79a050
R13: ffff88846c79a040 R14: dead000000000200 R15: ffff88846d447f00
FS:  00007f110c801700(0000) GS:ffff88846fb00000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000000c420009b80 CR3: 0000000005009003 CR4: 0000000000360ee0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 ? kmem_cache_free+0x187/0x1b0
 sgx_release+0xa8/0xd0
 __fput+0xad/0x210
 task_work_run+0x84/0xa0
 do_exit+0x2db/0xb40
 do_group_exit+0x3a/0xa0
 get_signal+0x14e/0x7b0
 do_signal+0x30/0x680
 ? __x64_sys_futex+0x134/0x180
 exit_to_usermode_loop+0x61/0xd0
 do_syscall_64+0xfb/0x120
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 arch/x86/kernel/cpu/sgx/driver/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/arch/x86/kernel/cpu/sgx/driver/main.c b/arch/x86/kernel/cpu/sgx/driver/main.c
index 2d1943c13879..45e2dd8c2845 100644
--- a/arch/x86/kernel/cpu/sgx/driver/main.c
+++ b/arch/x86/kernel/cpu/sgx/driver/main.c
@@ -51,7 +51,8 @@  static int sgx_release(struct inode *inode, struct file *file)
 	encl->flags |= SGX_ENCL_DEAD;
 	mutex_unlock(&encl->lock);
 
-	flush_work(&encl->work);
+	if (encl->work.func)
+		flush_work(&encl->work);
 	kref_put(&encl->refcount, sgx_encl_release);
 
 	return 0;