Commit Graph

1145 Commits

Author SHA1 Message Date
Joe Lawrence
97be7f57fb testing: add full path for /sbin executables
"/sbin" might not be in the user's path, so prefix callouts to such
utilities with their full path.
2017-01-13 13:54:35 -05:00
Joe Lawrence
f7b59ca809 testing: skip combined test for a single patch
If kpatch-test processes a single .patch file, it will skip creating a
COMBINED.patch.

Do the same on the testing side (instead of complaining that it "can't
find kpatch-COMBINED.ko, skipping.")
2017-01-13 13:54:35 -05:00
Joe Lawrence
1096da7155 testing: handle empty glob cases
If kpatch-test looks for *.patch or *.test globs in a directory that
contains no such files, it will try to handle a single file named
"*.patch" or "*.test".

Set the global nullglob option to avoid this problem.  At the same time,
stop and whine to the user if no .patch files were found.
2017-01-13 13:54:04 -05:00
Josh Poimboeuf
23bc1bc93d Merge pull request #624 from joe-lawrence/integration_tests
Update integration tests
2016-12-21 09:39:03 -06:00
Jessica Yu
823158d15d Merge pull request #647 from joe-lawrence/livepatch_compat
kpatch: better support for livepatch modules
2016-12-20 14:38:26 -08:00
Joe Lawrence
b55dfb7dee kpatch: better support for livepatch modules
Livepatch modules can be supported with minimal changes to the kpatch
script.  Adjust for appropriate sysfs paths, core-patching code (in
kernel for livepatch, kpatch.ko for kpatch), and checksum verification
(only verify the checksum if it exists).

Fixes #479.
2016-12-20 16:34:41 -05:00
Jessica Yu
5046cc9243 Merge pull request #644 from jpoimboe/no-seg-fault
create-diff-object: print error message instead of seg faulting
2016-12-20 11:55:27 -08:00
Jessica Yu
f6918090ff Merge pull request #645 from jpoimboe/kpatch-build-debug
kpatch-build: reduce the debug firehose
2016-12-20 10:42:06 -08:00
Josh Poimboeuf
c27b3206cf Merge pull request #643 from jpoimboe/gcc-6-rodata-str
create-diff-object: support gcc 6 per-function string tables
2016-12-20 10:30:40 -06:00
Josh Poimboeuf
d3d8a603e2 kpatch-build: reduce the debug firehose
When passing '-d' to kpatch-build, it prints out some useful information
and keeps the related files around in ~/.kpatch/tmp.  However, it also
passes '-d' to create-diff-object, which spits out way too much
information, drowning out all the other useful messages printed by
kpatch-build.

In my experience, the create-diff-object debug info is overkill for
debugging most issues, so disable it.  The flag can still be used when
running create-diff-object manually.
2016-12-19 17:36:06 -06:00
Josh Poimboeuf
79fd538f51 create-diff-object: print error message instead of seg faulting
Related to issue #629, print a useful error message at the time of the
original error condition instead of seg faulting later.
2016-12-19 17:29:57 -06:00
Josh Poimboeuf
bfc24c745d create-diff-object: support gcc 6 per-function string tables
With older versions of gcc, string tables were stored in a few
.rodata.str1.* sections:

  # eu-readelf -S patched/fs/proc/meminfo.o |grep rodata
  [ 6] .rodata.str1.1       PROGBITS     0000000000000000 0000005c 00000008  1 AMS    0   0  1
  [11] .rodata.str1.8       PROGBITS     0000000000000000 000000a0 00000364  1 AMS    0   0  8
  [16] .rodata.meminfo_proc_fops PROGBITS     0000000000000000 000009c0 000000d8  0 A      0   0 32
  [17] .rela.rodata.meminfo_proc_fops RELA         0000000000000000 00017a58 00000060 24 I     35  16  8

With gcc 6, there can now be per-function string tables:

  # eu-readelf -S patched/kernel/fork.o |grep rodata
  [10] .rodata.trace_raw_output_task_newtask.str1.8 PROGBITS     0000000000000000 00000208 00000032  1 AMS    0   0  8
  [13] .rodata.trace_raw_output_task_rename.str1.8 PROGBITS     0000000000000000 000002b0 00000030  1 AMS    0   0  8
  [24] .rodata.mm_init.str1.1 PROGBITS     0000000000000000 0000094b 0000000e  1 AMS    0   0  1
  [29] .rodata.sighand_ctor.str1.1 PROGBITS     0000000000000000 00000ba1 00000017  1 AMS    0   0  1
  [32] .rodata.str1.1       PROGBITS     0000000000000000 00000bec 000001d9  1 AMS    0   0  1
  [33] .rodata.__mmdrop.str1.8 PROGBITS     0000000000000000 00000dc8 000000c4  1 AMS    0   0  8
  [82] .rodata.copy_process.part.30.str1.8 PROGBITS     0000000000000000 000019e0 00000098  1 AMS    0   0  8
  [83] .rodata.copy_process.part.30.str1.1 PROGBITS     0000000000000000 00001a78 0000003f  1 AMS    0   0  1
  [92] .rodata._do_fork.str1.1 PROGBITS     0000000000000000 0000372e 00000009  1 AMS    0   0  1
  [173] .init.rodata         PROGBITS     0000000000000000 00004a18 00000011  0 A      0   0  1
  [202] .rodata.str__task__trace_system_name PROGBITS     0000000000000000 00004df0 00000005  0 A      0   0  1

Fixes: #628
2016-12-19 12:01:30 -06:00
Jessica Yu
5bbae490d4 Merge pull request #642 from iredko/enable-kpatch-for-debug-kernels
kpatch-build: make patches for debug kernels too
2016-12-19 09:56:17 -08:00
Igor Redko
8f237b1e7d kpatch-build: make patches for debug kernels too
GCC with KASAN instrumentation creates section ".rodata" with some static strings (i.e. some of them go to ".rodata.str1.1" for release build).
This change makes possible to build patch and check if it fixes issue found with KASAN, such as CVE-2016-9555.
2016-12-19 14:27:43 +03:00
Jessica Yu
86e21e9b9e Merge pull request #641 from joe-lawrence/sparse_smatch
Fix static code analyzer complaints
2016-12-16 16:50:34 -08:00
Jessica Yu
dd8d03ba9b Merge pull request #639 from jpoimboe/activeness-safety-retry
kpatch: retry kpatch load on failure
2016-12-16 16:35:34 -08:00
Joe Lawrence
6ee3c0f8fa testing: add a PATCHES_LIST to kpatch-test
Instead of building *.patch, allow the user to specify patch files on
the command line.  For example:

  kpatch-test --quick centos-7/cmdline-string.patch centos-7/data-new.patch

Update the top-level Makefile as well, so it can be similarly invoked:

  PATCHES="centos-7/cmdline-string.patch centos-7/data-new.patch" make quick

If no patches are specified on the kpatch-test command line, then fall
back to the previous behavior of *.patch.

NOTE: If patches *are* specified, then only the .test files
corresponding to those patches will be executed.  Provided patch paths
will also override any --directory value.
2016-12-16 16:18:19 -05:00
Joe Lawrence
5db4e232ee testing: use common Makefile
Move the integration tests Makefile up a directory level so that it can
be shared.  Update the kpatch-test script to accept a patch-directory
argument and the multiple.test cases to handle this new arrangement.
2016-12-16 16:16:30 -05:00
Joe Lawrence
b6692c14d7 testing: add and rebase integration tests for Ubuntu 16
Kernel version: 4.4.0-53-generic
2016-12-16 16:06:49 -05:00
Joe Lawrence
11ce8102c2 testing: add and rebase integration tests for CentOS 7
Kernel version: 3.10.0-327.36.3.el7.x86_64
2016-12-16 16:06:28 -05:00
Joe Lawrence
d7bcd38787 testing: rebase integration tests for Fedora 25
Kernel version 4.8.6-300.fc25.x86_64
2016-12-16 16:06:15 -05:00
Joe Lawrence
1592c5a711 testing: move integration test patches directory
Prepare for updating the integration tests and move into a standard path
(this should be easier for future automation).

The patch directory name(s) should be in the form ${ID}-${VERSION_ID}/
as defined by the target's /etc/os-release.
2016-12-16 16:05:59 -05:00
Joe Lawrence
33ac7db028 testing: add rebase_patches tool 2016-12-16 16:05:06 -05:00
Joe Lawrence
501a63ad6d smatch,sparse: trivial code cleanups
Fixes smatch warning:
  kmod/core/core.c:64:1: warning: symbol 'kpmod_list' was not declared.  Should it be static?

Fixes sparse warnings:
  kmod/core/core.c:680 kpatch_write_relocations() warn: inconsistent indenting
  kmod/core/core.c:750 kpatch_write_relocations() warn: inconsistent indenting
2016-12-16 14:26:45 -05:00
Joe Lawrence
5a6ddaad8d smatch: fix kpatch_shadow_alloc cleanup
The error paths in kpatch_shadow_alloc do not free an allocated
kpatch_shadow structure (and it's not added to the kpatch_shadow_hash).
Handle the kfree in the various error return paths.

Fixes the smatch warning:

  kmod/core/shadow.c:97 kpatch_shadow_alloc() warn: possible memory leak of 'shadow'
2016-12-16 14:26:11 -05:00
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