Commit Graph

2287 Commits

Author SHA1 Message Date
Josh Poimboeuf
629b5acf3d kpatch-build: Fix setlocalversion issue with 6.3 kernel
The kernel has a VERMAGIC_STRING, e.g. "6.2.0".  The module loader uses
that string to ensure that all loaded modules' version strings match the
kernel's.

If the kernel source is in a git tree, and if there are uncommitted
changes, the version string will have a '+' or "-dirty" appended to it,
like "6.1.0+" or "6.2.0-dirty".  This dirty tree detection is done by
the setlocalversion script.

This affects kpatch-build in a few ways.  When it builds the original
kernel, in some cases there are uncommitted changes to the makefiles.
When it builds the patched kernel, there are additional uncommitted
changes due to the .patch file being applied.

We want to avoid the VERMAGIC_STRING changing between builds.  Otherwise
it would cause problems:

  - object code which uses that string would change unnecessarily,
    causing a false positive change detected by create-diff-object

  - the linked patch module would report the wrong version, resulting in
    the module failing to load due to version mismatch.

Up until now, the version was prevented from changing by running
`setlocalversion --save-scmversion` before the build.  That command
hard-codes the version by saving it to a file which is then
automatically read later during future invocations of the kernel build.

Unfortunately that feature was removed in the 6.3 merge window with
commit f6e09b07cc12 ("kbuild: do not put .scmversion into the source
tarball").  So we need to come up with a new approach.

Fix it by temporarily replacing the setlocalversion script with a
one-liner which just echo's the original version.  I think this is
unfortunately the best we can do, as we really can't handle
VERMAGIC_STRING changing, either during/between kernel builds or during
the module link.

Fixes #1335.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2023-03-13 14:40:24 -07:00
Joe Lawrence
3f5845c28c
Merge pull request #1334 from joe-lawrence/create-v0.9.8
Bump to version v0.9.8
2023-03-10 12:11:56 -05:00
Joe Lawrence
2db193eb8b Bump to version v0.9.8
Updates of interest:
v0.9.8:
- Clang fix ups from Pete Swain
- Support for gcc-12
- Support for Linux 5.19
- Added RHEL-8.7 and 9.1 integration tests
- Fixed __UNIQUE_ID() variable correlation
- Improved handling of unsupported static calls

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2023-03-08 15:48:21 -05:00
Joe Lawrence
8ddfc5d25e
Merge pull request #1330 from sumanthkorikkar/update-s390-kernel-prerequisite
doc: Update s390 kernel prerequisite
2023-03-06 16:10:41 -05:00
Joe Lawrence
e8627520c6
Merge pull request #1326 from joe-lawrence/batch-sibling-calls
create-diff-object: batch report unsupported sibling calls
2023-03-06 16:10:09 -05:00
Sumanth Korikkar
324a43714b doc: Update s390 kernel prerequisite
Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
2023-02-23 15:30:01 +01:00
Joe Lawrence
75421ca94c create-diff-object: batch report unsupported sibling calls
Like unsupported jump labels and static call sites, batch report all
unsupported sibling calls so the kpatch developer doesn't need to
iteratively find them all.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2023-02-17 11:49:38 -05:00
Joe Lawrence
a45c17f849
Merge pull request #1323 from lulinqing/master
examples: add cmdline-string.patch as a compatible example
2023-01-25 16:58:54 -05:00
Linqing Lu
fa73892346 examples: add cmdline-string.patch as a compatible example
This is a test example currently preferable to proc-version.patch as
crash utility has difficulty parsing /proc/version content after being
altered.

Signed-off-by: Linqing Lu <lilu@redhat.com>
2023-01-25 16:55:55 -05:00
Josh Poimboeuf
059467dbc5
Merge pull request #1318 from jpoimboe/static-call-patch-author-guide
patch-author-guide: update jump label / static call descriptions
2022-12-02 11:47:41 -06:00
Josh Poimboeuf
a6aa2d8f37
Merge pull request #1319 from jpoimboe/github-unit
github actions: fix warning with node 16
2022-12-02 09:40:22 -06:00
Josh Poimboeuf
48854d5633 create-diff-object: rename "dynrela" -> "klp_reloc"
The term "dynrela" was invented before klp relocations ever existed.
They're basically the same thing: special livepatch-specific relocations
which get applied when the patched object gets loaded or patched.
They're necessary due to a) the need to access unexported symbols; and
b) late module patching.

The different names are confusing.  Consolidate them by replacing
"dynrela" with "klp_reloc" (code) or "klp relocation" (English).

Note there's still some antiquated code in the kpatch core module and in
the pre-4.7 klp patch template which still use the "dynrela" naming.
That code is mostly dead anyway so I've just left it alone.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-12-01 14:00:09 -08:00
Josh Poimboeuf
41128c0987 patch-author-guide: update jump label / static call descriptions
Now that we have KPATCH_STATIC_CALL(), document its usage.  While at it,
give a more thorough description for why jump labels and static calls
aren't supported in some scenarios.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-12-01 14:00:09 -08:00
Josh Poimboeuf
2c341722c3 github actions: fix warning with node 16
Attempt to fix the following warning:

  Node.js 12 actions are deprecated. For more information see: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/. Please update the following actions to use Node.js 16: actions/checkout@v2

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-12-01 09:08:29 -08:00
Josh Poimboeuf
063a0801d9
Merge pull request #1317 from jpoimboe/fix-make-check
kpatch-build: fix "make check"
2022-12-01 10:46:33 -06:00
Josh Poimboeuf
042cde03b3 kpatch-build: fix "make check"
For some reason the github version of 'make check' just started
complaining about these:

shellcheck kpatch/kpatch kpatch-build/kpatch-build kpatch-build/kpatch-cc

In kpatch-build/kpatch-build line 455:
	while [[ "${filedir#$common/}" = "$filedir" ]]; do
                            ^-----^ SC2295 (info): Expansions inside ${..} need to be quoted separately, otherwise they match as patterns.

Did you mean:
	while [[ "${filedir#"$common"/}" = "$filedir" ]]; do

In kpatch-build/kpatch-build line 460:
	result="${result}${filedir#$common/}"
                                   ^-----^ SC2295 (info): Expansions inside ${..} need to be quoted separately, otherwise they match as patterns.

Did you mean:
	result="${result}${filedir#"$common"/}"

In kpatch-build/kpatch-cc line 26:
			relobj=${obj##$KPATCH_GCC_SRCDIR/}
                                      ^----------------^ SC2295 (info): Expansions inside ${..} need to be quoted separately, otherwise they match as patterns.

Did you mean:
			relobj=${obj##"$KPATCH_GCC_SRCDIR"/}

For more information:
  https://www.shellcheck.net/wiki/SC2295 -- Expansions inside ${..} need to b...
make: *** [Makefile:70: check] Error 1
Error: Process completed with exit code 2.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-11-30 19:04:23 -08:00
Josh Poimboeuf
95f87659c9
Merge pull request #1315 from jpoimboe/static-call-fixes
Static call fixes
2022-11-30 14:58:58 -06:00
Josh Poimboeuf
b6bf122171 test/unit: bump
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-11-30 12:58:44 -08:00
Josh Poimboeuf
92c178b6a3 create-diff-object: use errx() instead of err()
Otherwise on recent distros it appends the errno to the error message,
like:

  create-diff-object: ERROR: x86.o: kpatch_regenerate_special_section: 2633: Found 1 unsupported static call(s) in the patched code. Use KPATCH_STATIC_CALL() instead.: Success

which is not what we want in most cases.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-11-30 12:58:31 -08:00
Josh Poimboeuf
ab2397c03e kpatch-macros: add KPATCH_STATIC_CALL()
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-11-30 12:58:31 -08:00
Josh Poimboeuf
f83218ad12 create-diff-object: detect unsupported static calls
Similar to jump labels, static calls aren't supported when the static
call key was originally defined in a module rather than in vmlinux.
Detect those cases and either remove them (in the case of tracepoints)
or error out.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-11-30 12:58:31 -08:00
Josh Poimboeuf
56bd8c4d0d create-diff-object: refactor jump label filtering
Convert the hard-coded should_keep_jump_label() to a proper callback,
since static calls will need a similar filter.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-11-30 12:58:31 -08:00
Josh Poimboeuf
87ad96760a create-diff-object: fix s390 special_section initializer spacing
Align the s390 special_section initializers to improve readability and
for consistency with the rest.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-11-30 12:58:31 -08:00
Josh Poimboeuf
984e7de2fc
Merge pull request #1314 from jpoimboe/unique-id-fix
create-diff-object: fix __UNIQUE_ID() variable correlation
2022-11-30 14:55:18 -06:00
Josh Poimboeuf
3bcaabc7e1 test/unit: bump
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-11-30 12:53:41 -08:00
Josh Poimboeuf
901445a54f create-diff-object: fix __UNIQUE_ID() variable correlation
kpatch_mangled_strcmp() only ignores the digits after the period, but in
the case of __UNIQUE_ID(), the symbol names have random digits before
the period due to the use of `__COUNTER__`.  Make sure such symbols are
properly correlated.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-11-21 19:46:18 -08:00
Joe Lawrence
bc145e95e5
Merge pull request #1311 from joe-lawrence/add-proc-version-example
examples: add /proc/version kpatch sample
2022-11-08 08:36:37 -05:00
Joe Lawrence
2feeb0f462 examples: add /proc/version kpatch sample
Create a simple kpatch test that should apply across a wide range of
kernels.  The version_proc_show() is a good candidate as it's easy to
verify and hasn't been touched upstream since 2008.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-11-07 11:02:00 -05:00
Joe Lawrence
a2333df7da
Merge pull request #1309 from joe-lawrence/integration-tests-kernel-4.18.0-425.3.1.el8
test/integration/rhel-8.7: add kernel-4.18.0-425.3.1.el8 tests
2022-11-07 08:01:39 -05:00
Joe Lawrence
51b4a7ce07
Merge pull request #1308 from joe-lawrence/integration-tests-kernel-5.14.0-162.6.1.el9_1
test/integration/rhel-9.1: add kernel-5.14.0-162.6.1.el9_1 tests
2022-11-07 08:01:25 -05:00
Joe Lawrence
a6958eca1c test/integration/rhel-8.7: add kernel-4.18.0-425.3.1.el8 tests
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-10-24 15:44:16 -04:00
Joe Lawrence
314504b777 test/integration/rhel-9.1: add kernel-5.14.0-162.6.1.el9_1 tests
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-10-24 15:34:26 -04:00
Josh Poimboeuf
f1fbf97345
Merge pull request #1289 from jpoimboe/find_kobj
kpatch-build: support Linux 5.19 .cmd file format
2022-10-14 11:18:47 -05:00
Josh Poimboeuf
1d7e8a74bb kpatch-build: support Linux 5.19 .cmd file format
Rewrite kobj_find() to deal with Linux 5.19, where the .cmd files use
object file paths relative to the .cmd file rather than relative to the
root of the kernel tree.

While at it, add several performance enhancements to prevent all
currently known deep finds.

This is all quite fiddly.  But it works.

Fixes #1277.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-10-12 16:55:31 -07:00
Josh Poimboeuf
7861240f48 kpatch-build: Add find_kobj() short-circuit for OOT modules
When patching an OOT module, the parent object is always the OOT module.
Hard-code that to prevent the need for any further special casing in
find_kobj() (e.g., commit 9143e88f16 ("kpatch-build: fix
find_parent_obj")).

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-10-12 16:55:31 -07:00
Josh Poimboeuf
1ead10d2b2 kpatch-cc: Add more file ignores
These files aren't in the kernel proper, and can be ignored.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-10-12 16:55:31 -07:00
Joe Lawrence
6507700d02
Merge pull request #1305 from joe-lawrence/llvm-from-swine
Collection of small llvm fixes
2022-10-04 10:06:23 -04:00
Joe Lawrence
114878a002
Merge pull request #1306 from joe-lawrence/gcc-12-ppc64le-plugin
gcc-plugin: update headers for gcc-12
2022-10-04 10:05:56 -04:00
Joe Lawrence
13182e50b0 gcc-plugin: update headers for gcc-12
Fix build error seen on gcc (GCC) 12.1.1 20220507 (Red Hat 12.1.1-1):

  g++ -MMD -MP -I../kmod/patch -Iinsn -Wall -Wsign-compare -Wno-sign-conversion -g -Werror -shared -I/usr/lib/gcc/ppc64le-redhat-linux/12/plugin/include -Igcc-plugins -fPIC -fno-rtti -O2 -Wall gcc-plugins/ppc64le-plugin.c -o gcc-plugins/ppc64le-plugin.so
  In file included from /usr/include/features.h:490,
                   from /usr/include/bits/libc-header-start.h:33,
                   from /usr/include/stdio.h:27,
                   from /usr/lib/gcc/ppc64le-redhat-linux/12/plugin/include/system.h:46,
                   from /usr/lib/gcc/ppc64le-redhat-linux/12/plugin/include/gcc-plugin.h:28,
                   from gcc-plugins/gcc-common.h:6,
                   from gcc-plugins/ppc64le-plugin.c:1:
  /usr/include/bits/error-ldbl.h:23:1: error: type of ‘error’ is unknown
     23 | __LDBL_REDIR_DECL (error)
        | ^~~~~~~~~~~~~~~~~
  /usr/include/bits/error-ldbl.h:23:1: error: ‘int error’ redeclared as different kind of entity
     23 | __LDBL_REDIR_DECL (error)
        | ^~~~~~~~~~~~~~~~~
  In file included from gcc-plugins/ppc64le-plugin.c:2:
  /usr/include/error.h:31:13: note: previous declaration ‘void error(int, int, const char*, ...)’
     31 | extern void error (int __status, int __errnum, const char *__format, ...)
        |             ^~~~~
  make[1]: *** [Makefile:39: gcc-plugins/ppc64le-plugin.so] Error 1

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-09-27 16:41:48 -04:00
Pete Swain
85781b7ea7 create-diff-object: ignore .llvm.* sections
Clang FDO adds a new, ignorable ELF section, .llvm.call-graph-profile

Generalize to ignore all .llvm.*

Signed-off-by: Pete Swain <swine@google.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com> [subject line]
2022-09-27 15:56:06 -04:00
Pete Swain
3704057244 create-diff-object: ignore clang's .llvm_addrsig sections
Signed-off-by: Pete Swain <swine@google.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com> [subject line]
2022-09-27 15:56:06 -04:00
Pete Swain
5f6c5965f1 kpatch-build: for clang, use .strtab if no .shstrtab
While gcc puts strings in .strtab and .shstrtab sections,
llvm toolchain just uses .strtab.

Adapt kpatch to handle both styles.

Signed-off-by: Pete Swain <swine@google.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com> [small changes]
2022-09-27 15:56:06 -04:00
Joe Lawrence
4a59a546da
Merge pull request #1299 from yhcote/bump-0.9.7
Bump to version v0.9.7
2022-09-26 11:48:50 -04:00
Joe Lawrence
7ec1ed6330
Merge pull request #1303 from anatasluo/temp
kpatch-build: strengthen conditions for changed sections
2022-09-23 17:05:19 -04:00
Joe Lawrence
e9742249c1
Merge pull request #1304 from joe-lawrence/unit-test-eh_frame
test/unit: update for .eh_frame removal
2022-09-23 17:04:33 -04:00
Joe Lawrence
71fbd169f0 test/unit: update for .eh_frame removal
Update the unit test submodule reference to include ppc64le files w/o
.eh_frame.  At the same time, give additional guidance on stripping
these sections going forward.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-09-23 14:14:40 -04:00
Longjun Luo
d46fea98ef kpatch-build: strengthen conditions for changed sections
If two sections want to be the same, they need to satisfy
two conditions:

1) the result of memcmp is zero, which means they
have the same content.

2) they have the same relocation entries.

In one specific situation, two sections have the same content.
But one section has relocation entries while the other one has
no relocation entries. For example, in X86, consider the
following code:

original code
```
__noreturn noinline int kpatch_func(void)
{
	while(1) {};
}
```

patched code
```
__noreturn notrace noinline int kpatch_func(void)
{
	asm(".byte 0xe8, 0x00, 0x00, 0x00, 0x00");
	while(1){};
}
```

Since the original code has a fentry call, these two functions have
the same compile result. But obviously, they are different functions.
Currently, kpatch would not find their differences since the patched
code has no relocation entries.

For the situation that one section has relocation entries while the
other one doesn't have, it should be set to be changed directly.

Cooperated-by: Zongwu Li <lizongwu@huawei.com>
Signed-off-by: Longjun Luo <luolongjuna@gmail.com>
2022-09-23 23:52:53 +08:00
Josh Poimboeuf
80fc15ac36
Merge pull request #1301 from anatasluo/master
kpatch-build: rela section could disappear after patched
2022-09-23 10:15:55 -05:00
Joe Lawrence
1f6a7dbbc0
Merge pull request #1298 from SuperSandro2000/patch-1
Add syntax highlighting to code blocks
2022-09-22 11:38:06 -04:00
Longjun Luo
9fac261ed0 kpatch-build: rela section could disappear after patched
After patched, rela information for some sections could
disappear. For example, a function like the following:

"
notrace noinline static int version_proc_show(struct seq_file *m,
    void *v)
{
    return 0;
}
"

Apart from common rela entries, trace and return thunk mechanism
will generate rela information. Use `notrace` to remove the
effect of trace. Make CONFIG_RETHUNK=n can remove the effect of
return thunk.

Discovered-by: Zongwu Li <lizongwu@huawei.com>
Signed-off-by: Longjun Luo <luolongjuna@gmail.com>
2022-09-21 10:10:41 +08:00