Project Description

When we experience a early boot crash, we are not able to analyze the kernel dump, as user-space wasn't able to load the crash system. The idea is to make the crash system compiled into the host kernel (think of initramfs) so that we can create a kernel dump really early in the boot process.

Goal for the Hackweeks

  1. Investigate if this is possible and the implications it would have (done in HW21)
  2. Hack up a PoC (done in HW22 and HW23)
  3. Prepare RFC series (giving it's only one week, we are entering wishful thinking territory here).

update HW23

  • I was able to include the crash kernel into the kernel Image.
  • I'll need to find a way to load that from init/main.c:start_kernel() probably after kcsan_init()
  • I workaround for a smoke test was to hack kexec_file_load() systemcall which has two problems:
    1. My initramfs in the porduction kernel does not have a new enough kexec version, that's not a blocker but where the week ended
    2. As the crash kernel is part of init.data it will be already stale once I can call kexec_file_load() from user-space.

The solution is probably to rewrite the POC so that the invocation can be done from init.text (that's my theory) but I'm not sure if I can reuse the kexec infrastructure in the kernel from there, which I rely on heavily.

update HW24

  • Day1
    • rebased on v6.12 with no problems others then me breaking the config
    • setting up a new compilation and qemu/virtme env
    • getting desperate as nothing works that used to work
  • Day 2
    • getting to call the invocation of loading the early kernel from __init after kcsan_init()
  • Day 3

    • fix problem of memdup not being able to alloc so much memory... use 64K page sizes for now
    • code refactoring
    • I'm now able to load the crash kernel
    • When using virtme I can boot into the crash kernel, also it doesn't boot completely (major milestone!), crash in elfcorehdr_read_notes()
  • Day 4

    • crash systems crashes (no pun intended) in copy_old_mempage() link; will need to understand elfcorehdr...
    • call path vmcore_init() -> parse_crash_elf_headers() -> elfcorehdr_read() -> read_from_oldmem() -> copy_oldmem_page() -> copy_to_iter()
  • Day 5

    • hacking arch/arm64/kernel/crash_dump.c:copy_old_mempage() to see if crash system really starts. It does.
    • fun fact: retested with more reserved memory and with UEFI FW, host kernel crashes in init but directly starts the crash kernel, so it works (somehow) \o/
  • TODOs

    • fix elfcorehdr so that we actually can make use of all this...
    • test where in the boot __init() chain we can/should call kexec_early_dump()
    • do we really need memdup() or can we used the complied kernel for creating the segments?
    • refactor and rename everything (Kconfig menu shows in wrong place, Kconfig entry needs to go somewhere else, ekdump vs early_dump vs early_kdump

Resources

Looking for hackers with the skills:

kernel kdump

This project is part of:

Hack Week 21 Hack Week 22 Hack Week 23 Hack Week 24

Activity

  • 2 days ago: livdywan liked this project.
  • 2 days ago: huanxie liked this project.
  • 10 days ago: djais joined this project.
  • about 1 month ago: jmodak liked this project.
  • 3 months ago: eomelette joined this project.
  • 3 months ago: m.crivellari liked this project.
  • about 1 year ago: vbabka liked this project.
  • about 1 year ago: pvorel liked this project.
  • almost 2 years ago: jzerebecki liked this project.
  • almost 2 years ago: tdz liked this project.
  • almost 2 years ago: Zildj1an liked this project.
  • almost 2 years ago: Zildj1an joined this project.
  • almost 2 years ago: tschmitz liked this project.
  • almost 2 years ago: paolodepa liked this project.
  • almost 2 years ago: afeijoo liked this project.
  • over 2 years ago: clin liked this project.
  • over 2 years ago: ptesarik liked this project.
  • over 2 years ago: akumar joined this project.
  • over 2 years ago: akumar liked this project.
  • over 2 years ago: coolgw liked this project.
  • over 2 years ago: mbrugger started this project.
  • over 2 years ago: mbrugger added keyword "kdump" to this project.
  • over 2 years ago: mbrugger added keyword "kernel" to this project.
  • over 2 years ago: mbrugger originated this project.

  • Comments

    • mbrugger
      about 1 year ago by mbrugger | Reply

      I got a tip to look into grub2 multiboot. Maybe we can load the crash kernel to the reserved memory region from grub. We then would only need to pass a kernel argument so that the kernel takes this into account.

    • ptesarik
      4 months ago by ptesarik | Reply

      FWIW I was contemplating a similar scheme back in 2016. My idea was to load: 1. kdump kernel 2. kdump initrd 3. production kernel 4. production initrd Then boot into the kdump kernel, update memory maps and kexec to the production kernel. When the production kernel crashes, pass control back to the kdump kernel. For the return to the kdump kernel, I was looking at the KEXEC_PRESERVE_CONTEXT flag, but in the end I doubt it's really helpful without further modifications to the production kernel. At this point, it's probably easier to boot the production kernel first and set up an initial crash kernel at early boot.

      Good luck!

    Similar Projects

    Contributing to Linux Kernel security by pperego

    Description

    A couple of weeks ago, I found this blog post by Gustavo Silva, a Linux Kernel contributor.

    I always strived to start again into hacking the Linux Kernel, so I asked Coverity scan dashboard access and I want to contribute to Linux Kernel by fixing some minor issues.

    I want also to create a Linux Kernel fuzzing lab using qemu and syzkaller

    Goals

    1. Fix at least 2 security bugs
    2. Create the fuzzing lab and having it running

    Resources

    The dashboard

    The serie of blog posts by Gustavo Silva inspiring this project.

    An email with some quick "where to start" instructions The patchset philosophy


    Create a DRM driver for VGA video cards by tdz

    Yes, those VGA video cards. The goal of this project is to implement a DRM graphics driver for such devices. While actual hardware is hard to obtain or even run today, qemu emulates VGA output.

    VGA has a number of limitations, which make this project interesting.

    • There are only 640x480 pixels (or less) on the screen. That resolution is also a soft lower limit imposed by DRM. It's mostly a problem for desktop environments though.
    • Desktop environments assume 16 million colors, but there are only 16 colors with VGA. VGA's 256 color palette is not available at 640x480. We can choose those 16 colors freely. The interesting part is how to choose them. We have to build a palette for the displayed frame and map each color to one of the palette's 16 entries. This is called dithering, and VGA's limitations are a good opportunity to learn about dithering algorithms.
    • VGA has an interesting memory layout. Most graphics devices use linear framebuffers, which store the pixels byte by byte. VGA uses 4 bitplanes instead. Plane 0 holds all bits 0 of all pixels. Plane 1 holds all bits 1 of all pixels, and so on.

    The driver will probably not be useful to many people. But, if finished, it can serve as test environment for low-level hardware. There's some interest in supporting old Amiga and Atari framebuffers in DRM. Those systems have similar limitations as VGA, but are harder to obtain and test with. With qemu, the VGA driver could fill this gap.

    Apart from the Wikipedia entry, good resources on VGA are at osdev.net and FreeVGA


    Modernize ocfs2 by goldwynr

    Ocfs2 has gone into a stage of neglect and disrepair. Modernize the code to generate enough interest.

    Goals: * Change the mount sequence to use fscontext * Move from using bufferhead to bio/folios * Use iomap * Run it through xfstests


    FizzBuzz OS by mssola

    Project Description

    FizzBuzz OS (or just fbos) is an idea I've had in order to better grasp the fundamentals of the low level of a RISC-V machine. In practice, I'd like to build a small Operating System kernel that is able to launch three processes: one that simply prints "Fizz", another that prints "Buzz", and the third which prints "FizzBuzz". These processes are unaware of each other and it's up to the kernel to schedule them by using the timer interrupts as given on openSBI (fizz on % 3 seconds, buzz on % 5 seconds, and fizzbuzz on % 15 seconds).

    This kernel provides just one system call, write, which allows any program to pass the string to be written into stdout.

    This project is free software and you can find it here.

    Goal for this Hackweek

    • Better understand the RISC-V SBI interface.
    • Better understand RISC-V in privileged mode.
    • Have fun.

    Resources


    Improve UML page fault handler by ptesarik

    Description

    Improve UML handling of segmentation faults in kernel mode. Although such page faults are generally caused by a kernel bug, it is annoying if they cause an infinite loop, or panic the kernel. More importantly, a robust implementation allows to write KUnit tests for various guard pages, preventing potential kernel self-protection regressions.

    Goals

    Convert the UML page fault handler to use oops_* helpers, go through a few review rounds and finally get my patch series merged in 6.14.

    Resources

    Wrong initial attempt: https://lore.kernel.org/lkml/20231215121431.680-1-petrtesarik@huaweicloud.com/T/