Commit Graph

2381 Commits

Author SHA1 Message Date
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
Josh Poimboeuf e9c0b67862 macros: add syscall patching macros
Attempting to patch a syscall results in an error due to a missing
fentry hook in the inner __do_sys##name() function.  The fentry hook is
missing because of the 'inline' annotation, which invokes 'notrace'.

Add some kpatch-specific syscall definition macros which can be used for
patching a syscall.

These macros are copied almost verbatim from the kernel, the main
difference being a 'kpatch' prefix added to the __do_sys##name()
function name.  This causes kpatch-build to treat it as a new function
(due to its new name), and its caller __se_sys##name() function is
inlined by its own caller __x64_sys##name() function, which has an
fentry hook.

To patch a syscall, just use replace the use of the SYSCALL_DEFINE1 (or
similar) macro with the "KPATCH_" prefixed version.

Fixes: #1171

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-04-19 19:11:44 -07:00
Joe Lawrence e4c0bb9999
Merge pull request #1260 from joe-lawrence/release-v0.9.6
Bump to version v0.9.6
2022-04-12 15:15:17 -04:00
Joe Lawrence eea6582fb2 Bump to version v0.9.6
Updates of interest:

v0.9.6:
- Tue Apr 12 Joe Lawrence <joe.lawrence@redhat.com> - 0.9.6
- Allow OOT modules to be built with non-distro kernels
- Add cross-arch unit testing support
- Support ELF extended symbol section indexes
- Allow setting kernel version if --sourcedir and --vmlinux are used
- Cleanup and enhance __LINE__ macro detection for all arches
- Fix segfault on .LCx string literal symbols
- Include __dyndbg section when referenced by jump table
- Honor user provided KBUILD_EXTRA_SYMBOLS
- Support .retpoline_sites section
- Add native compiler selection via CROSS_COMPILE

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-04-12 11:13:23 -04:00
Josh Poimboeuf ef8b270e4d
Merge pull request #1258 from jpoimboe/seg-fault
Fix seg fault caused by missing .LCx symbol
2022-04-07 09:31:52 -05:00
Josh Poimboeuf 8439de4616
Merge pull request #1254 from jpoimboe/dynamic-debug-fixes
Multiple `__LINE__` macro detection fixes and improvements
2022-04-07 09:31:20 -05:00
Josh Poimboeuf c2e73c2cbc create-diff-object: ensure debug sections don't use dynrelas
Debug sections are intended to refer to the patch module only.  And in
fact, any debug section references to non-included symbols are stripped
in kpatch_include_debug_sections().  So there's no need for
need_dynrela() to even think about it.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-04-06 13:26:09 -07:00
Josh Poimboeuf 305ff8a5d8 create-diff-object: include .LCx string literal symbols
A seg fault was reported:

  Program received signal SIGSEGV, Segmentation fault.
  0x00007ffff7f18c8e in __strcmp_avx2 () from /lib64/libc.so.6
  Missing separate debuginfos, use: dnf debuginfo-install elfutils-libelf-0.186-1.fc34.x86_64 zlib-1.2.11-26.fc34.x86_64
  (gdb) bt
  #0  0x00007ffff7f18c8e in __strcmp_avx2 () from /lib64/libc.so.6
  #1  0x000000000040a0f7 in kpatch_is_core_module_symbol (name=0x0) at create-diff-object.c:3060
  #2  0x000000000040a267 in need_dynrela (kelf=0x4669a0, table=0x92af30, sec=0x6d6b20, rela=0x8c7fd0) at create-diff-object.c:3117
  #3  0x000000000040a4cc in kpatch_create_intermediate_sections (kelf=0x4669a0, table=0x92af30, objname=0x7fffffffcfc6 "vmlinux", pmod_name=0x7fffffffd020 "livepatch_a") at create-diff-object.c:3281
  #4  0x000000000040c7c5 in main (argc=8, argv=0x7fffffffca48) at create-diff-object.c:3931

It happened because 'rela->sym->name' was NULL, and
kpatch_is_core_module_symbol() tried to dereference it.

Here's the corresponding relocation:

  Relocation section [455] '.rela.debug_loclists' for section [454] '.debug_loclists' at offset 0xd0478 contains 2432 entries:
    Offset              Type            Value               Addend Name
    ...
    0x000000000000aad6  X86_64_64       000000000000000000     +32 .LC55
    ...

That '.LC55' symbol lives in the following section:

  [104] .rodata.btf_show_end_aggr_type.str1.8 PROGBITS     0000000000000000 00003ef0 00000021  1 AMS    0   0  8

The problem is that the symbol wasn't included in the output file
(though its corresponding section was).  So it got zeroed by
kpatch_elf_teardown(), which was designed to trigger seg faults to help
find bugs like this.

The string literal sections which hold the '.LCx' string symbols are
already being included.  Include their symbols as well.

Fixes #1257.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-04-06 13:26:09 -07:00
Josh Poimboeuf 5f87a3cbd0
Merge pull request #1255 from euspectre/archversion-override
kpatch-build: Allow setting kernel version if --sourcedir and --vmlinux are used
2022-04-06 09:47:27 -05:00
Josh Poimboeuf e9b941a612
Merge pull request #1256 from rosslagerwall/name-len
kpatch-build: Increase name length limit to 55 chars
2022-04-06 09:47:10 -05:00
Josh Poimboeuf 641daaa489 test/unit: bump to master
Pull in unit tests for dyndbg & __LINE__ fixes.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-04-06 07:34:21 -07:00
Josh Poimboeuf b700732f5d create-diff-object: add "_printk" to the __LINE__ detection
The __LINE__ detection code looks for "printk", which on newer kernels
has been renamed to "_printk".  Fix the check for newer kernels.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-04-05 12:14:22 -07:00
Josh Poimboeuf 79fd60b28d create-diff-object: check arg2 and arg3 on all arches for line detection
For x86, we already check arg2 and arg3 for `__LINE__` immediate load
detection.  For parity, do the same thing for the other two arches.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-04-05 12:14:09 -07:00
Ross Lagerwall f7b27f2fec kpatch-build: Increase name length limit to 55 chars
Previously, the name length was limited to 48 chars. This was then
prepended with "kpatch-" and a trailing NUL terminator to get to the 56
char limit for kernel module names. After some code rearrangement, the
48 char restriction was applied to the name after being prefixed with
kpatch-/livepatch-, limiting the length more than necessary. Increase
the name length limit back to 55 chars to restore the original limit.

Fixes: c0105ea467 ("kpatch-build: set default module prefix accordingly")
Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
2022-04-05 10:35:12 +01:00
Josh Poimboeuf e6b1664d0e create-diff-object.c: add s390 support for __LINE__ detection
Technically we don't support s390 yet, but it's coming soon and there's
no harm in merging this one early.  In fact this came in handy for
testing my endian fixes with #1203.

Note it doesn't actually do anything since 'kelf->arch' can't actually
get set to 'S390' yet.  But it should work nicely with #1203 as it
evolves.

This is based on the patch from C. Erastus Toe in #1243, though there
may still be a few outstanding issues to look at in that PR, based on
some of the code review comments.

Originally-by: C. Erastus Toe <ctoe@redhat.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-04-04 21:13:49 -07:00
Josh Poimboeuf a6920b9381 create-diff-object: fix endian issues in insn_is_load_immediate()
With s390 support coming, we'll soon have to worry about endianness
issues when doing cross-compiles and cross-arch unit tests.  Make
insn_is_load_immediate() endian-agnostic.

Suggested-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-04-04 21:13:49 -07:00
Josh Poimboeuf 38839017d2 gitignore: ignore .swo files
Sometimes I like to live on the edge and edit the same file in multiple
vims :-)

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-04-04 21:13:49 -07:00
Josh Poimboeuf 1152e58244 create-diff-object: support __LINE__ detection for btrfs macros
These btrfs macros use the `__LINE__` macro.  Add proper support for
them in kpatch_line_macro_change_only().

   5:   ba 34 09 00 00          mov    $0x934,%edx
   a:   48 c7 c6 00 00 00 00    mov    $0x0,%rsi
                        d: R_X86_64_32S .rodata.__func__.5
  11:   4c 89 ef                mov    %r13,%rdi
  14:   e8 00 00 00 00          callq  19 <push_node_left.cold+0x19>
                        15: R_X86_64_PLT32      __btrfs_abort_transaction-0x4

Fixes #1253.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-04-04 21:12:58 -07:00
Evgenii Shatokhin fea0192104 kpatch-build: Allow setting kernel version if --sourcedir and --vmlinux are used
Using -a/--archversion to explicitly set target kernel version was not
allowed if the kernel source directory and/or path to vmlinux with debug
info were set. This seems too strict, however.

vmlinux with debug info is used during the build to get symbol data, the
size of special structures, GCC version used to build the kernel, and the
target kernel version. As it turned out, some kernels, e.g. the ones from
OpenSUSE and derivatives, contain all that data except the Linux version
string in the file with debug info for vmlinux. Instead, that string is
present in vmlinux itself but that file does not contain debug info.

A simple workaround is to allow specifying the target kernel version
explicitly using -a/--archversion even if --sourcedir and/or --vmlinux are
set. If vmlinux with debug info does contain the Linux version string and
the version is different, kpatch-build will report an error.

Signed-off-by: Evgenii Shatokhin <evgenii.shatokhin@openvz.org>
2022-04-04 13:16:24 +03:00
Josh Poimboeuf af672577b3 create-diff-object: use toc_rela() in kpatch_line_macro_change_only()
For ppc64le, if a rela goes through the .toc, it requires an extra level
of indirection.  Use toc_rela() here to ensure it gets the rela we care
about.  This will be needed for the upcoming patch which checks for
`__func__`.

For non-ppc64le arches, and for ppc64le relas which don't go through the
.toc, toc_rela() is a no-op which just returns the rela.  So this is
harmless for non-.toc cases.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-04-01 16:47:57 -07:00
Josh Poimboeuf 81296117f4 create-diff-object: unify kpatch_line_macro_change_only()
The arch-specific versions of kpatch_line_macro_change_only() are mostly
duplicate code.  Unify them into a single implementation.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-04-01 16:47:54 -07:00
Josh Poimboeuf 4ba6f1fbc9 create-diff-object: include __dyndbg section when referenced by jump table
If the only reference to the `__dyndbg` section is through a jump table
entry, the section doesn't get included and the jump table relocations
end up with a dangling reference to an UNDEF section symbol.

Make sure jump table referenced dynamic debug symbols get their sections
included.

Fixes #1253.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-03-31 21:37:28 -07:00
Joe Lawrence 75f220233b
Merge pull request #1251 from sm00th/symtab_shndx
symtab_shndx support
2022-03-02 15:48:32 -05:00
Artem Savkov 8d81cc8517 kpatch-elf: symtab_shndx support
Symbol indexes over 64k don't fit into st_shndx and are stored in
extended symbol table. Make sure we properly handle these cases. It is
not normally useful during kpatch builds but will come up if we start
diffing linked objects.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-03-02 09:26:29 +01:00
Joe Lawrence 110e196bac
Merge pull request #1233 from omatiusha/master
kpatch-build: add cross-compilation support (#1224 fix)
2022-02-14 08:57:36 -05:00
Joe Lawrence aaaebaf258
Merge pull request #1249 from sm00th/locals_match_fix
Fix sym->type condition in locals_match()
2022-02-04 09:10:01 -05:00
Joe Lawrence 1d4b3c2d16
Merge pull request #1248 from joe-lawrence/cross-arch
Remove host / target architecture assumption from create-diff-object
2022-02-04 09:09:46 -05:00
Artem Savkov 4d8c8102de Fix sym->type condition in locals_match()
Second loop in locals_match() checks table_sym->type instead of
sym->type.

Fixes: 7207687 Switch to per-file lookup table pointers.
Signed-off-by: Artem Savkov <asavkov@redhat.com>
2022-02-03 11:59:24 +01:00
Joe Lawrence f67a008478 test/unit: update for cross-arch testing
Bump the submodule reference and modify the unit test Makefile to check
all supported architectures.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-02-02 17:36:24 -05:00
Bill Wendling 4c0e4898d9 create-diff-object: detect architecture from input ELF file
libelf can read and write various architecture ELF files that may
differ from the host system.  Instead of using preprocessor directives
to build architecture-specific code as per the current host, detect the
intended target architecture from the input ELF files.

Based-on: https://github.com/dynup/kpatch/pull/1179
Signed-off-by: Bill Wendling <morbo@google.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com> [small tweaks]
2022-02-02 17:36:19 -05:00
Joe Lawrence 394a907a37 create-diff-object: move kpatch_find_func_profiling_calls definition
The last part of kpatch_elf_open() calls kpatch_find_func_profiling_calls() to
find and set sym->has_func_profiling.  However, only create-diff-object.c
requires sym->has_func_profiling, so remove the call from
kpatch_elf_open() and let the lone user, create-diff-object, provide and
call it as needed.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-01-21 16:12:28 -05:00
Joe Lawrence aa33ee7dff
Merge pull request #1247 from markusboehme/fix/retpoline-sites
create-diff-object: add support for .retpoline_sites section
2022-01-21 16:05:21 -05:00