| .. | |||
| README.md | 5 years ago | ||
| meminfo-string.patch | 5 years ago | ||
In order to patch existing kernel functions, you have to be able to resolve relocatable symbols in the currently running kernel. Doing this manually would be very difficult and time-consuming, so kpatch was created.
Kpatch works by first building the kernel tree normally, then rebuilding it with a patch provided as a source diff. Next, it takes the object files that changed, and rebuilds them again (both with and without the patch) with the GCC options -ffunction-sections and -fdata-sections. These two options cause all functions and data items to get their own sections, so that they can be found more easily without having to know precise offsets. Now the ELF relocation table can be built for the patched object file, and the kernel module is generated.
Setting up kpatch:
apt install dpkg-dev devscripts elfutils ccacheapt build-dep linuxgit clone git@github.com:dynup/kpatch.gitcd kpatch; make installlinux-image-unsigned-<KERNEL VERSION>-generic-dbgsym_<KERNEL VERSION>_amd64.ddebdpkg -i <path to .ddeb>To use:
grep -i vmallocchunk /proc/meminfokpatch-build -t vmlinux --vmlinux /lib/debug/boot/vmlinux-$(uname -r) meminfo-string.patchinsmod livepatch-meminfo-string.kogrep -i vmallocchunk /proc/meminfo again - notice that it's now in all-capsecho 0 | sudo tee /sys/kernel/livepatch/livepatch-meminfo-string/enabledrmmod livepatch-meminfo-string.koTested on Ubuntu 20.04 running under Vagrant. Helful Source: https://ruffell.nz/programming/writeups/2020/04/20/everything-you-wanted-to-know-about-kernel-livepatch-in-ubuntu.html.