Commit Graph

1430 Commits

Author SHA1 Message Date
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
Joe Lawrence
4031927f13
Merge pull request #805 from jpoimboe/gitignore
gitignore: ignore cache.mk from newer kernel builds
2018-03-22 10:44:27 -04:00
Joe Lawrence
2aa75f268f
Merge pull request #804 from jpoimboe/lookup-fix
lookup: fix discarded symbol handling for all kernel versions
2018-03-22 10:43:50 -04:00
Josh Poimboeuf
fefa67554b
Merge pull request #806 from cardoe/drop-rpmdevtools
drop unused rpmdevtools dependency
2018-03-21 22:34:03 -05:00
Josh Poimboeuf
f1d71ac846 create-diff-object: refactor symbol/section inclusion logic
kpatch_include_symbol() is confusing.  Refactor it:

- Remove the "inclusion tree" debug messages.  I never use them, and
  they just help make the code more confusing and the debug output more
  cluttered.

- Split it up into two functions: kpatch_include_symbol() and
  kpatch_include_section(), so that kpatch_include_section() can be used
  elsewhere.

- Call kpatch_include_section() from kpatch_include_standard_elements().
  This covertly fixes #702, by also including the .rela.rodata section.

- Add a bunch of comments to clarify some of the trickier points.

Fixes #702.
Fixes #807.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-03-21 21:36:33 -05:00
Doug Goldstein
ff5c554a40
drop unused rpmdevtools dependency
It appears that since 0dec5136ee nothing
has been used from the rpmdevtools package by kpatch-build.

Signed-off-by: Doug Goldstein <cardoe@cardoe.com>
2018-03-21 15:15:08 -05:00
Josh Poimboeuf
d4e4258172 gitignore: ignore cache.mk from newer kernel builds
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-03-21 13:22:26 -05:00
Josh Poimboeuf
b811940173 lookup: fix discarded symbol handling for all kernel versions
Fix discarded symbol handling for all kernel versions.

Fixes #765.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-03-21 13:19:31 -05:00
Kamalesh Babulal
19b0aba672 PPC64le - do not use the patched functions as callbacks directly
It was observed by Evgenii Shatokhin in PR#755, that when the RCU
callback was called on the patched function, from unloaded livepatch
module triggered a kernel crash.

This patch implements the approach on PowerPC outlined in PR#755.
With -mcmodel=large, like any other data, function pointers are also
loaded relative to the current TOC base and are populated as
relocation entries in .toc section. Every function passing a function
pointer as the argument need to load the function address through
.toc section + offset. Convert such .toc + offset relocation into
a dynamic rela, which resolves to original function address, during
module load.

Also move the comment related to nested function check, into
may_need_dynrela().

Suggested-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
Cc: Joe Lawrence <jdl1291@gmail.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2018-03-21 09:05:25 +05:30
Evgenii Shatokhin
495e619750 kpatch-build, x86: do not use the patched functions as callbacks directly
A kernel crash happened in __do_softirq() in very rare cases when the
binary patch created from mainline commit be82485fbcbb
("netlink: fix an use-after-free issue for nlk groups") was unloaded.

Investigation has shown that the kernel tried to execute an RCU
callback, deferred_put_nlk_sk(), defined in the patch module after the
module had been unloaded.

The callback was set by the patched variant of netlink_release() and
the address of the patched deferred_put_nlk_sk() was used, rather than
the address of the original function.

Similar problems occur with workqueue functions as well.

As suggested in
https://github.com/dynup/kpatch/pull/755#issuecomment-344135224,
create-diff-object was modified so that the addresses of the original
functions were used in such situations, at least for x86 systems. A
similar fix for PowerPC was added as well.

Changes in v4:

* '#ifdef __x86_64__' was removed. It is not actually needed right now
because the constants for relocation types are different on different
architectures.

Changes in v3:

* Minor refactoring and a comment explaining what this all is about.
Quite lengthy, but the dynrela-related code is really far from obvious.

Changes in v2:

* Handle the nested functions the same way as before, because they are
unlikely to be used as asynchronous callbacks. Example: cmp() in
bch_cache_show() from drivers/md/bcache/sysfs.c in the kernel 4.4.

As the nested functions are local to the functions they are defined in,
the compiler names them in a similar way to static locals: <name>.<number>.
Currently, we filter out all functions with '.' in their names. If there
are any asynchronous callbacks in the kernel that have a dot in their
names too, they could be handled in the future patches. It is unclear
though, if the callbacks with such names can appear in the kernel.

Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
2018-03-21 09:01:22 +05:30
Artem Savkov
2ac206b3ba Undefined reference failure logic rework
Don't die outright when encountering an 'undefined reference' error,
instead write those down and check if needed symbols are provided by the
resulting module or core kpatch module.

Fixes #783.

v2:
  - make undefined_references and new_symbols unique before comparing
  - remove leftover $KMOD_PATH from new_symbols readelf

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-03-20 20:42:55 +01:00
Joe Lawrence
d2fba54b42
Merge pull request #802 from sm00th/builtin_rename
Prepare for built-in.o -> built-in.a rename
2018-03-20 13:50:29 -04:00
Artem Savkov
cedcd2314b Prepare for built-in.o -> built-in.a rename
for-next branch of kbuild repo contains a "kbuild: rename built-in.o to
built-in.a" which renames all built-in.o instances. Filter on both .o
and .a in kpatch-gcc/kpatch-build to be prepared for this change.

Fixes #800.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-03-20 10:46:50 +01:00
Joe Lawrence
613794e85a
Merge pull request #773 from kamalesh-babulal/ppc64le_fixes
More ppc64le fixes
2018-03-19 16:53:06 -04:00
Joe Lawrence
794db9c318
Merge pull request #791 from kamalesh-babulal/ppc64le_addend
ppc64le - Fix wrong addend value for switch labels
2018-03-19 16:27:05 -04:00
Joe Lawrence
bb088de342
Merge pull request #797 from jpoimboe/PPC64_LOCAL_ENTRY_OFFSET-fix
create-diff-object: Fix PPC64_LOCAL_ENTRY_OFFSET usage
2018-03-19 16:15:31 -04:00
Kamalesh Babulal
d651cd994c livepatch-patch-hook: Add upper bound kernel version for immediate flag
Effective Kernel v4.16, the immediate flag is removed by upstream
kernel commit d0807da78e11 ("livepatch: Remove immediate feature").
Add an upper bound kernel version check for inclusion of the
immediate flag.

Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2018-03-17 15:00:55 +05:30
Kamalesh Babulal
481d8c4bc2 create-diff-object: Support for __warned placed in .data.once
With kernel commit b1fca27d384 ("kernel debug: support resetting
WARN*_ONCE") the *_ONCE warnings are placed .data.once section.
Including .data.once section is valid, so add an check in
kpatch_verify_patchability() while checking for included invalid
sections.

Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2018-03-17 15:00:50 +05:30