Commit Graph

1498 Commits

Author SHA1 Message Date
Joe Lawrence 27accf46ee
Merge pull request #857 from joe-lawrence/local-symbols
create-klp-module: group .kpatch.symbols with like-scope
2018-05-30 14:16:40 -04:00
Joe Lawrence ace1e2cbf6
Merge pull request #849 from sm00th/cdo-symtab
create-diff-object symtab
2018-05-30 14:15:43 -04:00
Joe Lawrence a879d1f3ea
Merge pull request #859 from jpoimboe/ppc-TOC
create-diff-object: don't convert .TOC. references to dynrelas
2018-05-30 14:09:02 -04:00
Joe Lawrence 9d0a2105ef
Merge pull request #861 from kamalesh-babulal/gcc_plugin
gcc-plugin: Include additional header for GCC 8
2018-05-30 14:06:32 -04:00
Joe Lawrence b387dffab6
Merge pull request #863 from jpoimboe/unit-submodule-root-dir
test/unit: run submodule command from base git directory
2018-05-30 14:04:41 -04:00
Josh Poimboeuf 5736f18d83 test/unit: run submodule command from base git directory
This fixes the following error with an older version of git
(1.8.3.1):

  make -C test/unit
  make[1]: Entering directory `/root/kpatch/test/unit'
  git submodule update --init --rebase
  You need to run this command from the toplevel of the working tree.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-05-30 10:54:24 -05:00
Joe Lawrence c2f6d4d0fb
Merge pull request #860 from jpoimboe/rhel-immediate
livepatch-patch-hook: add RHEL immediate check
2018-05-30 11:37:53 -04:00
Kamalesh Babulal 3ba9a145e9 gcc-plugin: Include additional header for GCC 8
plugin compilation fails on GCC 8:

In file included from gcc-plugins/gcc-common.h:100,
                 from gcc-plugins/ppc64le-plugin.c:1:
/usr/lib/gcc/powerpc64le-linux-gnu/8/plugin/include/attribs.h: In function ‘tree_node* canonicalize_attr_name(tree)’:
/usr/lib/gcc/powerpc64le-linux-gnu/8/plugin/include/attribs.h:118:11: error: ‘get_identifier_with_length’ was not declared in this scope
    return get_identifier_with_length (s + 2, l - 4);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/powerpc64le-linux-gnu/8/plugin/include/attribs.h:118:11: note: suggested alternative: ‘get_attr_min_length’
    return get_identifier_with_length (s + 2, l - 4);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~
           get_attr_min_length
Makefile:34: recipe for target 'gcc-plugins/ppc64le-plugin.so' failed

get_identifier_with_length() is defined under stringpool.h, include this
header file for GCC 8, before including attribs.h

Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2018-05-30 19:39:48 +05:30
Josh Poimboeuf 7023c239b1 create-diff-object: don't convert .TOC. references to dynrelas
When I made a patch to the nfsd module on a ppc64le system with a RHEL 7
based kernel, livepatch prevented the target module from loading with:

  livepatch: symbol '.TOC.' not found in symbol table

References to this symbol are treated specially by the kernel module
loader, so references to it should never be converted to dynrelas.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-05-30 08:59:54 -05:00
Josh Poimboeuf a3ee369448 livepatch-patch-hook: add RHEL immediate check
The 'immediate' flag removal is going to be backported to RHEL 7.
Adjust the check accordingly.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-05-29 17:54:59 -05:00
Joe Lawrence de10550fae create-klp-module: group .kpatch.symbols with like-scope
From Oracle's Linker and Libraries Guide [1]:

"The symbols in a symbol table are written in the following order ...
The global symbols immediately follow the local symbols in the symbol
table. The first global symbol is identified by the symbol table sh_info
value. Local and global symbols are always kept separate in this manner,
and cannot be mixed together."

[1] https://docs.oracle.com/cd/E19120-01/open.solaris/819-0690/chapter6-79797/index.html

Fixes #854.
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2018-05-29 15:30:39 -04:00
Joe Lawrence ba5f3a9900
Merge pull request #853 from jpoimboe/paravirt-alignment-panic
create-klp-module: Properly align merged .parainstructions sections
2018-05-21 17:17:37 -04:00
Josh Poimboeuf 3d04265899 create-klp-module: Properly align merged .parainstructions sections
When a patch is composed of multiple .o files which have
.parainstructions sections, loading the patch causes a panic:

  general protection fault: 0000 [#1] SMP
  Modules linked in: livepatch_4_9_88_1_20180518_1(OK+) livepatch_4_9_88_1_20180510_1(OK) ...
  CPU: 1 PID: 17257 Comm: insmod Tainted: G           O  K 4.9.0-6-amd64 #1 Debian 4.9.88-1
  Hardware name: HP ProLiant MicroServer Gen8, BIOS J06 11/02/2015
  task: ffff9ff3411a4480 task.stack: ffffac8f8271c000
  RIP: 0010:[<ffffffff8ae2e1d0>]  [<ffffffff8ae2e1d0>] apply_paravirt+0xc0/0x140
  RSP: 0018:ffffac8f8271f9a0  EFLAGS: 00010216
  RAX: 00010749ffffffff RBX: ffffffffc0940658 RCX: 0000000000000085
  RDX: 00000000bfebfbff RSI: ffffac8f8271f9a2 RDI: 0000000000000246
  RBP: ffffac8f8271f9a2 R08: 0000000000000085 R09: ffffffff8ae5acb0
  R10: 0000000000000001 R11: ffff9ff3544b4400 R12: ffffffffc0940660
  R13: 0000000000000000 R14: ffff9ff3544b49c0 R15: ffff9ff3b43f0800
  FS:  00007f04c1cea700(0000) GS:ffff9ff3ca640000(0000) knlGS:0000000000000000
  CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
  CR2: 0000560cfd63e460 CR3: 00000001455c6000 CR4: 0000000000160670
  Stack:
   401f0ff889486973 6172007172006b00 746c00650031312e 007265746e655f69
   74006e6f69007870 ffffac8f006e6f69 00ffac8f8271fa28 ffffffff8b13ae86
   ffffac8f8271fa68 ffffffffc09471ec ffffffff8b7da9eb 0000000affffffff
  Call Trace:
   [<ffffffff8b13ae86>] ? vsscanf+0x4c6/0x800
   [<ffffffff8b13b20e>] ? sscanf+0x4e/0x70
   [<ffffffff8ae52be5>] ? arch_klp_init_object_loaded+0x105/0x130
   [<ffffffff8b13b0be>] ? vsscanf+0x6fe/0x800
   [<ffffffff8b13b20e>] ? sscanf+0x4e/0x70
   [<ffffffff8aee29e8>] ? klp_init_object_loaded+0xf8/0x210
   [<ffffffff8aee2d85>] ? klp_register_patch+0x285/0x390
   [<ffffffffc09491fa>] ? patch_init+0x1fa/0x1000 [livepatch_4_9_88_1_20180518_1]
   [<ffffffffc0949000>] ? 0xffffffffc0949000
   [<ffffffff8ae0218e>] ? do_one_initcall+0x4e/0x180
   [<ffffffff8afc87dd>] ? __vunmap+0x6d/0xc0
   [<ffffffff8afc87dd>] ? __vunmap+0x6d/0xc0
   [<ffffffff8af7eaa1>] ? do_init_module+0x5b/0x1ed
   [<ffffffff8af025a6>] ? load_module+0x2596/0x2ab0
   [<ffffffff8aefed50>] ? __symbol_put+0x60/0x60
   [<ffffffff8af02d06>] ? SYSC_finit_module+0xc6/0xf0
   [<ffffffff8ae03b7d>] ? do_syscall_64+0x8d/0xf0
   [<ffffffff8b41244e>] ? entry_SYSCALL_64_after_swapgs+0x58/0xc6
  Code: 8d 7c 05 00 e8 62 f7 ff ff 0f b6 53 f9 48 8b 7b f0 48 89 ee e8 f2 f8 ff ff 49 39 dc 76 57 44 0f b6 43 09 41 80 f8 ff 75 84 0f 0b <48> 8b 10 48 8d 7d 08 48 83 e7 f8 48 89 55 00 89 ca 48 8b 74 10
  RIP  [<ffffffff8ae2e1d0>] apply_paravirt+0xc0/0x140
   RSP <ffffac8f8271f9a0>
  ---[ end trace 128c0fa6efe85d9e ]---

The panic is caused by a corrupt .klp.arch.vmlinux..parainstructions
section:

Relocation section [208] '.rela.klp.arch.vmlinux..parainstructions' for section [207] '.klp.arch.vmlinux..parainstructions' at offset 0x29dc78 contains 10 entries:
  Offset              Type            Value               Addend Name
  000000000000000000  X86_64_64       000000000000000000    +750 __get_user_pages
  0x0000000000000010  X86_64_64       000000000000000000    +823 __get_user_pages
  0x0000000000000020  X86_64_64       000000000000000000    +890 __get_user_pages
  0x0000000000000030  X86_64_64       000000000000000000    +941 __get_user_pages
  0x0000000000000040  X86_64_64       000000000000000000   +1631 __get_user_pages
  0x0000000000000050  X86_64_64       000000000000000000   +1671 __get_user_pages
  0x000000000000005c  X86_64_64       000000000000000000   +1245 handle_userfault
  0x000000000000006c  X86_64_64       000000000000000000   +1340 handle_userfault
  0x000000000000007c  X86_64_64       000000000000000000   +1417 handle_userfault
  0x000000000000008c  X86_64_64       000000000000000000   +1717 handle_userfault

The entries are supposed to be 16 bytes each, but notice they become
misaligned starting with the 'handle_userfault' entry.

This happens because the kernel linking process lies about the
.parainstructions section size, underreporting it by four bytes.  So
when two .parainstructions sections are merged together, it results in a
corrupted .klp.arch.vmlinux..parainstructions section.

Fix it by properly aligning the section before merging it with another
one.

Fixes #852.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-05-18 16:11:41 -05:00
Joe Lawrence 8b1e193eae
Merge pull request #851 from M1cRO/fix_kpatch_list
Show just modules in kpatch list
2018-05-18 14:02:45 -04:00
Ilya A. Arkhipov 0240e809b5 Show just modules (*.ko) in kpatch list:
load --all working just for .ko:
  for i in "$INSTALLDIR/$(uname -r)"/*.ko; do

 USUALLY, all modules have .ko extension

 /var/lib/kpatch can have not only modules, in my case (Yes it just my case) I have list with patches included in module.
2018-05-18 19:04:29 +03:00
Artem Savkov 3aa5abb807 kpatch-build: use symbol table instead of kobject
create-diff-object doesn't really need the full kernel object file as
input. All it requires is a symbol table. Switch to using "eu-readelf -s"'s
output instead of object files. This will enable us to cover more cases
in unit tests.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-05-18 09:24:40 +02:00
Artem Savkov e790d59bec create-diff-object: name arguments
Use named variables instead of cmdline argument indexes so that it is
easier to read create-diff-object.c.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-05-14 16:09:38 +02:00
Joe Lawrence 9477a047d8
Merge pull request #847 from sm00th/ppc64le-warn-detection
ppc64le: add WARN detection
2018-05-08 17:11:36 -04:00
Joe Lawrence ad332ec2f0
Merge pull request #846 from M1cRO/update_spec
Update kpatch.spec, keep it updated
2018-05-04 14:55:50 -04:00
Ilya A. Arkhipov e73b2756b8 Update kpatch.spec, keep it updated ^_^
fix changelog, doint it correct
2018-05-04 19:07:06 +03:00
Artem Savkov 5f610fdda2 ppc64le: add WARN detection
ppc64le lacked kpatch_line_macro_change_only() implementation. Add one
based on x86_64 version and available unit tests.

Fixes: #843

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-05-04 16:32:48 +02:00
Joe Lawrence 3c58d0a64d
Merge pull request #844 from sm00th/unit-upd
unittests: object submodule update
2018-04-27 16:42:04 -04:00
Artem Savkov e0acd5f835 unittests: object submodule update
Update submodule to 6774fbc "ppc64le: initial object files"
Remove CDO_ENV since it is moved to per-arch makefiles.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-27 20:10:43 +02:00
Joe Lawrence 404111f635
Merge pull request #842 from sm00th/unit-submodule
Unittests submodule
2018-04-26 14:20:56 -04:00
Artem Savkov ffc4122efb Add kpatch-unit-objs submodule
Add a submodule containing object files for unittests.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-26 18:49:29 +02:00
Artem Savkov 89a8ac740c Disable git-lfs
While convenient git-lfs has too many restrictions for kpatch's needs.
Remove links to the objectfiles and related configs.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-26 15:08:24 +02:00
Joe Lawrence 70959ce6ec
Merge pull request #838 from jpoimboe/test-cleanups
Test cleanups
2018-04-23 17:31:35 -04:00
Joe Lawrence 534b1318de
Merge pull request #841 from jpoimboe/kpatch-delay
kpatch: increase patch transition stall timeout
2018-04-23 15:55:21 -04:00
Joe Lawrence 58ae6bd6ff
Merge branch 'master' into kpatch-delay 2018-04-23 15:47:31 -04:00
Josh Poimboeuf d5eb921af1 Merge commit '7e5f59e10f8317ac17c2225f70f87b87abff1775' 2018-04-22 15:04:27 -05:00
Joe Lawrence 7e5f59e10f Bump version to 0.6.0
Increment version to 0.6.0 due to 926e4e0c7d ("kmod: add support for
in-kernel livepatch hooks"), which removed the kpatch (un)load hook API
support and converted to livepatch-style hooks.

Additional changes include:

* Lots of misc bugfixes and cleanups
* Manpage, README.md fixups
* More PPC64 work
* "Undefined reference" build failure rework
* Livepatch disable retries
* New unit testing framework

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-22 15:03:08 -05:00
Josh Poimboeuf 6db0a6f06c kpatch: increase patch transition stall timeout
I loaded a livepatch on an idle 112 CPU system, and it took over three
seconds for the patch transition to complete:

  [1561551.584871] livepatch: 'livepatch_foo': starting patching transition
  [1561554.867486] livepatch: 'livepatch_foo: patching complete

Presumably this is because more CPUS == more kthreads and idle tasks,
which are more likely to be running at any given time.

Currently the kpatch script will start signaling tasks if the transition
takes more than five seconds.  Increase that timeout a bit to 15
seconds, to give big/busy systems more time before we start signaling.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-20 16:31:42 -05:00
Josh Poimboeuf 3feb694c91 test/unit: further silence non-verbose mode
Just show a summary of each test command in non-verbose mode.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-20 08:16:26 -05:00
Josh Poimboeuf 4c1184dcf7 test/unit: add a library for common functions
I placed the library in the top-level test directory, as the same
assertions could also be used by the integration tests once we rework
them a bit.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-20 08:16:20 -05:00
Josh Poimboeuf 1fa1e7a05a
Merge pull request #840 from jpoimboe/config-stacktrace
kmod/core: add check for CONFIG_STACKTRACE
2018-04-20 06:39:13 -05:00
Josh Poimboeuf 81fb34ed57
Merge pull request #835 from jpoimboe/function-ptr-new
create-diff-object: skip dynrelas for function pointers to new functions
2018-04-20 06:38:55 -05:00
Josh Poimboeuf 4f6a96f94a kmod/core: add check for CONFIG_STACKTRACE
As discovered in #837.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:27:38 -05:00
Josh Poimboeuf d6dfa4a992 test/unit: test the number of patched functions
As an extra sanity check, ensure the number of patched functions never
changes.

Also added a test for convert-global-local to ensure the global symbol
is converted to a local.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:09 -05:00
Josh Poimboeuf e16b4187a1 test/integration: remove obsolete tests
Cleaning house a bit.  Now that we have unit tests, a lot of these tests
aren't very useful anymore.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:09 -05:00
Josh Poimboeuf 5629d91bfe test/unit: add WARN test
Add a WARN detection test, based on the integration test of the same
name.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:09 -05:00
Josh Poimboeuf 8e315b42e0 test/integration: update WARN detection patch
Update the WARN detection patch to be based on net/core/dev.c, which is
a much better stress test.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:09 -05:00
Josh Poimboeuf 635754fc46 test/unit: add meminfo-string test
Copy the meminfo-string test from the integration tests.  It's a good
stress test for dynrelas.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:08 -05:00
Josh Poimboeuf 0e1b95edea create-diff-object: update the __LINE__ macro checks
Update the `__LINE__` macro detection heuristics based on recent kernel
changes:

- __warn_printk(), used in the WARN macros, which put the line number in
  %edx

- __might_fault(), used in the usercopy macros

- lockdep_rcu_suspicious(), used in the RCU_LOCKDEP_WARN macro

- printk(), used in the ASSERT_RTNL macro

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:08 -05:00
Josh Poimboeuf ff5bcc2fdc test/unit: broaden the 'clean' target
Broaden the impact of the 'clean' target so that output objects will
still get cleaned when when old tests get removed or renamed.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:08 -05:00
Josh Poimboeuf af9f9f491c test: remove obsolete tests
After doing some research, I've discovered that most of these tests no
longer test what they were originally intended to test.

An exception here is the 'macro-hooks' test, which is probably better
suited as an integration test, so I removed its unit test and kept its
integration test.

Really, most of these tests weren't all that useful to begin with, so
it's not a big loss.  The one exception is 'gcc-static-local-var-2',
which was originally meant to test multiple static local variables with
the same name in the name function.  That's a good thing, so I'll try to
come up with another test for that which works with Linux 4.16.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:08 -05:00
Josh Poimboeuf 805b1f5d3f test/unit: fix 'new-fuction' test name typo
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:08 -05:00
Josh Poimboeuf 4884fd17fc
Merge pull request #832 from sm00th/ccache-link
readme: fix outdated epel ccache link
2018-04-19 08:29:36 -05:00
Josh Poimboeuf 678701e56e
Merge pull request #833 from sm00th/ppc64le-plugin-install-fix
ppc64le: fix gcc-plugin installation
2018-04-19 08:29:15 -05:00
Artem Savkov c16306f272 travis-ci: test installation
Install kpatch during testing so that any bugs in makefiles such as #833
can be caught early.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-19 15:14:17 +02:00
Josh Poimboeuf 87939db272 create-diff-object: skip dynrelas for function pointers to new functions
With #755, we started using dynrelas for function pointers.  However,
this behavior only makes sense for function pointers to existing
functions.  For function pointers to *new* functions, just use a normal
rela.

The 'function-ptr-new' unit test is from the following patch:

  https://github.com/dynup/kpatch/files/1927198/new-static-callback.patch.txt

Fixes #834.

Fixes: 495e619750 ("kpatch-build, x86: do not use the patched functions as callbacks directly")
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 07:56:12 -05:00