linux_kernel_hacking / 2_MemoryLoading / 2.1_kpatch /
@Harvey Phillips Harvey Phillips authored on 14 Jun 2020
..
Makefile patching chown in memory! 4 years ago
README.md update readme 4 years ago
chown.patch patching chown in memory! 4 years ago
stub.c patching chown in memory! 4 years ago
README.md

Linux Kernel Hacking

2.0: Loading a Kernel Module from Memory (Kpatching chown)

Patch the kernel with a single executable!

To use:

  • Set up kpatch following these instructions.
  • Build the patch with kpatch-build -t vmlinux -v /lib/debug/boot/vmlinux-<KERNEL>-generic chown.patch
  • Remove the - from the filename (C doesn't like it in variable names)
    • mv livepatch-chown.ko livepatch_chown.ko
  • Build the loader with make
  • Execute as root with sudo ./load
  • chown a file, e.g. chown vagrant:vagrant chown.patch
  • Check output in kernel buffer with dmesg
  • Unload with echo 0 | sudo tee /sys/kernel/livepatch/chown/enabled && sudo rmmod chown