sgx-lkl
sgx-lkl copied to clipboard
Segfault on host-side virtio shutdown
The following only happens in sw mode, and only when not having a tty (which is common when running things within a Docker container).
Repro:
cd apps/basic/helloworld
setsid sh -c 'tty; make run-sw' < /dev/null | cat
2020-04-16T10:44:40.7369506Z [[ SGX-LKL ]] lkl_termination_thread(): termination thread unblocked
2020-04-16T10:44:40.7370126Z [ 0.250259] EXT4-fs (vda): re-mounted. Opts: (null)
2020-04-16T10:44:40.7370423Z [LWP 875 exited]
2020-04-16T10:44:40.7370932Z [[ SGX-LKL ]] lkl_termination_thread(): calling lkl_sys_halt()
2020-04-16T10:44:40.7371300Z [ 0.251472] reboot: Restarting system
2020-04-16T10:44:40.7371858Z [[ SGX-LKL ]] lkl_termination_thread(): lthread_detach2() done
2020-04-16T10:44:40.7372478Z [ SGX-LKL ] ethread (3: 0) ethread (2: 0) [LWP 882 exited]
2020-04-16T10:44:40.7372785Z [LWP 881 exited]
2020-04-16T10:44:40.7373070Z ethread (1: 0) init (0: 0 exit=0) [LWP 880 exited]
2020-04-16T10:44:40.7373341Z [LWP 879 exited]
2020-04-16T10:44:40.7373492Z
2020-04-16T10:44:40.7373881Z [ SGX-LKL ] oe_terminate_enclave...
2020-04-16T10:44:40.7374440Z Thread 7 "sgx-lkl-run-oe" received signal SIGSEGV, Segmentation fault.
2020-04-16T10:44:40.7374759Z [Switching to LWP 877]
2020-04-16T10:44:40.7375145Z 0x000000004001452b in virtio_process_queue (dev=0x7ffff7f03008, qidx=0) at host_interface/virtio.c:284
2020-04-16T10:44:40.7375592Z 284 host_interface/virtio.c: No such file or directory.
2020-04-16T10:44:40.7376056Z #0 0x000000004001452b in virtio_process_queue (dev=0x7ffff7f03008, qidx=0) at host_interface/virtio.c:284
2020-04-16T10:44:40.7376613Z #1 0x0000000040011c39 in monitor_console_input (cons_dev=0x7ffff7f03000) at host_interface/virtio_console.c:108
2020-04-16T10:44:40.7377431Z #2 0x00007ffff70736db in start_thread () from /opt/sgx-lkl/bin/../lib/external/libpthread-2-1032040b.27.so
2020-04-16T10:44:40.7378191Z #3 0x00007ffff6d9c88f in clone () from /opt/sgx-lkl/bin/../lib/external/libc-2-cd7c1a03.27.so
I set a breakpoint just before oe_terminate_enclave and I was surprised to see many host threads still running, like console_task, monitor_console_input, netdev_task, blkdevice_thread. Shouldn't they all be shut down by then?
It makes sense that you see those host-side threads, as the segfault happened during the host side termination sequence.
This should be fairly easy to fix, as I suspect that, due to the missing TTY, the host-side of the virtio console was not allocated correctly.