Commit Graph

2019 Commits

Author SHA1 Message Date
Yannick Cote
b99e2781ac
Merge pull request #1094 from joe-lawrence/kpatch-R_X86_64_64
kmod/core: apply dynrela addend for R_X86_64_64
2020-05-03 14:14:00 -04:00
Joe Lawrence
15067fcd64 kmod/core: apply dynrela addend for R_X86_64_64
User stettberger noticed that the kpatch support module does not
apply the addend for R_X86_64_64 in kpatch_write_relocations().

The AMD64 ABI draft doc [1], Table 4.10: Relocation Types lists that
relocation type as:

  Name         Value  Field   Calculation
  R_X86_64_64  1      word64  S + A

where:

  S : Represents the value of the symbol whose index resides in the
      relocation entry.

  A : Represents the addend used to compute the value of the relocatable
      field.

[1] http://refspecs.linuxfoundation.org/elf/x86_64-abi-0.99.pdf

Fixes: #1093
Reported-by: Christian Dietrich <stettberger@dokucode.de>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2020-05-01 09:01:50 -04:00
Yannick Cote
8e8707ed72
Merge pull request #1092 from sm00th/ppc64le-int-module-fix
tests/integration/module.patch: fix ppc64le build
2020-04-23 10:29:40 -04:00
Artem Savkov
e0e41f0943 tests/integration/module.patch: fix ppc64le build
ppc64le build currently fails dues to unused sched_clock variable. Move
it's declaration into ifdef block.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2020-04-23 14:15:31 +02:00
julien-thierry
42bc85d0dc
Merge pull request #1091 from julien-thierry/ignore-untraceable
create-diff-object: Ignore kpatch_ignored functions/sections missing …
2020-04-23 10:31:10 +01:00
Julien Thierry
c1caee1468 create-diff-object: Ignore kpatch_ignored functions/sections missing ftrace hook
Some theoretically unchanged functions can have undesired changes if the
compiler decides to perform inlining in a different way (e.g. because of
newly added references). In such a case, it can be useful to discard
changes to functions that don't actually need modification.

Sadly, this currently doesn't work for functions missing the ftrace hook
(e.g. notrace code) as presence of the hook is checked before
identifying elements to ignore.

Look for functions/sections to ignore earlier.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-04-23 08:22:50 +01:00
Josh Poimboeuf
097bfa6455
Merge pull request #1090 from yhcote/fix-doc-typo
patch-author-guide: fix typo in code
2020-04-18 09:38:07 -05:00
Yannick Cote
ebc776a4fc
patch-author-guide: fix typo in code
In shadow-newpid.patch, a new structure member is created using the
klp_shadow_get_or_alloc() routine. The simplified and explained version
of it in the patch author guide has a typo that replaces
klp_shadow_get_or_alloc() with klp_shadow_get().

Signed-off-by: Yannick Cote <ycote@redhat.com>
2020-04-17 11:50:06 -04:00
Yannick Cote
44f31f8d07
Merge pull request #1089 from jpoimboe/no-klp-arch
Use non-failing jump label tests
2020-04-15 09:14:19 -04:00
Josh Poimboeuf
61ef8238d1 test/unit: Use non-failing jump label tests
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-04-14 17:41:17 -05:00
Josh Poimboeuf
f24f5cb2ca test/integration: improve module integration test
Replace module-call-external.patch with a more fleshed-out version which
tests multiple things (including jump tables for newer kernels), and
also includes a runtime test.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-04-14 16:46:03 -05:00
Josh Poimboeuf
1991ff0018 create-diff-object: add support for .klp.arch removal
Starting with Linux 5.8, vmlinux-specific KLP relas are applied early,
before all the special section initializations are done.

This means that jump labels can now be supported for cases where the
corresponding static keys live in the core kernel (vmlinux).

It also means that paravirt patching and alternatives can also now be
supported without the need for the .klp.arch sections.

This simplifies things greatly for newer kernels.  We just have to make
sure that module-specific KLP relas aren't created for special sections.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-04-14 12:44:04 -05:00
Josh Poimboeuf
3982b329bc kpatch-build: drop support for old non-.klp.arch kernels
There were a few kernels (4.7 and 4.8) which didn't have support for
.klp.arch sections, but for which we still tried to use
CONFIG_LIVEPATCH.  Those are inherently buggy, so just drop
CONFIG_LIVEPATCH support for them altogether.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-04-14 12:44:04 -05:00
Josh Poimboeuf
e80562a8cb kpatch-build: add kpatch.ko deprecation warning
kpatch.ko has been quietly deprecated for a while, because there are
some known issues, including special section initialization ordering
issues.  Starting with Linux 5.7, it will be completely broken because
kallsyms_lookup_name() will no longer be exported.

Add a warning to make its deprecation status more obvious.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-04-14 12:44:04 -05:00
Josh Poimboeuf
d97de8d554 kpatch-build: readability cleanups
Do some kpatch-build script cleanups to improve readability.  This
is only a cleanup and shouldn't affect any functionality.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-04-14 12:44:04 -05:00
Josh Poimboeuf
4e0db559c1 lookup: fix Module.symvers reading for newer kernels
With Linux commit 5190044c2965 ("modpost: move the namespace field in
Module.symvers last"), the format of Module.symvers has changed yet
again.

Use a completely different approach for figuring out the format.  If a
column has "vmlinux", assume that's the "Module" column.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-04-14 12:44:00 -05:00
Yannick Cote
1cc52bf19b
Merge pull request #1088 from euspectre/show-all-jump-labels
create-diff-object: show all jump labels before reporting failure
2020-04-14 09:09:48 -04:00
Yannick Cote
5432c86ded
Merge pull request #1056 from jpoimboe/dynrela
dynrela cleanups
2020-04-14 09:07:06 -04:00
Evgenii Shatokhin
89e8574027 create-diff-object: show all jump labels before reporting failure
We have recently encountered a situation when a patched function
had more than one jump label (static branches with the same static key
used to turn on/off some debugging feature). As it is often the case
with jump labels, their locations were far from obvious in the source
code, hidden in the chains of inline functions.

create-diff-object, however, exits after it has reported one jump label.
This is inconvenient, because, after one updates the patch to avoid
that jump label, the next build of the binary patch reveals another
one and fails again, and so on. It can be very time-consuming.

Let us report all jump labels first.

Before this commit the messages looked like this:

  kpatch-build/create-diff-object: ERROR: dev.o:
  kpatch_regenerate_special_section: 2084:
  Found a jump label at ploop_req_state_process()+0x220, using key css_stacks_on.
  Jump labels aren't currently supported.  Use static_key_enabled() instead.

After:

  dev.o: Found a jump label at ploop_req_state_process+0x220, key: css_stacks_on.
  dev.o: Found a jump label at ploop_ioctl+0x2708, key: css_stacks_on.
  kpatch-build/create-diff-object: ERROR: dev.o:
  kpatch_regenerate_special_section: 2123:
  Found 2 jump label(s) in the patched code.
  Jump labels aren't currently supported. Use static_key_enabled() instead.

Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
2020-04-10 19:26:06 +03:00
Josh Poimboeuf
0a3e6c5f42 create-diff-object: refactor dynrela conversion
The dynrela (aka .klp.rela) conversion logic is notoriously complex and
fragile.  Simplify it and improve the comments.

This is mainly a cosmetic change.  In theory it shouldn't change
functionality or break anything.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-04-06 15:18:58 -05:00
Josh Poimboeuf
d2089a4d72 create-diff-object: rename lookup 'result' -> 'symbol'
Improve readability by renaming the lookup "result" variables to
"symbol".

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-04-06 15:18:58 -05:00
Josh Poimboeuf
ae9f1c17b1 lookup: add duplicate symbol checks
Add checks for duplicate symbols, and refactor the logic slightly.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-04-06 15:18:58 -05:00
Josh Poimboeuf
3064cf3c60 lookup: add 'objname' to lookup table and lookup results
This will be needed for the upcoming dynrela refactoring.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-04-06 15:18:58 -05:00
Josh Poimboeuf
7e1f2b0e07 lookup: convert lookup functions to return bool
IMO, the code is easier to follow if these functions return bool.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-04-06 15:18:58 -05:00
Josh Poimboeuf
6cc03f9599 lookup: rename 'pos' to 'sympos'
To more accurately describe its purpose.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-04-06 15:18:58 -05:00
Josh Poimboeuf
cd121422d9 lookup: rename 'value' -> 'addr'
Rename 'value' to 'addr' to more accurately describe it.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-04-06 15:18:58 -05:00
Josh Poimboeuf
5fad6599a4 lookup: remove unused testing code
This testing code is no longer used.  Remove it.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-04-06 15:18:58 -05:00
Josh Poimboeuf
e4d37dad5d lookup: Skip .dynsym table in symtab_read()
On powerpc, "readelf -s" of vmlinux shows both .dynsym and .symtab.
.dynsym is just a subset of .symtab, so skip it to avoid duplicates.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-04-06 15:18:58 -05:00
Josh Poimboeuf
7e48138185 lookup: Simplify first loop in symtab_read()
symtab_read() is quite fragile because it relies on the fact that the
first and second loops have the exact same conditions.

Instead just change the first loop to count all the lines in the file,
to get an upper bound for allocation.  It's ok to over-allocate
slightly.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-04-06 15:18:58 -05:00
Josh Poimboeuf
74c9c99931 create-diff-object: reduce indentation in kpatch_create_patches_sections()
Reverse the if condition and use a 'continue' statement to reduce
indentation and improve readability.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-04-06 15:18:58 -05:00
Yannick Cote
e2c66d7fb0
Merge pull request #1054 from julien-thierry/static-local-reworks
Static local reworks
2020-04-04 17:00:35 -04:00
Joe Lawrence
666635d4b0
Merge pull request #1083 from joe-lawrence/integration-rhel-7.8
test/integration: add rhel-7.8 rebased patches
2020-03-31 19:03:01 -04:00
Yannick Cote
3e5210315f
Merge pull request #1087 from kamalesh-babulal/rhel-8-1-test-files
test/integration: rhel-8.1 Add missing *.test files
2020-03-31 11:10:33 -04:00
Kamalesh Babulal
2e4309eebb test/integration: rhel-8.1 Add missing *.test files
Add the missing *.test files in test/integration/rhel-8.1

[Artem Savkov: Suggested to disable gcc-static-local-var-4.test]
Suggested-by: Artem Savkov <asavkov@redhat.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2020-03-30 20:21:00 +05:30
Julien Thierry
24fc731ab2 test/integration: Reenable test
Reenable previously failing test gcc-static-local-var-5.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-03-30 14:21:40 +01:00
Julien Thierry
2265ce6fc2 test/unit: Add unit test for static local moving sections
Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-03-30 14:14:17 +01:00
Julien Thierry
b548ba153f kpatch-build: Look for local static variables in child functions
A symbol in the original object might get split in several sub-functions
in the patched object, which can themselves be bundled (and use a
separate rela section). References to local static variables from the
original function, might have been moved in one of the sub-functions
in the patched object.

Look for references to local static variables in the rela section
of child symbols in the patched object.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-03-30 14:14:17 +01:00
Julien Thierry
42128ff78c kpatch-build: Include .part. symbols as child function
Consider symbols containing .part. in their names as sub-function
of the symbols they are derived from (if such symbol still exists in the
object file).

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-03-30 14:14:17 +01:00
Julien Thierry
b502e5b1cc kpatch-build: Allow function to have multiple child functions
A symbol associated to a function can be split into multiple
sub-functions. Currently, kpatch only supports one child per function.

Extend this to support an arbitrary number of sub-function per function.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-03-30 14:14:17 +01:00
Julien Thierry
af1fe267c5 create-diff-object: Avoid unnecessary parent symbol inclusion
When a child symbol has changed, the parent symbol is only needed
in the output object if the child symbol is unpatchable on its own.
This is the case when the child symbol does not have its own profiling
call.

Only include unchanged parent symbols if their child has changed and
the child does not have a function profiling call.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-03-30 14:14:17 +01:00
Yannick Cote
421df07ffa
Merge pull request #1086 from kamalesh-babulal/rhel8-1-testcases-rebase
test/intergation: Rebase to RHEL 8.1
2020-03-27 11:47:43 -04:00
Kamalesh Babulal
db3c916e7c test/integration: Disable special-static testcase
Disabling the test case, until we find a workaround for functions
with the static key getting inlined. Read the comments from
@joe-lawrence in #1086 for detailed analysis.

Suggested-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2020-03-27 15:46:41 +05:30
Joe Lawrence
22772a8466
Merge pull request #1081 from joe-lawrence/update-integration-rebase
testing/integration: update rebase_patches tool
2020-03-23 16:26:54 -04:00
Yannick Cote
e84ddd02a8
Merge pull request #1082 from yhcote/fix-0.9.0
Bump version to v0.9.1
2020-03-23 15:05:18 -04:00
Kamalesh Babulal
4423e471d1 test/intergation: Rebase to RHEL 8.1
Rebase the integration testcase on top of RHEL 8.1 kernel
4.18.0-147.el8.

Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2020-03-17 17:31:09 +05:30
Joe Lawrence
d9a40744aa test/integration: add rhel-7.8 rebased patches
Rebased against the RHEL-7.8 GA kernel-3.10.0-1127.el7.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2020-03-11 10:09:30 -04:00
Yannick Cote
0c3c219308 Bump version to v0.9.1
Increment version to v0.9.1 and update v0.9.0's changelog section
following many fixes and improvements.

*Note* that the tree has been tagged to v0.9.0 earlier at
(commit: fd8209aa00). This is to update the tree accordingly. Full
list of changes:

v0.9.1:
- Handle ppc64le toc with only constants
- Don't strip callback section symbols
- Integration tests update
- Fix -Wconversion warnings
- Process debug sections last

v0.9.0:
- Many fixes in integration tests and adding rhel-8.0
- Updates to documentation
- Many updates and additions to the patch author guide
- Fix to relocations used for ZERO_PAGE(0)
- Simplify static local variables correlation
- Make symvers reading code more flexible
- Free sections in elf teardown
- Fix kpatch-test module unloading
- Disable the build of kpatch.ko module by default
- Simplify mangled function correlation
- Use whole word filename matching in find_parent_obj()
- Simplify relocation processing

Signed-off-by: Yannick Cote <ycote@redhat.com>
2020-03-11 10:02:33 -04:00
Joe Lawrence
ffe36c7716 testing/integration: update rebase_patches tool
Update the rebase_patches hack^H^H^H tool to make it easier to define
environment variables to drive it, rather than sourcing source
/etc/os-release for everything.  Fix a bunch of shellcheck warnings
along the way.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2020-03-10 10:36:46 -04:00
Joe Lawrence
b4d2a4e504
Merge pull request #1079 from julien-thierry/fix-norela-toc
create-diff-object: Handle ppc64le toc with only constants
2020-03-03 14:40:47 -05:00
Joe Lawrence
2bf36a9a54
Merge pull request #1076 from euspectre/load-patches-before-network
kpatch.service: make sure it starts before networking services
2020-03-03 14:40:26 -05:00