Commit Graph

2381 Commits

Author SHA1 Message Date
Josh Poimboeuf fe45029b4d kpatch-build: fix KBUILD_MODNAME for OOT modules
For consistency with what the kernel does (and what we already do for
in-tree modules), if the file has any dashes ('-'), replace them with
underscores in the objname (aka KBUILD_MODNAME).

Fixes #1286.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-08-05 09:29:39 -07:00
Nicolas Lorin 8cc0fedefb kpatch-build: use err.h instead of error.h for musl support 2022-08-05 08:52:03 +02:00
Joe Lawrence 67e4e2048a
Merge pull request #1283 from jerdfelt/jerdfelt/prefix-strip
kpatch-cc: fix stripping of source tree prefix
2022-08-02 09:23:48 -04:00
Johannes Erdfelt 07433e98c0 kpatch-cc: fix stripping of source tree prefix
To support building out-of-tree kernel modules, the source tree prefix
is attempted to be stripped from change object file paths to make them
relative. However, if the path is already relative, the change can
strip a substring instead, resulting in build errors.

Ensure just the prefix is stripped instead of any substring.

Fixes: #1282
Fixes: 51a8fad34f ("Add support for building out-of-tree modules")
2022-07-27 10:29:36 -07:00
Joe Lawrence 6992acf9c2
Merge pull request #1281 from dobsonj/issue1280
create-diff-object: add support for .return_sites section (x86)
2022-07-21 10:30:59 -04:00
Joe Lawrence dbde872cee
Merge pull request #1279 from joe-lawrence/syscalls
macros: tweak syscall patching macros
2022-07-21 10:30:40 -04:00
Jonathan Dobson 33368a88cd create-diff-object: add support for .return_sites section (x86) 2022-07-16 15:46:54 -06:00
Joe Lawrence e921c557f9 macros: tweak syscall patching macros
Kernel version specific __KPATCH_SYSCALL_DEFINEx macros were added to
kpatch-syscall.h for x86, but only single versions for other arches.
This works out for s390x, but not ppc64le for which kpatch-build support
goes back to kernel versions that require slightly different macros.

Reorder the __KPATCH_SYSCALL_DEFINEx macros to define the arch-specific
ones first (arch/.../include/asm/syscall_wrapper.h) and then fall back
to using generic ones (include/linux/syscalls.h versions).

Fixes: #1278
Fixes: 9c0b678621b9 ("macros: add syscall patching macros")
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-07-13 22:30:28 -04:00
Joe Lawrence dc7e5cb03d
Merge pull request #1203 from sumanthkorikkar/s390x-kpatch-support
S390x kpatch support
2022-06-29 09:55:53 -04:00
Joe Lawrence d1423a3d65
Merge pull request #1275 from joe-lawrence/integration-updates-jun-2022
Integration updates
2022-06-29 09:45:34 -04:00
Joe Lawrence 14f24fe481 test/integration: add missing syscall-LOADED.test for rhel-9.0
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-06-17 14:50:52 -04:00
Joe Lawrence 8aa91803be test/integration: tweak paravirt call in module.patch
Calling __flush_tlb_local() may result in a kernel warning:

  STATIC_NOPV void native_flush_tlb_local(void)
  {
          /*
           * Preemption or interrupts must be disabled to protect the access
           * to the per CPU variable and to prevent being preempted between
           * read_cr3() and write_cr3().
           */
          WARN_ON_ONCE(preemptible());

so use another paravirt call like slow_down_io() instead.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-06-16 11:06:10 -04:00
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
Sumanth Korikkar 48d997f2a3 README: Update s390 as supported and backporting info
* Add s390 as supported.
* Add backporting information for the distros.

Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
2022-05-25 06:20:04 +02: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
Sumanth Korikkar 0308d52bcd kpatch/s390: Enable kpatch build support
Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
2022-05-20 15:50:29 +02:00
Sumanth Korikkar b0330ab18e kpatch/s390: Add additional bundled symbols.
1. static const struct inet_sock fake_sk = {
	/* makes ip6_route_output set RT6_LOOKUP_F_IFACE: */
	.sk.sk_bound_dev_if = 1,
	.pinet6 = (struct ipv6_pinfo *) &fake_pinfo,
};

gcc can place fake_sk in .data.rel.ro.local:
ndx 38, data 0x3ffb3280a58, size 960, name .data.rel.ro.local.fake_sk.1
ndx 39, data 0x3ffb32be5e8, size 24, name .rela.data.rel.ro.local.fake_sk.1

2. static LIST_HEAD(patch_objects);

gcc can place patch_objects relocation in .data.rel.local:
sym 56, type 1, bind 0, ndx 34, name patch_objects -> .data.rel.local

Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
2022-05-20 15:50:29 +02:00
Sumanth Korikkar eb4a85f778 kpatch/s390: Add exclusion lists
Add object exclusion for s390

Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
2022-05-20 15:50:29 +02:00
Sumanth Korikkar f0d00a9290 kpatch/s390: Add initial support for kpatch
* Add s390 specific checks
* Identify patchable functions.
* Dont mark expolines as dynrelas. These expolines are always included
  in final kernel module. This ensures that expoline functions and the
  kernel itself are not too far apart and avoids out of range
  relocation. However, this isnt a problem for other functions, as these
  relocations are performed via R_390_PLT32DBL using gcc option
  -mno-pic-data-is-text-relative.
* s390 maintains expoline tables to locate the expoline thunks. If
  needed,  the module loader could later replace these expoline thunks
  with normal indirect branch. Each element in the expoline table is of 4
  bytes. If there is a changed function in rela.s390_return*, then mark
  that specific rela symbol as included. This is already performed in the
  processing of special sections. Hence include it.

Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
2022-05-20 15:50:29 +02:00
Sumanth Korikkar 10002f5aa6 kpatch/s390: Add gcc prerequisite flags for kpatch
1. -mno-pic-data-is-text-relative prevents relative addressing between
   code and data. This is needed to avoid relocation error when klp text
   and data are too far apart

2. Avoid generation of LANCHOR symbols through -fno-section-anchors.
   kpatch-build does not handle it well.

Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
2022-05-20 15:50:29 +02:00
Vasily Gorbik c6d0b5450b lookup: fix symtab parsing
symtab_read tries to skip '.dynsym' symbol table and only
read '.symtab' symbol table. Newer readelf from binutils 2.37
now adds section names (see the diff):

--- vmlinux.symtab      2022-02-18 02:10:06.691220932 +0100
+++ vmlinux.symtab.new  2022-02-18 01:16:06.161210458 +0100
Symbol table '.dynsym' contains 1541 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000100000     0 SECTION LOCAL  DEFAULT    1 .text
     2: 00000000017a3ac0     4 OBJECT  GLOBAL DEFAULT   19 sclp_console_pages
Symbol table '.symtab' contains 159980 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
-    41: 0000000001a93600     0 SECTION LOCAL  DEFAULT   41
-    42: 0000000001a9c678     0 SECTION LOCAL  DEFAULT   42
...
+    41: 0000000001a93600     0 SECTION LOCAL  DEFAULT   41 .dynsym
+    42: 0000000001a9c678     0 SECTION LOCAL  DEFAULT   42 .rela.dyn
...
     54: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS main.c

Simple matching of ".dynsym" in the line buffer is not enough anymore,
because it hits not just

Symbol table '.dynsym' contains 1541 entries:

line, but also

    41: 0000000001a93600     0 SECTION LOCAL  DEFAULT   41 .dynsym

skipping the rest of the file and leading to an error:

create-diff-object: ERROR: *.o: find_local_syms: 189: couldn't find matching
*.c local symbols in vmlinux symbol table

Limit matching only to lines containing "Symbol table" header.
This works with readelf from the binutils, as well as readelf from
elfutils (its output looks slightly different).

Symbol table [41] '.dynsym' contains 1541 entries:

Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
2022-05-20 15:50:29 +02: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