Commit Graph

2040 Commits

Author SHA1 Message Date
Joe Lawrence
eb0e84f748
Merge pull request #1063 from haoren3696/master
kpatch-build: replace all '-' to '_' in KOBJFILE_NAME
2020-01-06 10:34:04 -05:00
Zhipeng Xie
61c55d9e52 kpatch-build: replace all '-' to '_' in KOBJFILE_NAME
When patching kernel module dm-persistent-data, I found
that the KOBJFILE_NAME is incorrectly replaced to
dm_persistent-data while the module name in kernel is
dm_persistent_data.

Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
2019-12-30 17:48:14 +08:00
Joe Lawrence
ff51f80177
Merge pull request #1041 from joe-lawrence/author-guide-updates
Author guide updates
2019-12-06 10:19:53 -05:00
Joe Lawrence
64027b4c9e patch-author-guide: remove kpatch.ko-era references
The kpatch.ko support module is no longer needed by modern upstream and
recent distribution kernels, so update the patch author guide
accordingly.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2019-12-05 15:01:01 -05:00
Joe Lawrence
cd305fd7ec patch-author-guide: add sibling call info
kpatch-build doesn't support GCC's sibling call optimizations in patched
functions to avoid potentially dangerous generated code.  Explain the
error message that may result and link to the commit which provided
detailed explanation of why we disabled support for this in kpatch.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2019-12-05 15:00:58 -05:00
Joe Lawrence
59fbf45d8e patch-author-guide: add jump label notes
Add a quick explanation for jump labels and how to workaround the
current limitations.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2019-12-05 14:48:29 -05:00
Joe Lawrence
1e2f73216f patch-author-guide: explain "inline" and implicit "notrace"
The kernel's definition of "inline" implies "notrace" and that may lead
to unexpected kpatch-build errors.  Explain why that is and how to work
around the issue.

Fixes #983.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2019-12-05 14:48:29 -05:00
Julien Thierry
68530e4c2b kpatch-build: Make local static twining stricter
The current code to find the twin of a local static variable allows two
variables of the same name to be wrongly matched with the other's twin.

While there isn't a magic formula to avoid this, make stricter
requirements for twining static local from the original object with
a symbol from the patched object. This reduces the risk of erroneous
matches.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2019-11-22 09:53:16 +00:00
Josh Poimboeuf
ea348164f6
Merge pull request #1058 from julien-thierry/doc-link-fix
doc: Update broken hyperlink
2019-11-14 10:47:49 -06:00
Julien Thierry
e4b6e1ff6e doc: Update broken hyperlink
Referenced kernel documentation has moved from txt file to rst. Update
the hyperlink to point to the correct file.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2019-11-14 11:39:25 +00:00
Josh Poimboeuf
19baa5b7c7 create-diff-object: process debug sections last
Process the debug sections only after all the other inclusion logic has
finished, since it makes decisions based on what else has already been
included.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-11-01 15:26:07 -05:00
julien-thierry
b53e4e3f44
Merge pull request #1048 from julien-thierry/correlation-rename-fixes
Correlation rename fixes
2019-11-01 07:41:21 +00:00
Julien Thierry
54553c0622 test/unit: Update unit test submodule
Include test for mangled symbol modification.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2019-11-01 07:37:54 +00:00
Julien Thierry
0c96fd0968 test/integration: Fix RHEL-8 test new-function for ppc64le
new-function test fails on ppc64le with the following message:

create-diff-object: ERROR: n_tty.o: kpatch_no_sibling_calls_ppc64le: 3445: Found an unsupported sibling call at n_tty_write()+0x20.  Add __attribute__((optimize("-fno-optimize-sibling-calls"))) to n_tty_write() definition.

Add the suggested attribute, as was done for rhel-7.[5-7] versions of
the test.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2019-10-31 12:49:24 +00:00
Julien Thierry
6943128ceb test/integration: Disable test affecting jump label on ppcle64
On ppcle64, test gcc-static-local-var-4 impacts a jump label reference
which is currently unsupported.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2019-10-31 12:49:24 +00:00
Julien Thierry
4710df3c78 test/integration: Disable RHEL-8.0 tests using jump labels
Jump labels are unsupported, so tests modifying functions using them are
expected to fail. So disable them, for now...

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2019-10-31 12:49:24 +00:00
Kamalesh Babulal
f42a4127f5 test/integration: Rebase to RHEL 8.0
Rebase the integration test cases on top of RHEL 8.0 kernel version
4.18.0-80.el8.

Suggested-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
[JT: adapt data-new-LOADED to new meminfo format,
     use common template for multiple.test]
Signed-off-by: Julien Thierry <jthierry@redhat.com>
2019-10-31 12:49:24 +00:00
Julien Thierry
0f648b8056 test/integration: Skip disabled tests for combined test
Disabled patches won't trigger a build, but the combined load test
will still attempt to run their associated LOADED.test script. The
combined test will fail due to voluntarily disabled tests.

Do not run tests scripts associated with disabled tests.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2019-10-31 12:47:01 +00:00
Julien Thierry
4aa909eb8f test/integration: Skip disabled tests in multiple.test
Tests intentionaly disabled should be skipped by multiple.test

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2019-10-31 12:47:01 +00:00
Julien Thierry
852bad5e8d create-diff-object: Use new helpers for static local correlation
Simplify static local variable correlation and renaming code by using
the newly introduced helpers for section and symbol correlation.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2019-10-29 15:29:51 +00:00
Julien Thierry
e49e3a59c2 create-diff-object: Rename elements getting correlated
Change 935f199875 ('create-diff-object: simplify mangled function
correlation') simplified the way symbols are correlated and got rid of
symbol section renaming.

As a result a symbol/section can now have a CHANGED status, being
correlated to an element that doesn't have the exact same name. This
will cause lookups to the original object fail when creating the new
patch object.

So lets bring back the symbol/section renaming, but only once they
have actually been correlated.

Fixes: 935f199875 ('create-diff-object: simplify mangled function
correlation')
Signed-off-by: Julien Thierry <jthierry@redhat.com>
2019-10-29 15:27:51 +00:00
Julien Thierry
49a9adaf74 create-diff-object: Correlate objects related to a section at once
Elements from the original object and the patched object can be
correlated using their mangled names. In case an elements (section or
symbol) could be matched with more than one object through mangling,
make sure all elements related to a section are correlated with the
corresponding elements of the twin section.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2019-10-29 15:27:51 +00:00
Julien Thierry
770f529225 kpatch-elf: Ensure stale references are not used
When freeing a kpatch_elf, another object might have symbols and
sections twined with elements that are getting freed.

Clear the twin references, so if they are used after the object they
reference is freed, the program will crash.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2019-10-29 10:48:02 +00:00
Josh Poimboeuf
e0bd024c18
Merge pull request #1052 from sm00th/symvers
Make symvers reading code more flexible.
2019-10-28 15:46:53 -05:00
Josh Poimboeuf
c9519b6a14
Merge pull request #1050 from julien-thierry/elf-teardown-free-sec
kpatch-elf: Free sections in elf teardown
2019-10-28 15:26:46 -05:00
Josh Poimboeuf
eec99f0923
Merge pull request #1046 from julien-thierry/unload-fixes
Unload fixes
2019-10-28 14:28:11 -05:00
Artem Savkov
3a1a73f08c Make symvers reading code more flexible.
Kernel commit cb9b55d21fe0 modpost: add support for symbol namespaces
adds a new namespace column to Module.symvers file which can be blank.
fscanf is no longer a viable solution to parse that. Switch to the way
scripts/mod/modpost.c handles this and try to support both versions with
and without namespace column.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-10-25 14:17:11 +02:00
Julien Thierry
a02842fb69 kpatch-elf: Free sections in elf teardown
Currently, only rela section get freed. This seems like a simple
scope mistake.

Free all sections regardless of their nature in kpatch_elf_teardown()

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2019-10-15 16:02:11 +01:00
Julien Thierry
c9a4e09b45 test/integration: Fix kpatch-test module unloading
The unload_all() function in kpatch-test script is out dated and
does not unload patches loaded through livepatching.

Luckily, "kpatch unload --all" should support both kpatch unloading
kpatch patches and livepatch patches.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2019-10-08 08:32:42 +01:00
Julien Thierry
58eead5a16 kpatch: Fix all module unloading
Some versions of Linux livepatching require patches to be unloaded
in the opposite order than the order they were loaded. Currently
kpatch simply goes through the list of sysfs livepatch directories
and tries to disable them one by one. This makes the following fail:

	$ kpatch load a.ko
	$ kpatch load b.ko
	$ kpatch unload --all
	kpatch: failed to unload module b

Since kpatch is not bound to a version of Linux, cater for those version
that do not support random unloading order, even for patches that do not
depend on one another.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2019-10-08 08:32:42 +01:00
Julien Thierry
e59355c2b7 test/integration: Make multiple.test cleanup after itself
If an error occurs while loading a module or one of the tests,
multiple.test will exit leaving the working modules loaded. This leaves
the system in an unwanted state and causes the test that previously pass
to fail (succeeding before being loaded for multiple.test's point of
view).

Cleanup the loaded modules before exiting due to errors.

Also take this opportunity to factorize the test for the different
distros.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2019-10-08 08:31:39 +01:00
Joe Lawrence
df5730076f
Merge pull request #1043 from jpoimboe/double-constprop
create-diff-object: simplify mangled function correlation
2019-10-07 13:46:17 -04:00
Joe Lawrence
d3416e2eff
Merge pull request #1042 from yhcote/gh966
kmod: don't build module by default
2019-10-07 13:45:57 -04:00
Yannick Cote
21645c6a07
kmod: don't build module by default
The stacktrace internal interface has been updated for v5.2. On x86,
among others, this means that stack_trace_save_tsk* is to be used
instead of instantiating a stack_trace struct. Those routines are
currently not exported for module use.

See linux kernel: <25e39e32b0a3> (livepatch: Simplify stack trace retrieval)
for more info about the stacktrace interface changes.

The kernel/livepatch subsystem is the way forward for using kpatch and
there are plans to phase out 'kmod' altogether in the near future.

It is still possible to build and use kmod by doing something like:
$ env BUILDMOD="yes" make

Closes #966

Signed-off-by: Yannick Cote <ycote@redhat.com>
2019-10-03 22:41:12 -07:00
Josh Poimboeuf
935f199875 create-diff-object: simplify mangled function correlation
The RHEL powerpc kernel is compiled with -O3, which triggers some
"interesting" new optimizations.  One of them, which seems to be
relatively common, is the replacing of a function with two separate
"constprop" functions.

Previously we only ever saw a single constprop clone, so we just renamed
the patched version of the function to match the original version.  Now
that we can have two such clones, that no longer makes sense.

Instead of renaming functions, just improve the correlation logic such
that they can be correlated despite having slightly different symbol
names.  The first clone in the original object is correlated with the
first clone in the patched object; the second clone is correlated with
the second clone; and so on.

This assumes that the order of the symbols and sections doesn't change,
which seems to be a reasonable assumption based on past experience with
the compiler.  Otherwise it will just unnecessarily mark the cloned
constprop functions as changed, which is annoying but harmless, and
noticeable by a human anyway.

Fixes #935.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-10-03 09:38:29 -05:00
Josh Poimboeuf
683289206b
Merge pull request #1038 from wwheart/master
kpatch-build: fix two parent matches error
2019-09-27 14:43:25 -05:00
Josh Poimboeuf
c175d8697c
Merge pull request #1039 from julien-thierry/misc-cleanups
Misc cleanups
2019-09-27 14:29:53 -05:00
Josh Poimboeuf
d131d43656
Merge pull request #1040 from sm00th/multiple_test
integration/rhel-*: fix multiple.test
2019-09-27 14:16:34 -05:00
chenzefeng
e9755413ed kpatch-build: use whole word filename matching in find_parent_obj()
Building a kpatch for a module with this Makefile:

The Makefile is as follow:
	obj-m += m_hello.o
	m_hello-y = hello.o
	default:
        	$(MAKE) -C /lib/modules/4.4.21-69-default/build M=$(shell pwd) modules
	clean:
        	$(MAKE) -C /lib/modules/4.4.21-69-default/build M=$(shell pwd) clean

results in kpatch-build "ERROR: two parent matches for hello.o".

The problem is that find_parent_obj() looks for filenames like so:

	% grep -l hello.o ./.*.cmd | grep -Fv hello.o
	.m_hello.ko.cmd
	.m_hello.o.cmd

where .m_hello.ko.cmd is the parant for m_hello.o, and .m_hello.o.cmd is the
parant for hello.o, but because the "hello.o" is a substring of "m_hello.o",
it will cause "m_hello.o" to be matched for the "hello.o" as well.

Fix this by using grep's -w|--word-regexp option to force it to match
whole words instead of substrings.

Signed-off-by: chenzefeng <chenzefeng2@huawei.com>
2019-09-27 09:36:39 +08:00
Artem Savkov
52d4936e72 integration/rhel-*: fix multiple.test
When these from internal depths of Red Hat upstream paths changed and
now we are one level deeper in directory tree.

The issue probably also exist in rhel8.0 rebase pr #993.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-09-18 12:29:50 +02:00
Josh Poimboeuf
0b000cb87d
Merge pull request #1037 from jpoimboe/ppc64le-remove-unsupported-check
Revert "create-diff-object: Check for *_fixup sections changes"
2019-09-17 11:37:05 -05:00
Josh Poimboeuf
7a9fc1fbc8
Merge pull request #1036 from sm00th/mod_cmd
Fix parent matches for kernels newer than 5.3
2019-09-17 11:36:48 -05:00
Julien Thierry
878bac379f create-diff-object: Simplify relocation processing
If the symbol associated with a relocation does not have a section set,
nothing is done for that relocation.

Skip iterating through all the symbols of the ELF file in such a case.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2019-09-17 15:42:01 +01:00
Julien Thierry
bd4fae25f9 create-diff-object: Add const to unmodified rela_insn arguments
rela_insn() only retrieves information about an instruction and does not
modify sections or relocations.

Add const to make this explicit.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2019-09-17 15:42:01 +01:00
Julien Thierry
50476c94cc create-diff-object: Check ELF headers earlier
There is no point inspecting through the symbols of the ELF files
(original and patched) when the ELF headers do not meet requirements.

Check ELF headers as soon as the files are mapped.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2019-09-17 15:42:01 +01:00
Josh Poimboeuf
2499eb2bdc Revert "create-diff-object: Check for *_fixup sections changes"
We are seeing the following error on a real world patch:

  unsupported reference to special section __barrier_nospec_fixup

The kpatch commit bb444c2168 ("create-diff-object: Check for *_fixup
sections changes") created this error because we were trying to be
future proof.  However, that may have been overly paranoid, as it
doesn't seem likely that those fixup sections will need relocations
anytime soon, because the replacement instructions are manually
generated in code.  And anyway that "future proof" commit breaks the
present.

Also we decided at LPC that we are going to remove .klp.arch sections
anyway, so once that happens we will be fully future-proof anyway.

This reverts commit bb444c2168.

Fixes #974.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-09-16 09:22:54 -05:00
Artem Savkov
aabdf9c9c9 Fix parent matches for kernels newer than 5.3
Somewhere starting with 5.3 (probably with 9f69a496f100 "kbuild: split
out *.mod out of {single,multi}-used-m rules", but that is not
confirmed) .mod and correcponding .mod.cmd files started showing up
during module builds throwing off kpatch-build's find_parent_obj() func.

Filter out any files ending with .mod.cmd as they are definitely not the
parent.

Signed-off-by: Artem Savkov <artem.savkov@gmail.com>
2019-09-16 14:18:32 +02:00
Joe Lawrence
0507ea2bb7
Merge pull request #1030 from joe-lawrence/verify-patch-files
kpatch-build: sanity check patched filenames
2019-09-03 10:19:08 -04:00
Joe Lawrence
debf44a0f1
Merge pull request #1034 from wipawel/osrelease
kpatch-build: Check if /etc/os-release exists
2019-08-28 15:40:11 -04:00
Pawel Wieczorkiewicz
ed5091b16f kpatch-build: Check if /etc/os-release exists
Not every distro out there supports /etc/os-release file.
This file is useful for obtaining given distro defaults, but not
essential for the script to work (when all parameters are passed
on a command line).

To avoid warnings or unwanted errors, make sourcing of this file
conditional.

Signed-off-by: Pawel Wieczorkiewicz <wipawel@amazon.de>
2019-08-27 14:52:05 +00:00