Commit Graph

2212 Commits

Author SHA1 Message Date
Joe Lawrence 30f09bfaa2 test/integration: add upstream 5.18.0 patches
Add patches rebased on top of upstream 5.18.0.

Integration tests for these can be ran as this:

  $ make PATCH_DIR="linux-5.18.0" KPATCH_BUILD_OPTS="--non-replace --sourcedir /path/to/src/linux-5.18.0" integration-slow

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-06-16 11:06:07 -04:00
Josh Poimboeuf 7fdbb2561c
Merge pull request #1273 from jpoimboe/create-secsym
create-diff-object: Create missing section symbol
2022-06-07 20:32:17 -07:00
Josh Poimboeuf a1171b112e create-diff-object: Create missing section symbol
Recent toolchains only create a section symbol if it's needed, i.e. if
there's a reference to it.  If there's a missing section symbol in
kpatch_create_intermediate_sections(), create one instead of erroring
out.

Fixes #1272.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-06-07 20:31:10 -07:00
Joe Lawrence e425e653aa
Merge pull request #1271 from joe-lawrence/integration-kpatch_rhel_dependencies
kpatch build dependency cleanup
2022-05-25 09:35:12 -04:00
Joe Lawrence 02306e62ae Makefile: add make help
We've got a lot of top level Makefile targets, help out the user.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-05-23 08:47:18 -04:00
Joe Lawrence b6b650a006 Makefile: add dependencies target
Installing the dependencies should be a one-step operation for the user.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-05-23 08:47:18 -04:00
Joe Lawrence b6abf449d6 test/integration/lib.sh: combine Fedora, CentOS with RHEL dependencies
All three distributions work more or less the same, so just combine
their dependency installs.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-05-23 08:47:18 -04:00
Joe Lawrence e72b876f97 test/integration/lib.sh: fix kernel build dependencies
The yum-builddep utility doesn't always install all the kernel build
dependencies.  Using the --skip-unavailable flag (rhel8+) lets us skip
over packages that it can't find, but continue to install the ones it
can. (Unavailable packages are usually platform-specific or not strictly
necessary for kpatch-build's kernel build invocation.)

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-05-23 08:47:18 -04:00
Joe Lawrence 6b0b482d16 test/integration/lib.sh: tweak epel URL for rhel-major
EPEL ships an epel-release-latest-X.noarch.rpm per rhel-X major release.
Install the package matching the system release.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-05-23 08:47:18 -04:00
Josh Poimboeuf f6e1838ab9
Merge pull request #1269 from jpoimboe/reloc-addend
Fix addend handling and other cleanups for s390
2022-05-19 18:25:52 -05:00
Joe Lawrence 4d485dddb7
Merge pull request #1270 from rikvanriel/master
kpatch: also unload a loaded, but no longer enabled kernel live patch
2022-05-19 10:00:19 -04:00
Rik van Riel 1bf9609327 kpatch: also unload a loaded, but no longer enabled kernel live patch
Currently "kpatch force unload <klp_some_version>" will fail to unload
an old kernel live patch module that is no longer seeing any use, when
the "enabled" file for that module is no longer present.

Check for the presence of such modules by checking /sys/module, and
return success from disable_patch() for a module that is already
disabled.

This allows "kpatch force unload <klp_some_version>" to succeed for
already disabled modules.

Signed-off-by: Rik van Riel <riel@surriel.com>
2022-05-18 14:39:29 -04:00
Josh Poimboeuf 52863dace0 create-diff-object: fix endianness in kpatch_no_sibling_calls_ppc64le()
Otherwise it fails the unit tests on an s390 host.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-05-17 19:28:56 -07:00
Josh Poimboeuf 017015a725 create-diff-object: make kpatch_check_relocations() more precise
Use rela_target_offset() to make the relocation bounds checking more
precise.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-05-17 19:28:56 -07:00
Josh Poimboeuf f0e3da336c create-diff-object: fix string extraction
The current string extraction is broken for non-section symbols.  Fix
that.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-05-17 19:28:55 -07:00
Josh Poimboeuf 86d5208b46 create-diff-object: error on symbol conversion failure
If a section reference can't be converted to a symbol reference, error
out to try to prevent unexpected behavior later on.

There are a few sections for which a symbol is optional: .rodata and
string literal sections.  Don't warn about those.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-05-17 19:27:25 -07:00
Joe Lawrence 6a0dcb0da8
Merge pull request #1263 from anatasluo/master
kpatch-build: add support for openEuler
2022-05-13 10:00:22 -04:00
Josh Poimboeuf 325bccd89d create-diff-object: skip conversion for sections which never have symbols
These sections don't have symbols.  Don't even try to replace references
to them with symbols.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-05-11 17:02:07 -07:00
Josh Poimboeuf 8508abd3b1 create-diff-object: allow converstion of empty symbols
Empty (zero-length) symbols are possible, allow
kpatch_replace_sections_syms() to work on them.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-05-11 17:02:07 -07:00
Josh Poimboeuf 8d5a628bde create-diff-object: add extra check for symbol conversion edge case
This issue was only seen in in a text section.  Explicitly check for
that.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-05-11 17:02:07 -07:00
Josh Poimboeuf 01427d50a1 create-diff-object: move addend math to a new function
Split out the addend offset math into a separate function so it can be
used elsewhere.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-05-11 17:02:04 -07:00
Josh Poimboeuf bec6488af6 create-diff-object: add rela_insn() error check
Error out if the insn can't be found.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-05-11 17:00:26 -07:00
Josh Poimboeuf 6b1895a6b7 create-diff-object: convert rela_insn() to take normal 'sec'
rela_insn() only cares about the base section.  Convert it to take a
non-rela section as its argument instead of a relasec.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-05-11 17:00:26 -07:00
Josh Poimboeuf bf212f7750 create-diff-object: error on unsupported rela in symbol conversion
Error out if an unsupported rela is encountered.  This is more robust
than just ignoring it.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-05-11 17:00:26 -07:00
Josh Poimboeuf 3f8e1062cc create-diff-object: support R_X86_64_NONE in kpatch_replace_sections_syms()
Add support for R_X86_64_NONE.  With an upstream kernel, it's quite
rare, only used for a few jump labels.  With older kernels it was used
for fentry hooks.  Either way, it should be treated like a PC-relative
relocation.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-05-11 17:00:26 -07:00
Josh Poimboeuf 79f45d1b0a create-diff-object: fix kpatch_replace_sections_syms() for non-text
It doesn't make sense to disassemble a data section.  That just happened
to work by accident.  PC-relative offsets only need adjusting when
associated with an instruction.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-05-11 17:00:26 -07:00
Josh Poimboeuf 61e46094b5 create-diff-object: convert function return types to 'bool'
Several functions have a boolean semantic, but don't actually return
bool, which is confusing.  Fix that.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-05-11 17:00:26 -07:00
Josh Poimboeuf c24d135f40 create-diff-object: rename "sec" -> "relasec" for rela sections
Several functions expect to take a ".rela" section as an argument.  Make
such cases more clear by renaming "sec" -> "relasec".

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-05-11 17:00:25 -07:00
Josh Poimboeuf 3b63456817 kpatch-elf: convert functions to static
These functions are only called locally, convert them to static.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-05-11 16:59:54 -07:00
Josh Poimboeuf 0c5a1e7753 kpatch-build: make xtrace output less verbose
With '--debug', most of the xtrace output shows the reading of the
.config and Module.symvers files, which isn't very useful and floods the
rest of the xtrace output.  Temporarily disable xtrace before reading
the files.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-05-11 13:55:56 -07:00
Joe Lawrence f6e0142b3c
Merge pull request #1265 from joe-lawrence/integration-tests-rhel-9.0
test/integration/rhel-9.0: add kernel-5.14.0-70.13.1.el9_0 tests
2022-05-10 18:32:00 -04:00
anatasluo e680087567 doc/install.md: add instructions for openEuler
Signed-off-by: anatasluo <luolongjuna@gmail.com>
2022-05-07 10:04:45 +08:00
Joe Lawrence 4774d070d2 test/integration/rhel-9.0: remove obsolete tests
Clean out any integration tests that no longer exercise their original
use cases.

Suggested-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-05-06 14:42:11 -04:00
Joe Lawrence 9bf6aba6b1
Merge pull request #1266 from joe-lawrence/integration-tests-rhel-8.6
test/integration/rhel-8.6: add kernel-4.18.0-372.9.1.el8 tests
2022-05-06 14:34:11 -04:00
anatasluo 2784f5056b kpatch-build: add support for openEuler
As I noticed, commit eaaced191 has added
partial support for openEuler.

This patch enables usage in openEuler like:
kpatch-build xxxx.patch

I test it in openEuler 21.09, for people who
want to use kpatch in openEuler, two more steps
are needed.

1) add repo source
source rpm package of openEuler kernel are put in
two places. One is
https://repo.openeuler.org/openEuler-21.09/source/
Another one is
https://repo.openeuler.org/openEuler-21.09/update/source/
The latter one is not inclued in rpm repo lists by default.

2) compile kernel with CONFIG_LIVEPATCH_PER_TASK_CONSISTENCY enabled
openEuler has its own strategy when trying to apply patches.
We can use the klp_enable_patch function only when
CONFIG_LIVEPATCH_PER_TASK_CONSISTENCY is enabled.

Signed-off-by: anatasluo <luolongjuna@gmail.com>
2022-05-06 10:58:20 +08:00
Josh Poimboeuf 43e91f6b9f
Merge pull request #1268 from yhcote/fix-doc
doc: fix internal link to supported arches
2022-05-05 13:16:13 -05:00
Yannick Cote 7b4e422cba
doc: fix internal link to supported arches
Signed-off-by: Yannick Cote <ycote@redhat.com>
2022-05-04 12:10:41 -04:00
Joe Lawrence dd11b08659
Merge pull request #1264 from liu-song-6/fix-01
kpatch-build: remove duplicated use_klp_arch
2022-05-02 10:11:08 -04:00
Joe Lawrence dc1d49a142 test/integration/rhel-9.0: add kernel-5.14.0-70.13.1.el9_0 tests
* gcc-constprop.patch
In v4.20, 33e26418193f ("y2038: make do_gettimeofday() and get_seconds()
inline"), do_gettimeofdat() no longer exists as a stand alone function
in kernel/time/timekeeping.c.

* gcc-static-local-var-4.patch
Unlike on rhel-8.4, _always_inline put_aio_ring_file() is causing too
many inlines and results in modified, but not ftrace-able,
__do_sys_io_submit() and __do_sys_io_setup().  Remove the annotation
from this function.

* module.patch
In v4.20, 9ceddd9da134 ("knfsd: Allow lockless lookups of the exports"),
the nfs_exports_op seq_operations converted to RCU protected lookups.
Calling yield() from a kpatched e_show() results in a kernel warning,
"Voluntary context switch within RCU read-side critical section!"
Substitute with single_task_running(), which does not context switch or
have any other side effects.

In v5.10, ec6347bb4339 ("x86, powerpc: Rename memcpy_mcsafe() to
copy_mc_to_{user, kernel}()") did away with the mcsafe_key.  Use
another exported static key like context_tracking_enabled.

In v5.13, a0e2bf7cb700 ("x86/paravirt: Switch time pvops functions to
use static_call()"), paravirt_sched_clock() was converted from a
paravirt call to a non-exported static call.  Update the x86 code to
instead call __flush_tlb_local() (which is still a paravirt call).

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-05-01 11:34:28 -04:00
Joe Lawrence 734a9d9ef5 test/integration/rhel-8.6: add kernel-4.18.0-372.9.1.el8 tests
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-04-29 16:14:30 -04:00
Song Liu 3392049665 kpatch-build: remove duplicated use_klp_arch
The two versions are not the same (4.18.0-240.el8 vs. 4.18.0-284.el8).
But I am not quite sure which one is accurate. Remove the first one as the
second one is being used before this change.

Signed-off-by: Song Liu <song@kernel.org>
2022-04-28 11:43:50 -07:00
Josh Poimboeuf b0444d2599
Merge pull request #1173 from jpoimboe/syscall-macros
Add syscall macros
2022-04-26 11:44:02 -05:00
Josh Poimboeuf 1528c8d298
Merge pull request #1261 from jpoimboe/readme
readme: bring README.md into the 21st century
2022-04-26 11:43:43 -05:00
Josh Poimboeuf edcac8ac78
Merge pull request #1262 from jpoimboe/unit
test/unit: bump
2022-04-22 11:36:17 -05:00
Josh Poimboeuf f835cff795 test/unit: bump
Oops, this somehow ended up with a reference to nonexistent commit.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-04-22 09:33:49 -07:00
Josh Poimboeuf e6c1c082ce readme: bring README.md into the 21st century
Update a lot of the old cruft and move the boring installation stuff to
a separate file.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-04-22 09:28:55 -07:00
Josh Poimboeuf 286e85fddf patch-author-guide: Add TOC
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-04-22 09:10:16 -07:00
Josh Poimboeuf fe5df04d30 patch-author-guide: Add section about patching syscalls
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-04-22 08:40:00 -07:00
Josh Poimboeuf b21b35f7d4 patch-author-guide: Add latest jump label status
Mention that jump labels in patched functions are mostly supported for
Linux 5.8+.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-04-22 08:38:14 -07:00
Josh Poimboeuf 373993ec1c test/integration: Add tests for patching a syscall
Add ".kpatch" to the end of "uname -s".

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-04-20 08:35:12 -07:00