Commit Graph

1447 Commits

Author SHA1 Message Date
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
Josh Poimboeuf
b3b9e858fe
Merge pull request #831 from jpoimboe/unit-stderr
unit: don't suppress stderr
2018-04-18 08:26:52 -05:00
Josh Poimboeuf
69ba464462 unit: don't suppress stderr in non-fail tests
Don't suppress stderr in the non-fail unit tests so that
create-diff-object error messages will be printed.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-18 08:03:25 -05:00
Joe Lawrence
4caf44ff66
Merge pull request #830 from sm00th/travisci
Enable TravisCI
2018-04-17 10:16:54 -04:00
Joe Lawrence
e7834dcdff
Merge pull request #828 from rppt/callbacks-fix
livepatch-patch-hook: make callbacks addition depend on the kernel ve…
2018-04-17 10:16:02 -04:00
Mike Rapoport
dd1bfbecd5 livepatch-patch-hook: make callbacks addition depend on the kernel version
Since commit 926e4e0c7d ("kmod: add support
for in-kernel livepatch hooks") livepatch-patch-hook.c unconditionally
creates callbacks. This causes build error for kernels older than 4.15:

make -C /home/rppt/git/linux M=/home/rppt/.kpatch/tmp/patch livepatch-proc-vmalloc-live.ko
make[1]: Entering directory '/home/rppt/git/linux'
  CC [M]  /home/rppt/.kpatch/tmp/patch/patch-hook.o
In file included from /home/rppt/.kpatch/tmp/patch/patch-hook.c:21:0:
/home/rppt/.kpatch/tmp/patch/livepatch-patch-hook.c:82:23: error: field ‘callbacks’ has incomplete type
  struct klp_callbacks callbacks;
                       ^
/home/rppt/.kpatch/tmp/patch/livepatch-patch-hook.c: In function ‘patch_init’:
/home/rppt/.kpatch/tmp/patch/livepatch-patch-hook.c:395:10: error: ‘struct klp_object’ has no member named ‘callbacks’
   lobject->callbacks = object->callbacks;
          ^
scripts/Makefile.build:302: recipe for target '/home/rppt/.kpatch/tmp/patch/patch-hook.o' failed
make[2]: *** [/home/rppt/.kpatch/tmp/patch/patch-hook.o] Error 1
Makefile:1687: recipe for target 'livepatch-proc-vmalloc-live.ko' failed
make[1]: *** [livepatch-proc-vmalloc-live.ko] Error 2
make[1]: Leaving directory '/home/rppt/git/linux'
Makefile:20: recipe for target 'livepatch-proc-vmalloc-live.ko' failed
make: *** [livepatch-proc-vmalloc-live.ko] Error 2

Introduce HAVE_CALLBACKS to allow conditional compilation of the callbacks
addition.

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
2018-04-16 20:06:38 +03:00
Josh Poimboeuf
0d99e91c46
Merge pull request #824 from joe-lawrence/author-guide-callback-locks
patch-author-guide: more on locks in callbacks
2018-04-16 07:59:13 -05:00
Artem Savkov
ebe51660b9 Enable TravisCI
Add .travis.yml with build/unit/shellcheck tests.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-16 14:06:11 +02:00
Joe Lawrence
9b5ade5c12
Merge pull request #818 from sm00th/unittests
Unittests
2018-04-13 17:15:07 -04:00
Joe Lawrence
88241ef8e5
Merge pull request #829 from sm00th/sign-compare
Sign compare fixes
2018-04-13 15:21:07 -04:00
Joe Lawrence
fb06282505 patch-author-guide: more on locks in callbacks
Elaborate on the difficulties in using locks/mutexes from the kpatch
callback routines and suggest a few workarounds.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2018-04-13 15:13:18 -04:00
Artem Savkov
1ada45a352 unittests: top-level make target
Add new 'unit' make target to top-level makefile.
Add unittests dir to CLEAN_DIRS.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-13 18:11:51 +02:00
Artem Savkov
a0edfc1ded unittests: check that obj files are fetched
Check that tested .o is not an lfs meta-file before testing.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-13 18:11:50 +02:00
Artem Savkov
b9c56c475a uinttests: add strip check
Check that files are stripped of debuginfo as it is useless for
unittesting at this moment.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-13 18:11:17 +02:00
Artem Savkov
3ee81ec4ee x86_64: integration test objs
Populate x86_64 dir with objectfiles from integration test builds.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-13 18:10:34 +02:00
Artem Savkov
a05c644c7b Add create-diff-object unittest framework
Add a simple unittest framework for create-diff-object implemented in
GNU Make.
It will automatically scan the kpatch-unit-objs/$(uname -m) directory
for specifically named files running one of 3 tests:
  - creating diff object with expected success
  - creating diff object with expected failure
  - creating diff object and running a shell script on it with expected
  success

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-13 18:09:37 +02:00
Artem Savkov
a39eace756 kpatch-build: add -Wsign-compare to CFLAGS
Add -Wsign-compare to kpatch-build CFLAGS to make sure something like #826
never happens again.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-13 16:27:23 +02:00
Artem Savkov
1638c64fe5 Fix multiple sign-compare warnings
- convert section/symbol indexes and rela->offset to unsigned int as I
    couldn't find any way for them to become negative.
  - cast a number of rela->addend comparisons to int (assuming an 64bit
    system this should be enough)
  - a number of simple for-loop counter conversions to the type it
    compares against

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-13 16:26:06 +02:00
Joe Lawrence
c5e4b51982
Merge pull request #827 from vincentbernat/fix/ubuntu-kernel-retry
kpatch-build: fix Ubuntu kernel detection on successive retries
2018-04-12 14:11:38 -04:00
Joe Lawrence
2a53a96ade
Merge pull request #826 from sm00th/oorr-comparison-fix
Fix false-positives in kpatch_check_relocations
2018-04-12 13:44:23 -04:00
Vincent Bernat
e2e7d2cd21 kpatch-build: fix Ubuntu kernel detection on successive retries
If a patch failed a first time, kpatch-build is using the previous
cache directory on subsequent builds. The UBUNTU_KERNEL=1 variable is
not set in this case. Therefore, utsrelease.h is not updated correctly
and the appropriate structures are not used. Just check if distro is
Ubuntu and we didn't request our own specific directory.

Signed-off-by: Vincent Bernat <vincent@bernat.im>
2018-04-12 18:29:18 +02:00
Artem Savkov
4591c0701c Fix false-positives in kpatch_check_relocations
Because of signedness difference kpatch_check_relocations() would trigger
an error on any negative addend.
Fix by casting Elf_Data->d_size from size_t to int.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-12 17:46:12 +02:00
Joe Lawrence
88e9eb3ee0
Merge pull request #823 from sm00th/oorr
create-diff-object: check for out-of-range relocations
2018-04-11 14:54:24 -04:00
Joe Lawrence
86d18c7ce3
Merge pull request #816 from joe-lawrence/module-probe-failed
kmod/core: account for failing modules in notifier
2018-04-11 10:40:58 -04:00
Joe Lawrence
326b8f863b
Merge pull request #822 from sm00th/aguide
patch-author-guide: sleeping locks in callbacks
2018-04-11 10:12:28 -04:00
Joe Lawrence
ae79f2206d
Merge pull request #812 from kirawrath/upstart-support
Adding support to upstart systems.
2018-04-11 10:10:59 -04:00
Artem Savkov
1d9f75a155 create-diff-object: check for out-of-range relocations
Check that none of the relocations are out-of-range of their
corresponding sections before writing the output elf.

Fixes: #618

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-11 10:40:34 +02:00
Joe Lawrence
fdf36400fb kmod/core: account for failing modules in notifier
The module notifier currently only handles newly loaded modules in the
MODULE_STATE_COMING state.  If target modules need to be unloaded, the
any kpatch module that patches it must first be disabled, releasing
module references held against the target module.  When the kpatch
modules are disabled, the target module is unpatched and the kpatch
core's data structures updated accordingly.

If a loading module happens to fail its init routine (missing hardware
for example), that module will not complete loading.  The kpatch core
doesn't properly account for this "phantom" target module, so when the
kpatch patch module is removed, it spews out an ugly warning when
attempting to remove a non-existing ftrace filter on the target module.

Register an additional module notifier (first in the list) to handle the
MODULE_STATE_GOING case.  This handler needs to do the inverse of the
MODULE_STATE_COMING handler.

Fixes #699.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2018-04-10 11:46:36 -04:00
Joe Lawrence
e73d98ec0f
Merge pull request #820 from kamalesh-babulal/ppc64le_rela_equal
create-diff-object: Refactor rela_equal() using toc_rela()
2018-04-06 17:24:24 -04:00
Kamalesh Babulal
ed14d8d332 create-diff-object: Refactor rela_equal() using toc_rela()
Heavy lifting of reading .toc rela entries for rela symbols
referring to .toc + offset, can be simplified using toc_rela() in
rela_equal() and remove the #ifdery guarding PowerPC code.

This patch also trims the commentary related to PowerPC.

Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2018-04-06 21:12:51 +05:30
Artem Savkov
808a6b83de patch-author-guide: sleeping locks in callbacks
Add a note about dealing with sleeping locks in callbacks.
2018-04-06 16:28:02 +02:00
loretob
c9614c4298 Adding support to upstart systems.
Currently kpatch rely on systemd to load all kmods on startup.
This patch aims to enable kpatch to be used on upstart systems.

Limitations:
With systemd, it would be possible to unload all modules by issuing:
        systemctl stop kpatch
It was not possible to make a reasonable upstart's equivalent of it, so
to unload the modules it will be necessary to call kpatch explicitly:
        kpatch unload --all

I believe this it an non-issue, as it is still possible to unload
the modules by calling kpatch explicitly.

The file /etc/init/kpatch.conf will be installed unconditionally, and
removed on uninstall.

On my tests I have verified that all newly added files by this commit
are also deleted on uninstall.

It was also verified that applied patches are loaded again on startup.

rpmlint does not complain about anything new.

Signed-off-by: Bruno Loreto <loretob@amazon.com>
2018-04-06 16:12:02 +02:00
Josh Poimboeuf
547f6eda1f
Merge pull request #821 from kamalesh-babulal/testcase_cleanup
Testcase: Clean up gcc-static-local-var-2
2018-04-06 08:32:12 -05:00
Josh Poimboeuf
9792d8e542 test: test github's support of git-lfs
Testing github's support of git-lfs for our unit tests.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-06 07:55:31 -05:00
Kamalesh Babulal
4d3363a975 Testcase: Clean up gcc-static-local-var-2
The test case gcc-static-local-var-2 doesn't uses any macros
from kpatch-macros.h, so remove the hunk including it.

Cc: Joe Lawrence <jdl1291@gmail.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2018-04-06 12:11:05 +05:30
Josh Poimboeuf
055f9c8596
Merge pull request #817 from jpoimboe/ppc64le-static-locals-part-1
create-diff-object: fix ppc64le static local variable correlation
2018-04-05 09:48:26 -05:00
Kamalesh Babulal
bfacf5d15c Testing: Add testcase for correlating static local variable
This patch adds a reproducer testcase for correlating static local
variables added in .rodata* section, ahead of .toc section. This
testcase is for issue seen on PowerPC. For more details on the issue
refer pull request: 793.

It add's the testcase for:
- Fedora-27 Kernel version 4.15.10-300
- Centos-7 Kernel version 3.10.0-693 and
- Ubuntu-16.04 Kernel version 4.13.0-25.29

Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2018-04-05 09:44:45 -05:00
Josh Poimboeuf
ff8b2510af create-diff-object: fix ppc64le static local variable correlation
On ppc64le, the static local variable correlation doesn't take into
account the .toc rela indirection for data references, meaning that it's
basically broken in many cases.

Fix it by making the code .toc-aware.

Fixes #793.

Reported-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-04 16:30:07 -05:00
Joe Lawrence
55650e16af
Merge pull request #780 from joe-lawrence/livepatch-hooks
kmod: add support for in-kernel livepatch hooks
2018-04-02 14:49:07 -04:00
Joe Lawrence
9e7db03d3f
Merge pull request #810 from joe-lawrence/sparse
sparse: quiet latest trivial complaints
2018-03-24 15:50:08 -04:00
Joe Lawrence
e4131d4651
Merge pull request #809 from joe-lawrence/make-check
scripts: small ShellCheck cleanups
2018-03-24 15:49:48 -04:00
Joe Lawrence
812081c329
Merge pull request #789 from kamalesh-babulal/ppc64le_callback
[RFC] PC64le - do not use the patched functions as callbacks directly
2018-03-24 15:49:22 -04:00
Joe Lawrence
4d5febd4a8 sparse: quiet latest trivial complaints
Fixes sparse warnings:

  kmod/core/core.c:142:20: warning: symbol 'trace' was not declared. Should it be static?

  livepatch-patch-hook.c:73:18: warning: symbol 'lpatch' was not declared. Should it be static?

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2018-03-23 16:20:45 -04:00
Joe Lawrence
926e4e0c7d kmod: add support for in-kernel livepatch hooks
Upstream 4.15 kernels provide support for pre and post (un)patch
callbacks, inspired by the kpatch load hooks.  Add support for them
in the livepatch-patch-hook.

At the same time, convert the kpatch hooks to use the same API.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2018-03-23 10:32:14 -04:00
Joe Lawrence
64173f4f1d scripts: small ShellCheck cleanups
Cleanup some of the new bash script code to appease 'make check':

  - kpatch: Use integer comparison for $MAX_LOAD_ATTEMPTS
  - kpatch-build: Quote ${TEMPDIR} variable

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2018-03-23 10:27:35 -04:00
Joe Lawrence
7e1b495f52
Merge pull request #762 from joe-lawrence/fedora-27-rebase
testing fedora 27: rebase integration test patches
2018-03-22 14:43:48 -04:00
Joe Lawrence
1d942ebb41 testing: rebase patches for Fedora 27 4.13.9-300.fc27.x86_64
Rename the old Fedora 25 integration patch directory and rebase to
Fedora 27 sources.

Fixes #761.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2018-03-22 14:36:34 -04:00
Joe Lawrence
4a0b3541be
Merge pull request #796 from jpoimboe/plugin-fix
gcc-plugin: run the plugin at an earlier pass
2018-03-22 14:32:10 -04:00
Joe Lawrence
5ec00a0bfd
Merge pull request #801 from sm00th/extsym
Undefined reference failure logic rework
2018-03-22 14:20:02 -04:00
Joe Lawrence
0f17a019be
Merge pull request #808 from jpoimboe/include-logic-rewrite
create-diff-object: refactor symbol/section inclusion logic
2018-03-22 13:06:09 -04:00