Commit Graph

1170 Commits

Author SHA1 Message Date
Jessica Yu
e9fc979712 Merge pull request #637 from arges/636
kpatch and patch module builds fail on Ubuntu 16.04 #636
2016-12-16 10:55:45 -08:00
Josh Poimboeuf
62f8e6daa2 kpatch: retry kpatch load on failure
If a kpatch load fails due to an activeness safety check, try again, up
to 5 times.

Unfortunately, insmod doesn't return the error code reported by the
kernel.  So we have to parse its error output instead.
2016-12-16 11:05:28 -06:00
Josh Poimboeuf
e4f6b5d4c4 kpatch: convert load_module() to use local variables
The kpatch script's functions don't use local variables, which makes it
bug prone and hard to understand.  It would be nice to convert the whole
file, but I'll just start with converting load_module() for now.

This also removes the unused 2nd argument to insmod, which is leftover
from commit 8e8de4718d ("kpatch: deprecate the replace command").
2016-12-16 11:05:28 -06:00
Chris J Arges
eb55adc52d use livepatch 4.5 features in Ubuntu Xenial kernel
Some features were backported into the 4.4 kernel which change the fields
of the livepatch structures. Ensure we can work with either v4.5 or greater,
or Ubuntu 4.4.0-7 or greater.
2016-12-16 07:05:53 -06:00
Chris J Arges
254e8bbe8d kpatch-build: Add UTS_UBUNTU_RELEASE_ABI symbol for utsrelease.h
The UTS_UBUNTU_RELEASE_ABI symbol is in utsrelease.h as installed by
linux-headers-`uname -r`. However when building a module with kpatch-build
utsrelease.h gets regenerated and doesn't include the ABI variable. This
patch just adds the additional define based on the input ARCHVERSION.
2016-12-16 07:05:15 -06:00
Jessica Yu
afc7f12bb7 Merge pull request #638 from jpoimboe/activeness-safety-fixes
kmod/core: fix activeness safety checks for kernels >= 4.6
2016-12-15 12:59:38 -08:00
Jessica Yu
ecaf939291 Merge pull request #640 from jpoimboe/dup-file-symbol
create-diff-object: better error message for dup file+symbol
2016-12-14 21:30:41 -08:00
Josh Poimboeuf
20871391d9 create-diff-object: better error message for dup file+symbol
Give a slightly better error message for the dup file+symbol issue.
It's still cryptic but it's good enough to at least give us kpatch
developers a better idea about what went wrong.  This would have helped
diagnose issue #633 much more quickly.
2016-12-14 15:05:55 -06:00
Josh Poimboeuf
8927b02197 kmod/core: fix activeness safety checks for kernels >= 4.6
If an activeness safety check fails for kernels newer than 4.6, the
error is silently ignored because the newer version of
kpatch_backtrace_address_verify() doesn't set args.ret on error.

It would be an easy fix to just set args->ret on error, but I think a
better approach is just to combine the two versions of the function into
a single function with the use of a little macro trickery.
2016-12-14 10:40:45 -06:00
Jessica Yu
f9cfd80718 Merge pull request #630 from jpoimboe/LDFLAGS_vmlinux
kpatch-build: fix 'undefined reference to kpatch_shadow_*' errors
2016-12-11 23:37:21 -08:00
Jessica Yu
a963ee76ee Merge pull request #631 from jpoimboe/treewide-rebuild-fixes
kpatch-build: fix tree-wide rebuild
2016-12-09 16:17:15 -08:00
Jessica Yu
6a6ff7e8ef Merge pull request #632 from jpoimboe/rhel-rebuild-workaround
kpatch-build: fix tree-wide rebuild on RHEL 7
2016-12-09 14:54:24 -08:00
Josh Poimboeuf
1fc364ee75 kpatch-build: fix tree-wide rebuild on RHEL 7
On RHEL 7 based kernels, copy_user_64.o misuses the .fixup section by
placing a normal function in it.  That confuses create-diff-object.

Work around it by just skipping the file altogether, which is fine to do
because it's an assembly file which should never change anyway.

Fixes #625.
2016-12-06 21:54:05 -06:00
Josh Poimboeuf
5f5fd136bb kpatch-build: fix tree-wide rebuild
For newer kernels, some new objects have been added to the 'head-y'
build target.  These objects aren't directly traceable to vmlinux so
they have to be added manually.

Fixes #626.
2016-12-05 21:13:15 -06:00
Josh Poimboeuf
1330b4a3e5 kpatch-build: fix 'undefined reference to kpatch_shadow_*' errors
When building the patched version of the kernel, vmlinux has to be
linked with the '--warn-unresolved-symbols' linker flag.  Otherwise the
link will fail if the patch uses kpatch-specific symbols like
kpatch_shadow_alloc() and friends.

As of upstream Linux commit b36fad65d61f ("kbuild: Initialize exported
variables"), LDFLAGS_vmlinux= no longer works from the command line,
resulting in '--warn-unresolved-symbols' no longer getting set.

Instead we can use kpatch-gcc to pass the flag to the linker.

Fixes #627.
2016-12-05 20:22:11 -06:00
Jessica Yu
6fa5360c22 Merge pull request #620 from joe-lawrence/617_KASLR_support
Add CONFIG_RANDOMIZE_BASE KASLR support
2016-11-29 13:31:02 -08:00
Joe Lawrence
a6133bba08 Add CONFIG_RANDOMIZE_BASE KASLR support
Backport the symbol lookup and checking code from upstream livepatch
code that relies on a symbol position enumeration rather than a fixed
memory address.

Fixes #617.
2016-11-29 13:55:34 -05:00
Jessica Yu
dc3ef4d6da Merge pull request #616 from rosslagerwall/extable-addend
create-diff-object: Update fixup offsets in .rela__ex_table
2016-11-24 20:04:46 -08:00
Ross Lagerwall
13d61012f9 create-diff-object: Update fixup offsets in .rela__ex_table
When pruning entries from the fixup table, update the offsets in
.rela__ex_table otherwise the relas might point to the wrong fixup entry
or even out of the .fixup section.

Fixes #615.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
2016-11-24 09:15:48 +00:00
Jessica Yu
e0d176465d Merge pull request #622 from jpoimboe/patch-author-guide-updates
doc: some patch author guide updates
2016-11-22 16:51:03 -08:00
Josh Poimboeuf
7535471b1d doc: some patch author guide updates
Update the patch author guide to reflect some recent experiences (with
upstream commits 19be0eaffa3a and 906c55579a63).
2016-11-18 10:59:07 -06:00
Josh Poimboeuf
f47d4c6cfc Merge pull request #621 from flaming-toast/dirty-srcdir
kpatch-build: refresh git index during cleanup if $SRCDIR was a git repository
2016-11-16 11:31:46 -06:00
Jessica Yu
de63a856c0 kpatch-build: refresh git index during cleanup if $SRCDIR was a git repository
If $SRCDIR was a git repo, we leave the repo with a dirty index even after
reversing the patch during cleanup. This gets picked up by
scripts/setlocalversion and consequently subsequent kpatch-builds using the
same $SRCDIR end up with a '+' sign appended to the version string. Fix
this by properly refreshing the index during cleanup.
2016-11-16 02:03:25 -08:00
Jessica Yu
ab012ab5d2 Merge pull request #619 from jpoimboe/kpatch-build-remove-git-dir
kpatch-build: remove ~/.kpatch/src/.git dir on Fedora
2016-11-15 14:22:00 -08:00
Josh Poimboeuf
d200d40569 kpatch-build: remove ~/.kpatch/src/.git dir on Fedora
Source RPMs for recent Fedora kernels have a '.git' subdirectory, which
causes '+' to be appended to the module version magic, causing the
module to fail to load:

  kpatch_readdir: version magic '4.8.6-201.fc24.x86_64+ SMP mod_unload ' should be '4.8.6-201.fc24.x86_64 SMP mod_unload '
2016-11-10 16:50:11 -06:00
Jessica Yu
4e1a5962da Merge pull request #611 from flaming-toast/v0.3.4
bump version to 0.3.4
2016-10-11 11:31:42 -07:00
Jessica Yu
2935ec3de0 bump version to 0.3.4 2016-10-11 11:28:44 -07:00
Josh Poimboeuf
7e00c94c4f Merge pull request #610 from joe-lawrence/skipcleanup
Add kpatch-build --skip-cleanup option
2016-10-11 13:14:42 -05:00
Joe Lawrence
86ba41ee06 Add kpatch-build --skip-cleanup option
Add a switch to kpatch-build that provides an opt-out to the cleanup
portion of the script.  This can be handy when debugging $TEMPDIR or
$RPMTOPDIR contents, as well as inspecting the patched source code
itself.
2016-09-29 16:30:38 -04:00
Josh Poimboeuf
fa557bd11d Merge pull request #609 from jpoimboe/v0.3.3
bump version to 0.3.3
2016-08-19 13:40:18 -04:00
Josh Poimboeuf
6645f8ef44 bump version to 0.3.3 2016-08-19 12:39:24 -05:00
Jessica Yu
835fc0474f Merge pull request #608 from jpoimboe/ipmodify
kmod/core: use FTRACE_OPS_FL_IPMODIFY flag
2016-08-19 10:33:07 -07:00
Josh Poimboeuf
3c7300c341 kmod/core: use FTRACE_OPS_FL_IPMODIFY flag
ftrace only allows a single user of this flag to register for a given
function.  This prevents kpatch conflicts with kprobes handlers which
also might want to change regs->ip for a function.

We should have done this a few years ago.  Better late than never...
2016-08-19 12:09:30 -05:00
Jessica Yu
c305c0b34f Merge pull request #605 from bearieq/master
kpatch-build: do not assume that TEMPDIR is unexported on entry to script
2016-07-25 19:01:56 -07:00
Martin Carroll
145d1289dc kpatch-build: do not assume that TEMPDIR is unexported on entry to script
The user's environment might have TEMPDIR exported.  If so, then kpatch-build
dies with a bogus "invalid ancestor" error. If you turn those bogus errors into
warnings, then the script goes on to incorrectly put into the generated .ko file
every single function that was compiled in the *original* kernel build, thereby
producing an immense .ko file with more than 64k sections that the linux kernel
cannot load.  This fix makes sure that TEMPDIR is unexported on the build of the
original kernel.  Actually, this fix uses a separate KPATCH_GCC_TEMPDIR variable,
so that if the kernel build is interrupted, the cleanup function in the kpatch-kbuild
script will still have TEMPDIR set correctly.

Signed-off-by: Martin Carroll <martin.carroll@alcatel-lucent.com>
2016-07-25 11:02:37 -04:00
Jessica Yu
649764db02 Merge pull request #603 from jpoimboe/warn_on_once
create-diff-object: fix WARN*_ONCE detection on newer kernels
2016-07-15 11:07:36 -07:00
Josh Poimboeuf
6b03bc8ec0 create-diff-object: fix WARN*_ONCE detection on newer kernels
This fixes the detection of WARN_ON_ONCE, WARN_ONCE, and WARN_TAINT_ONCE
on Linux 4.6 and newer.

The signature for those macros changed with upstream Linux commit
dfbf2897d004 ("bug: set warn variable before calling WARN()").

Fixes #602.
2016-07-13 16:53:02 -05:00
Josh Poimboeuf
f678f31898 Merge pull request #601 from flaming-toast/kpatch-elf
Introduce a common kpatch-elf "api"
2016-07-13 10:31:11 -04:00
Jessica Yu
a343edcff0 kpatch-elf: make is_bundleable() a static function
Since is_bundleable() is only called once by kpatch_create_symbol_list(),
and no other kpatch-build tool will need to call this function, we can
simply make it static and local to kpatch-elf.c
2016-07-12 14:45:18 -07:00
Jessica Yu
adcd4581cc kpatch-elf: introduce a common kpatch-elf and logging interface
Introduce a common kpatch elf api by moving all functions and struct
declarations related to manipulating kpatch_elf objects from
create-diff-object to kpatch-elf.{h,c}. Move logging macros to a separate
file log.h, and have kpatch-elf.h include it. These changes will generalize
the kpatch-elf and logging api and make it available to other kpatch-build
tools.
2016-07-12 14:45:16 -07:00
Josh Poimboeuf
8e54471f4a Merge pull request #600 from arges/patch-1
Add section on removing static local references.
2016-07-01 17:07:39 -04:00
Josh Poimboeuf
e6b02cc25c Merge pull request #596 from flaming-toast/altinstructions
Only include .altinstr_replacement if .altinstructions is also included
2016-07-01 17:06:33 -04:00
Jessica Yu
cfe9aff51e create-diff-object: include .altinstr_replacement if .altinstructions is included
Including the .altinstr_replacement section by itself and without
.altinstructions doesn't make sense, as it only serves as a memory area to
hold replacement instructions to be copied over when alternatives are
applied. Don't include .altinstr_replacement unconditionally and only
include it when .altinstructions is also marked as included.
2016-07-01 12:33:28 -07:00
Chris J Arges
b28c2b0638 Add section on removing static local references.
This was discovered when trying to patch a netfilter issue and resulted in the following issue:
https://github.com/dynup/kpatch/issues/599

This patch adds some documentation in case this situation is encountered in the future.
2016-07-01 14:21:29 -05:00
Jessica Yu
03ef5a2ff4 Merge pull request #595 from rosslagerwall/install-fix
kmod: Fix install path
2016-05-06 11:35:59 -07:00
Ross Lagerwall
075c4745f0 kmod: Fix install path
When building against a different kernel from the one that is currently
running, install the kernel module to a directory based on the version
of the target kernel rather than the currently running kernel.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
2016-05-06 10:47:43 +01:00
Josh Poimboeuf
71afb17143 Merge pull request #594 from NonerKao/master
kpatch-build: Add "CONFIG_DEBUG_KERNEL" kernel config checking
2016-05-02 22:28:51 -05:00
Quey-Liang Kao
f4686ee7df kpatch-build: Add "CONFIG_DEBUG_KERNEL" kernel config checking
While the officially supported distributions all have
CONFIG_DEBUG_KERNEL enabled, this is not true for some other
distributions.
This option is necessary when kpatch-build retrieves the
SPECIAL_VARS using readelf command.

Signed-off-by: Quey-Liang Kao <s101062801@m101.nthu.edu.tw>
2016-05-03 04:49:30 +08:00
Josh Poimboeuf
8256149124 Merge pull request #592 from flaming-toast/584
kmod/core: fix stacktrace_ops 'address' function prototype for 4.6
2016-04-28 16:06:16 -05:00
Jessica Yu
684171acc7 kmod/core: fix stacktrace_ops 'address' function prototype for 4.6
Upstream commit 568b329a "perf: generalize perf_callchain" modified the
return type (void -> int) of the address member of struct stacktrace_ops.
Use the void function if the kernel version is < 4.6 or return an int
otherwise.
2016-04-27 14:40:28 -07:00