Skip to content

Commit ee92a12

Browse files
razvandsergiu121
authored andcommitted
Documentation: teaching: Add bonus exercise
An apparently valid ELF file (when doing static analysis) causes a segmentation fault when loaded. The kernel sends out a SIGSEGV signal because something is not right with the ELF program. Use ftrace or some similar tool to identify the root cause of the SIGSEGV in the kernel code. Signed-off-by: Razvan Deaconescu <razvan.deaconescu@cs.pub.ro>
1 parent 0343461 commit ee92a12

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

Documentation/teaching/labs/kernel_profiling.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,3 +432,42 @@ or is it a scheduling issue?
432432
Try to trace the I/O operations using ``perf``, or use the
433433
``iosnoop.sh`` script in order to inspect what I/O is happening at a
434434
certain point.
435+
436+
5. Bad ELF
437+
----------
438+
439+
.. note::
440+
441+
This is a bonus exercise that has been tested on a native Linux system.
442+
It may run under the QEMU virtual machine, but the behavior was weird in our testing.
443+
We recommend you used a native (or VirtualBox or VMware) Linux system.
444+
445+
We managed to build (as part of a `Unikraft <https://github.com/unikraft/unikraft>`__ build) an ELF file that is valid when doing static analysis, but that can't be executed.
446+
The file is ``bad_elf``, located in the ``5-bad-elf/`` folder.
447+
448+
Running it triggers a *segmentation fault* message.
449+
Running it using ``strace`` show an error with ``execve()``.
450+
451+
.. code::
452+
453+
... skels/kernel_profiling/5-bad-elf$ ./bad_elf
454+
Segmentation fault
455+
456+
... skels/kernel_profiling/5-bad-elf$ strace ./bad_elf
457+
execve("./bad_elf", ["./bad_elf"], 0x7ffc3349ba50 /* 70 vars \*/) = -1 EINVAL (Invalid argument)
458+
--- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=NULL} ---
459+
+++ killed by SIGSEGV +++
460+
Segmentation fault (core dumped)
461+
462+
The ELF file itself is valid:
463+
464+
.. code::
465+
466+
... skels/kernel_profiling/5-bad-elf$ readelf -a bad_elf
467+
468+
The issue is to be detected in the kernel.
469+
470+
Use either ``perf``, or, better yet `ftrace <https://jvns.ca/blog/2017/03/19/getting-started-with-ftrace/>`__ to inspect the kernel function calls done by the program.
471+
Identify the function call that sends out the ``SIGSEGV`` signal.
472+
Identify the cause of the issue.
473+
Find that cause in the `manual page elf(5) <https://linux.die.net/man/5/elf>`__.
Binary file not shown.

0 commit comments

Comments
 (0)