2014-02-17 15:54:25 +00:00
|
|
|
kpatch: dynamic kernel patching
|
|
|
|
===============================
|
2014-02-11 20:34:19 +00:00
|
|
|
|
|
|
|
kpatch is a tool for the generation and application of kernel
|
|
|
|
modules that patch a running Linux kernel while in operation,
|
|
|
|
without requiring a reboot. This is very valuable in cases
|
|
|
|
where critical workloads, which do not have high availability via
|
|
|
|
scale-out, run on a single machine and are very downtime
|
|
|
|
sensitive or require a heavyweight approval process and
|
|
|
|
notification of workload users in the event of downtime.
|
|
|
|
|
2014-02-13 16:04:35 +00:00
|
|
|
|
2014-02-17 15:54:25 +00:00
|
|
|
Installation
|
|
|
|
------------
|
2014-02-13 16:04:35 +00:00
|
|
|
|
|
|
|
The default install prefix is in /usr/local.
|
|
|
|
|
|
|
|
make
|
|
|
|
sudo make install
|
|
|
|
|
|
|
|
|
2014-02-17 15:54:25 +00:00
|
|
|
Quick Start
|
|
|
|
-----------
|
2014-02-13 03:53:05 +00:00
|
|
|
|
2014-02-17 15:54:25 +00:00
|
|
|
*NOTE: While kpatch is designed to work with any recent Linux
|
2014-02-13 16:04:35 +00:00
|
|
|
kernel on any distribution, the "kpatch build" command currently
|
2014-02-17 15:54:25 +00:00
|
|
|
only works on Fedora.*
|
2014-02-13 03:53:05 +00:00
|
|
|
|
2014-02-14 20:47:11 +00:00
|
|
|
First, use diff to make a source patch against the kernel tree, e.g. foo.patch.
|
2014-02-13 16:18:46 +00:00
|
|
|
Then:
|
2014-02-13 03:53:05 +00:00
|
|
|
|
2014-02-14 20:47:11 +00:00
|
|
|
kpatch build foo.patch
|
2014-02-13 16:04:35 +00:00
|
|
|
sudo insmod kpatch.ko kpatch-foo.ko
|
2014-02-13 03:53:05 +00:00
|
|
|
|
|
|
|
Voila, your kernel is patched.
|
|
|
|
|
2014-02-13 16:04:35 +00:00
|
|
|
|
2014-02-17 15:54:25 +00:00
|
|
|
License
|
|
|
|
-------
|
2014-02-11 18:00:17 +00:00
|
|
|
|
|
|
|
kpatch is under the GPLv2 license.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
2014-02-17 15:54:25 +00:00
|
|
|
|
|
|
|
Status
|
|
|
|
------
|
2014-02-11 18:00:17 +00:00
|
|
|
|
|
|
|
kpatch is currently is early development. For now, it should _not_ be used
|
|
|
|
in production environments until significantly more testing on various
|
|
|
|
patches and environments is conducted.
|
|
|
|
|
2014-02-17 15:54:25 +00:00
|
|
|
|
|
|
|
Dependencies
|
|
|
|
------------
|
2014-02-11 18:00:17 +00:00
|
|
|
|
2014-02-13 13:49:02 +00:00
|
|
|
kpatch-build tools require libelf library and development headers to be installed.
|
2014-02-17 15:54:25 +00:00
|
|
|
See Gotchas section below.
|
2014-02-11 18:00:17 +00:00
|
|
|
|
2014-02-17 15:54:25 +00:00
|
|
|
|
|
|
|
Gotchas
|
|
|
|
-------
|
2014-02-11 18:00:17 +00:00
|
|
|
|
|
|
|
The version of elfutils (namely libelf) that ship with most distros as of
|
|
|
|
the time of this writing, have a bug in libelf that is exposed by kpatch.
|
|
|
|
|
|
|
|
elfutils-0.158 or higher contains the fix.
|
|
|
|
|
|
|
|
The specific commit is 88ad5ddb71bd1fa8ed043a840157ebf23c0057b3.
|
|
|
|
|
|
|
|
git://git.fedorahosted.org/git/elfutils.git
|
|
|
|
|
2014-02-17 15:54:25 +00:00
|
|
|
|
|
|
|
Patch module generation algorithm
|
|
|
|
---------------------------------
|
2014-02-11 18:00:17 +00:00
|
|
|
|
2014-02-13 16:51:00 +00:00
|
|
|
An example script for automating the patch module generation is
|
2014-02-13 13:49:02 +00:00
|
|
|
kpatch-build/kpatch-build. The script is written for Fedora but should
|
2014-02-11 18:00:17 +00:00
|
|
|
be adaptable to other distributions with limited changes.
|
|
|
|
|
2014-02-13 16:51:00 +00:00
|
|
|
The primary steps in the patch module generation process are:
|
2014-02-11 18:00:17 +00:00
|
|
|
- Building the unstripped vmlinux for the kernel
|
|
|
|
- Patching the source tree
|
|
|
|
- Rebuilding vmlinux and monitoring which objects are building rebuilt.
|
|
|
|
These are the "changed objects".
|
|
|
|
- Recompile each changed object with -ffunction-sections -fdata-sections
|
|
|
|
resulting in the changed patched objects
|
|
|
|
- Unpatch the source tree
|
|
|
|
- Recompile each changed object with -ffunction-sections -fdata-sections
|
2014-02-13 13:49:02 +00:00
|
|
|
resulting in the changed original objects
|
|
|
|
- Use create-diff-object to analyze each original/patched object pair
|
2014-02-11 18:00:17 +00:00
|
|
|
for patchability and generate an output object containing modified
|
|
|
|
sections
|
|
|
|
- Link all the output objects in a into a cumulative object
|
2014-02-13 13:49:02 +00:00
|
|
|
- Use add-patches-section to add the .patches section that the
|
2014-02-11 18:00:17 +00:00
|
|
|
core kpatch module uses to determine the list of functions that need
|
|
|
|
to be redirected using ftrace
|
2014-02-13 16:51:00 +00:00
|
|
|
- Generate the patch kernel module
|
2014-02-13 13:49:02 +00:00
|
|
|
- Use link-vmlinux-syms to hardcode non-exported kernel symbols
|
2014-02-13 16:51:00 +00:00
|
|
|
into the symbol table of the patch kernel module
|
2014-02-11 20:34:19 +00:00
|
|
|
|
|
|
|
|
2014-02-17 15:54:25 +00:00
|
|
|
Demonstration
|
|
|
|
-------------
|
|
|
|
|
|
|
|
A low-level demonstration of kpatch is available on Youtube:
|
2014-02-11 20:34:19 +00:00
|
|
|
|
|
|
|
http://www.youtube.com/watch?v=WeSmG-XirC4
|
|
|
|
|
2014-02-17 15:54:25 +00:00
|
|
|
This demonstration completes each step in the previous section in a manual
|
2014-02-11 20:34:19 +00:00
|
|
|
fashion. However, from a end-user perspective, most of these steps will
|
|
|
|
be hidden away in scripts (eventually).
|