functional reorganization

Organize the files functionally:
- kmod/core: core kmod source
- kmod/patch: patch kmod source
- kpatch: kpatch script
- kpatch-build: kpatch build script and supporting tools
- contrib: distro-related files
This commit is contained in:
Josh Poimboeuf 2014-02-13 07:49:02 -06:00
parent a8ab0c16a7
commit 4f27b9ae31
17 changed files with 30 additions and 42 deletions

10
.gitignore vendored
View File

@ -1,13 +1,9 @@
kpatch-diff-gen/kpatch-diff-gen
*.o
*.o.cmd
*.ko
*.ko.cmd
*.mod.c
*.swp
kmod/.tmp_versions/
kmod/Module.symvers
kmod/modules.order
tools/add-patches-section
tools/create-diff-object
tools/link-vmlinux-syms
kpatch-build/add-patches-section
kpatch-build/create-diff-object
kpatch-build/link-vmlinux-syms

View File

@ -1,8 +0,0 @@
SUBDIRS = kpatch-kmod tools
.PHONY: clean
clean:
for dir in $(SUBDIRS); do \
$(MAKE) -C $$dir $@; \
done

16
README
View File

@ -18,7 +18,7 @@ This only works on Fedora currently.
First make a patch against the kernel tree, e.g. foo.patch. Then:
sudo scripts/kpatch-build ~/foo.patch
sudo kpatch-build/kpatch-build ~/foo.patch
insmod kpatch.ko kpatch-foo.ko
Voila, your kernel is patched.
@ -51,7 +51,7 @@ patches and environments is conducted.
DEPENDENCIES
kpatch tools require libelf library and development headers to be installed.
kpatch-build tools require libelf library and development headers to be installed.
See GOTCHAS below.
GOTCHAS
@ -67,8 +67,8 @@ git://git.fedorahosted.org/git/elfutils.git
HOWTO
An example script for automating the hotfix module generation is in
scripts/kpatch-build. The script is written for Fedora but should
An example script for automating the hotfix module generation is
kpatch-build/kpatch-build. The script is written for Fedora but should
be adaptable to other distributions with limited changes.
The primary steps in the hotfix module generation process are:
@ -80,16 +80,16 @@ The primary steps in the hotfix module generation process are:
resulting in the changed patched objects
- Unpatch the source tree
- Recompile each changed object with -ffunction-sections -fdata-sections
resulting in the changed base objects
- Use tools/create-diff-object to analyze each base/patched object pair
resulting in the changed original objects
- Use create-diff-object to analyze each original/patched object pair
for patchability and generate an output object containing modified
sections
- Link all the output objects in a into a cumulative object
- Use tools/add-patches-section to add the .patches section that the
- Use add-patches-section to add the .patches section that the
core kpatch module uses to determine the list of functions that need
to be redirected using ftrace
- Generate the hotfix kernel module
- Use tools/link-vmlinux-syms to hardcode non-exported kernel symbols
- Use link-vmlinux-syms to hardcode non-exported kernel symbols
into the symbol table of the hotfix kernel module
DEMONSTRATION

View File

@ -2,9 +2,9 @@ KPATCH_BUILD ?= /usr/lib/modules/$(shell uname -r)/build
KPATCH_MAKE = $(MAKE) -C $(KPATCH_BUILD) M=$(PWD)
obj-m := kpatch.o
kpatch-y := base.o trampoline.o
kpatch-y := core.o trampoline.o
kpatch.ko: base.c trampoline.S
kpatch.ko: core.c trampoline.S
$(KPATCH_MAKE) kpatch.ko
all: kpatch.ko

View File

@ -1,4 +1,4 @@
CFLAGS=-I../kpatch-kmod
CFLAGS=-I../kmod/core
all: create-diff-object add-patches-section link-vmlinux-syms

View File

@ -24,7 +24,7 @@
BASE=$PWD
LOGFILE=$PWD/kpatch-build.log
TOOLSDIR=$BASE/tools
TOOLSDIR=$BASE/kpatch-build
ARCHVERSION=$(uname -r)
DISTROVERSION=${ARCHVERSION%*.*}
CPUS=$(grep -c ^processor /proc/cpuinfo)
@ -56,10 +56,10 @@ then
exit 3
fi
PATCHBASE=`basename $PATCHFILE`
if [[ $PATCHBASE =~ \.patch ]] || [[ $PATCHBASE =~ \.diff ]]
PATCHNAME=`basename $PATCHFILE`
if [[ $PATCHNAME =~ \.patch ]] || [[ $PATCHNAME =~ \.diff ]]
then
PATCHBASE=${PATCHBASE%.*}
PATCHNAME=${PATCHNAME%.*}
fi
cleanup
@ -101,7 +101,7 @@ else
cp -a $KSRCDIR $KSRCDIR_CACHE
fi
cp -R $BASE/kpatch-files/* $BASE/kpatch-kmod $TEMPDIR || die
cp -R $BASE/kmod/patch/* $BASE/kmod/core $TEMPDIR || die
cp vmlinux $TEMPDIR || die
echo "Building patched kernel"
@ -127,36 +127,36 @@ do
done
patch -R -p1 < $PATCHFILE >> $LOGFILE 2>&1
mkdir $TEMPDIR/base
mkdir $TEMPDIR/orig
for i in $(cat $TEMPDIR/changed_objs)
do
rm -f $i
KCFLAGS="-ffunction-sections -fdata-sections" make $i >> $LOGFILE 2>&1 || die
strip -d $i
cp -f $i $TEMPDIR/base/
cp -f $i $TEMPDIR/orig/
done
echo "Extracting new and modified ELF sections"
cd $TEMPDIR
mkdir output
for i in base/*
for i in orig/*
do
FILE=`basename $i`
$TOOLSDIR/create-diff-object base/$FILE patched/$FILE output/$FILE >> $LOGFILE 2>&1 || die
$TOOLSDIR/create-diff-object orig/$FILE patched/$FILE output/$FILE >> $LOGFILE 2>&1 || die
done
echo "Building base module: kpatch.ko"
cd kpatch-kmod
echo "Building core module: kpatch.ko"
cd core
KPATCH_BUILD=$KSRCDIR make >> $LOGFILE 2>&1 || die
cd ..
echo "Building hotpatch module: kpatch-$PATCHBASE.ko"
echo "Building patch module: kpatch-$PATCHNAME.ko"
ld -r -o output.o output/* >> $LOGFILE 2>&1 || die
$TOOLSDIR/add-patches-section output.o vmlinux >> $LOGFILE 2>&1 || die
KPATCH_BASEDIR=$TEMPDIR/kpatch-kmod KPATCH_BUILD=$KSRCDIR KPATCH_NAME=$PATCHBASE make >> $LOGFILE 2>&1 || die
strip -d kpatch-$PATCHBASE.ko >> $LOGFILE 2>&1 || die
$TOOLSDIR/link-vmlinux-syms kpatch-$PATCHBASE.ko vmlinux >> $LOGFILE 2>&1 || die
KPATCH_BASEDIR=$TEMPDIR/core KPATCH_BUILD=$KSRCDIR KPATCH_NAME=$PATCHNAME make >> $LOGFILE 2>&1 || die
strip -d kpatch-$PATCHNAME.ko >> $LOGFILE 2>&1 || die
$TOOLSDIR/link-vmlinux-syms kpatch-$PATCHNAME.ko vmlinux >> $LOGFILE 2>&1 || die
echo "SUCCESS"
cp -f $TEMPDIR/kpatch-$PATCHBASE.ko $TEMPDIR/kpatch-kmod/kpatch.ko $BASE
cp -f $TEMPDIR/kpatch-$PATCHNAME.ko $TEMPDIR/core/kpatch.ko $BASE
cleanup