From 628bce2ee8493cc30b1d538410deb4cc70aa6a10 Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Tue, 11 Feb 2014 12:01:51 -0600 Subject: [PATCH] add file documentation and copyright Signed-off-by: Seth Jennings --- scripts/kpatch-build | 9 +++++++-- tools/add-patches-section.c | 18 ++++++++++++++++++ tools/create-diff-object.c | 32 ++++++++++++++++++++++++++++++++ tools/link-vmlinux-syms.c | 15 +++++++++++++++ 4 files changed, 72 insertions(+), 2 deletions(-) diff --git a/scripts/kpatch-build b/scripts/kpatch-build index e33ddf3..5bbdf3d 100755 --- a/scripts/kpatch-build +++ b/scripts/kpatch-build @@ -1,12 +1,17 @@ #/bin/bash -# kpatch build script -# +# kpatch build script for Fedora + # This script takes a patch based on the version of the kernel # currently running and creates a kernel module that will # replace modified functions in the kernel such that the # patched code takes effect. +# This script contains Fedora specific nuances and will probably +# not work on other distributions; however, it does serve as a tutorial +# on the various steps involved and should be adaptable to other +# distributions. + # This script: # - Installs the required yum/rpm tools # - Downloads the kernel src rpm for the currently running kernel diff --git a/tools/add-patches-section.c b/tools/add-patches-section.c index eed6be3..c76d429 100644 --- a/tools/add-patches-section.c +++ b/tools/add-patches-section.c @@ -1,3 +1,21 @@ +/* + * tools/add-patches-section.c + * + * Copyright (C) 2014 Seth Jennings + * + * This tool takes an elf object, the output of create-diff-object + * and the base vmlinux as arguments and adds two new sections + * to the elf object; .patches and .rela.patches. + * + * These two sections allow the kpatch core modules to know which + * functions are overridden by the patch module. + * + * For each struct kpatch_patch entry in the .patches section, the core + * module will register the new function as an ftrace handler for the + * old function. The new function will return to the caller of the old + * function, not the old function itself, bypassing the old function. + */ + #include #include #include diff --git a/tools/create-diff-object.c b/tools/create-diff-object.c index 499e30b..9f9b985 100644 --- a/tools/create-diff-object.c +++ b/tools/create-diff-object.c @@ -1,3 +1,35 @@ +/* + * tools/create-diff-object.c + * + * Copyright (C) 2014 Seth Jennings + * Copyright (C) 2013 Josh Poimboeuf + * + * This file contains the heart of the ELF object differencing engine. + * + * The tool takes two ELF objects from two versions of the same source + * file; a "base" object and a "patched" object. These object need to have + * been compiled with the -ffunction-sections and -fdata-sections GCC options. + * + * The tool compares the objects at a section level to determine what + * sections have changed. Once a list of changed sections has been generated, + * various rules are applied to determine any object local sections that + * are dependencies of the changed section and also need to be included in + * the output object. + * + * After all the sections for the output object have been selected, a + * reachability test is performed to ensure that every included section + * is reachable from a changed function symbol. If there is a section that + * is not reachable from a changed function, this means that the source-level + * change can not be captured by employing ftrace and therefore can not be + * dynamically patched by kpatch. Changes to static data structures are an + * example. + * + * If the reachability test succeeds + * - Changed text sections are copied into the output object + * - Changed rela sections have there symbol indexes fixed up + * - shstrtab, strtab, and symtab are all rebuilt from scratch + */ + #include #include #include diff --git a/tools/link-vmlinux-syms.c b/tools/link-vmlinux-syms.c index 818c75e..6295763 100644 --- a/tools/link-vmlinux-syms.c +++ b/tools/link-vmlinux-syms.c @@ -1,3 +1,18 @@ +/* + * tools/link-vmlinux-syms.c + * + * Copyright (C) Seth Jennings + * + * This tools takes the nearly complete hotfix kernel module and + * the base vmlinux. It hardcodes the addresses of any global symbols + * that are referenced by the output object but are not exported by + * vmlinux into the symbol table of the kernel module. + * + * Global symbols that are exported by the base vmlinux can be + * resolved by the kernel module linker at load time and are + * left unmodified. + */ + #include #include #include