Commit Graph

2281 Commits

Author SHA1 Message Date
Joe Lawrence
a19c4ed296 testing: pass KPATCH_BUILD_OPTS to kpatch-test
Update the test/integration/Makefile to pass a KPATCH_BUILD_OPTS
variable to kpatch-test.  This allows the user better control over the
kpatch build process, for example, building non-atomic replace .ko files
on kernels that do support atomic-replace:

  % make integration KPATCH_BUILD_OPTS="--non-replace"

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2021-08-09 17:58:02 -04:00
Joe Lawrence
a02668a0f7 kmod: remove redundant -mcmodel=large on ppc64le
In PR #1205, Kamalesh reports:

  ... I see that the -mcmodel=large flag is being passed twice with
  KBUILD_CFLAGS_MODULE set:

  gcc -Wp,-MMD,/root/.kpatch/tmp/patch/.livepatch-meminfo.mod.o.d ............ -mcmodel=medium .... -I/root/kpatch/kmod/patch -mcmodel=large -fplugin=/root/kpatch/kpatch-build/gcc-plugins/ppc64le-plugin.so ... -DMODULE -mno-save-toc-indirect -mcmodel=large -mcmodel=large -DKBUILD_BASENAME='"livepatch_meminfo.mod"' -DKBUILD_MODNAME='"livepatch_meminfo"' -D__KBUILD_MODNAME=kmod_livepatch_meminfo -c -o /root/.kpatch/tmp/patch/livepatch-meminfo.mod.o /root/.kpatch/tmp/patch/livepatch-meminfo.mod.c.

  I loaded the module built without the KBUILD_CFLAGS_MODULE +=
  -mcmodel=large flag and seems to okay. I guess, we can remove the arch
  specific flag from the Makefile.

Suggested-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2021-08-09 17:58:02 -04:00
Joe Lawrence
624e5e3b82 kmod: pass CFLAGS_MODULE to module build
The kmod/patch/Makefile defines KBUILD_CFLAGS_MODULE, but it seems that
kbuild doesn't honor it as environment variable.  This is noticed when
attempting to use the kpatch-build --non-replace option: the flag is
added to KBUILD_CFLAGS_MODULE, yet the kernel module build ignores it.

At the same time, the kernel docs suggest passing CFLAGS_MODULE [1], not
KBUILD_CFLAGS_MODULE, from the commandline.  Setup KPATCH_MAKE to pass
these options through that variable.

[1] https://www.kernel.org/doc/Documentation/kbuild/makefiles.txt

Fixes: c14e6e9118 ("kpatch-build: Add PPC64le livepatch support")
Fixes: 17dcebf077 ("kpatch-build: enable klp with replace option by default")
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2021-08-09 17:58:02 -04:00
Joe Lawrence
58c816ebd4
Merge pull request #1199 from joe-lawrence/kpatch-build-extraversion
kpatch-build: set EXTRAVERSION and not localversion for RH kernels
2021-07-20 11:22:44 -04:00
Artem Savkov
948fb639c6
Merge pull request #1200 from sm00th/secsym
Make sure section symbols exist
2021-07-19 09:00:17 +02:00
Artem Savkov
ae574f6975 Bump unittest objs submodule
Update unittest objects submodule to point to a version that contains
objectfiles to test #1193.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-07-13 17:42:36 +02:00
Artem Savkov
5622e3cc3d Make sure section symbols exist
Binutils recently became much more aggressive about removing unused
section symbols. Since we can not rely on those being available anymore
add additional checks before using them.

Fixes: #1193

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-07-13 17:40:58 +02:00
Artem Savkov
59aabd154e
Merge pull request #1186 from gwelymernans/secsym-pr
create-diff-object: Check that the section has a secsym
2021-07-13 17:40:01 +02:00
Joe Lawrence
a26b2af2a3 kpatch-build: set EXTRAVERSION and not localversion for RH kernels
There are some Red Hat kernel NVR combinations like
"kernel-5.13.0-0.rc4.33.el9.x86_64" that don't work well with our srpm
localversion strategy and end up botching the utsrelease.h file... which
allows for kpatch builds, but the module loader rightly rejects the
vermagic mismatch.

An ordinary rpmbuild sets up the kernel Makefile with:

  # make sure EXTRAVERSION says what we want it to say
  # Trim the release if this is a CI build, since KERNELVERSION is limited to 64 characters
  ShortRel=$(perl -e "print \"%{release}\" =~ s/\.pr\.[0-9A-Fa-f]{32}//r")
  perl -p -i -e "s/^EXTRAVERSION.*/EXTRAVERSION = -${ShortRel}.%{_target_cpu}${Variant:++${Variant}}/" Makefile

The simplest fix is just adding the version string to the kernel
Makefile EXTRAVERSION as rpmbuild would do (minus the perl voodoo).

Fixes: #1196
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2021-07-02 16:34:27 -04:00
Artem Savkov
cecf544e8e
Merge pull request #1190 from liu-song-6/kpatch-rmmod-before-insmod
kpatch: rmmod module of the same name before loading a module
2021-06-21 11:03:20 +02:00
Artem Savkov
0331438d7e
Merge pull request #1183 from liu-song-6/replace
kpatch-build: enable option -R|--replace to build replace klp
2021-06-21 11:02:49 +02:00
Song Liu
df1e98f2c7 kpatch: rmmod module of the same name before loading a module
With klp->replace, when a patch is replaced, it is no longer an active
patch, but the module is still loaded with a refcount of 0. If the user
tries to load the patch again, insmod will fail with EEXIT. To avoid
such errors, run a proactive rmmod before loading the module. This is a
no-op if the module is not loaded or is actually in use.

Also, update module_ref_count() to only succeed with refcnt > 1.

Signed-off-by: Song Liu <song@kernel.org>
2021-06-18 12:09:16 -07:00
Joe Lawrence
10abc1bbc3
Merge pull request #1192 from xiejingf/upstream_master
kpatch: use /sys/kernel/kpatch/ to check whether core module is loaded
2021-06-17 16:58:28 -04:00
tim.xjf
39f695bbb2 kpatch: use /sys/kernel/kpatch/ to check whether core module is loaded
Fixes #1187

checking if kpatch_register or klp_enable_patch exists in /proc/kallsyms
might not be reliable when module loading or unloading occurs at the same time.
The kernel implementation about /proc/kallsyms is not guranteed to be consistent.

Signed-off-by: xiejingfeng <xiejingfeng@linux.alibaba.com>
2021-06-12 00:43:45 +08:00
Joe Lawrence
6d90e31172
Merge pull request #1189 from theyoyojo/fixes_1188
kpatch: Sync signal subcmd usage output with manpage
2021-06-08 11:29:08 -04:00
Joel Savitz
17539e71e7 kpatch: Sync signal subcmd usage output with manpage
Fixes: 1188

Signed-off-by: Joel Savitz <jsavitz@redhat.com>
2021-06-07 17:40:30 -04:00
Bill Wendling
ba3defa060 create-diff-object: Check that the section has a secsym
A STT_SECTION symbol is not needed if if it is not used as a relocation
target. Therefore, a section, in this case a debug section, may not have
a secsym associated with it.

Signed-off-by: Bill Wendling <morbo@google.com>
2021-06-03 01:50:16 -07:00
Artem Savkov
cbbdae2a3d
Merge pull request #1185 from jpoimboe/irc-libera
README.md: Migrate #kpatch IRC channel to libera.chat
2021-05-27 09:21:56 +02:00
Josh Poimboeuf
87ca62d8de README.md: Migrate #kpatch IRC channel to libera.chat
Move the #kpatch channel to libera.chat due to the freenode implosion.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2021-05-26 15:40:26 -05:00
Song Liu
4b68be868f kpatch-test: disable replace flag when the kernel doesn't support it
For redhat kernel < 4.18.0-193.el8 or non-redhat kernel version < 5.1,
add -R to $KPATCHBUILD_OPTS.

Signed-off-by: Song Liu <song@kernel.org>
2021-05-25 15:22:27 -07:00
Song Liu
8487a0ca0a manpages: update kpatch-build with -R | --non-replace option
Signed-off-by: Song Liu <song@kernel.org>
2021-05-25 15:21:44 -07:00
Song Liu
69e69d59e8 doc: kpatch-build uses "replace" flag by default
Add documentation about kpatch-build enables livepatch "replace" flag by
default, and provides -R|--non-replace option to disable the flag.

Signed-off-by: Song Liu <song@kernel.org>
2021-05-25 15:19:16 -07:00
Song Liu
17dcebf077 kpatch-build: enable klp with replace option by default
Since 5.1 kernel, klp_patch supports a "replace" option, which does atomic
replace of cumulative patches. Enable building such patch by default. If
replace behavior is not desired, the user can use -R|--non-replace option
to disable it.

Signed-off-by: Song Liu <song@kernel.org>
2021-05-25 15:18:36 -07:00
Joe Lawrence
97b69bee75
Merge pull request #1172 from jpoimboe/out-of-range-rela-fix
A couple of fixes for the out-of-range relocation check
2021-05-05 12:35:26 -04:00
Yannick Cote
e499f09942
Merge pull request #1175 from yhcote/master
Bump to v0.9.3
2021-04-20 14:45:58 -04:00
Yannick Cote
35b771712e Bump to v0.9.3
Interesting changes since v0.9.2:

- Initial support for clang compiler
- Add support for rhel-8.4
- rhel-8.4: workaround pahole and extended ELF sections
- rhel-8.4: drop klp.arch support
- Kpatch command waits for module to fully unload
- Kpatch command informs user when signal subcommand is unnecessary
- kpatch-build skips ppc64le vdso files

Signed-off-by: Yannick Cote <ycote@redhat.com>
2021-04-20 14:34:00 -04:00
Joe Lawrence
c819391c26
Merge pull request #1174 from joe-lawrence/rhel-8.4-support
Additional rhel 8.4 support
2021-04-20 14:19:57 -04:00
Joe Lawrence
fed5786932 integration: add rhel-8.4
Rebased to kernel-4.18.0-304.el8.

Note: since RHEL-8.4 dropped klp.arch support, we can now re-enable
those tests that reference static keys defined in vmlinux.

Also, adjust for adjust for ppc64le inlining:

Building gcc-static-local-var-4.patch on ppc64le results in test
failure, as the kpatch .ko now contains a 'free_ioctx' symbol (the test
expects to NOT see one).

From the build log:

  aio.o: changed function: free_ioctx
  aio.o: new function: put_aio_ring_file      << now un-inlined?
  aio.o: changed function: aio_free_ring
  aio.o: changed function: ioctx_alloc
  aio.o: changed function: aio_prep_rw
  aio.o: changed function: aio_read_events
  aio.o: new function: kpatch_aio_foo         << expected new function

and a source code change to free_ioctx():

  % diff -upr \
       <(objdump -D -j .text.free_ioctx ~/.kpatch/tmp/orig/fs/aio.o) \
       <(objdump -D -j .text.free_ioctx ~/.kpatch/tmp/patched/fs/aio.o)

  --- /dev/fd/63  2020-10-26 14:28:18.086236019 -0400
  +++ /dev/fd/62  2020-10-26 14:28:18.086236019 -0400
  @@ -1,5 +1,5 @@

  -/root/.kpatch/tmp/orig/fs/aio.o:     file format elf64-powerpcle
  +/root/.kpatch/tmp/patched/fs/aio.o:     file format elf64-powerpcle

   Disassembly of section .text.free_ioctx:
  @@ -53,7 +53,7 @@ Disassembly of section .text.free_ioctx:
     b0:  00 00 82 3c     addis   r4,r2,0
     b4:  00 00 84 e8     ld      r4,0(r4)
     b8:  78 fb e6 7f     mr      r6,r31
  -  bc:  e0 00 63 38     addi    r3,r3,224
  +  bc:  38 00 63 38     addi    r3,r3,56
     c0:  01 00 00 48     bl      c0 <free_ioctx+0xb8>
     c4:  00 00 00 60     nop
     c8:  70 ff ff 4b     b       38 <free_ioctx+0x30>

Marking put_aio_ring_file() as __always_inline keeps the r3 / 224
offset value, leaving free_ioctx() unchanged.  Since it's no longer
included in the resulting .ko, gcc-static-local-var-4.test will pass
once again.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2021-04-20 11:40:59 -04:00
Joe Lawrence
d9f49e850a kpatch-build: drop klp.arch support in RHEL-8.4
RHEL-8.4 backported the "livepatch,module: Remove .klp.arch and
module_disable_ro()" patchset, so update kpatch-build accordingly.

Link: https://lore.kernel.org/live-patching/nycvar.YFH.7.76.2005080016330.25812@cbobk.fhfr.pm/T/#t
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2021-04-20 11:17:56 -04:00
Josh Poimboeuf
81f9ca4833 create-diff-object: Fix out-of-range relocation check
Improve the relocation check for the case where the referenced symbol
isn't at the beginning of the section.

Note that the check still isn't perfect, as many relocations have a
negative addend.  But it's still a lot better than nothing.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2021-04-13 14:04:54 -05:00
Josh Poimboeuf
fa5a95cafd create-diff-object: Fix out-of-range relocation error message
Showing sec+addend isn't valid, show sym+addend instead.

Before:

  create-diff-object: ERROR: sys.o: kpatch_check_relocations: 2550: out-of-range relocation .rodata.__kpatch_do_sys_uname.str1.1+139 in .rela.text.__kpatch_do_sys_uname

After:

  create-diff-object: ERROR: sys.o: kpatch_check_relocations: 2550: out-of-range relocation .LC7+139 in .rela.text.__kpatch_do_sys_uname

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2021-04-13 13:58:59 -05:00
Joe Lawrence
453fb1b97a
Merge pull request #1167 from jpoimboe/static-call
kpatch-build: add support for static calls
2021-03-24 13:47:59 -04:00
Joe Lawrence
a9d435ae8e
Merge pull request #1163 from joe-lawrence/rhel-8.4-no-klp-arch
kpatch-build: drop klp.arch support in RHEL-8.4
2021-03-24 13:47:41 -04:00
Joe Lawrence
509bfab25f
Merge pull request #1168 from sm00th/actions
github actions: unit tests
2021-03-24 13:47:19 -04:00
Josh Poimboeuf
7be75549ba kpatch-build: add support for static calls
Add the new .static_call_sites special section.

Fixes #1165.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2021-03-24 10:37:44 -05:00
Artem Savkov
5abe5f666b github actions: unit tests
Add unit tests through github actions. This is exactly the same as our
travis tests but using github actions instead.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-03-23 08:47:29 +01:00
Joe Lawrence
6d466fa76f kpatch-build: drop klp.arch support in RHEL-8.4
RHEL-8.4 backported the "livepatch,module: Remove .klp.arch and
module_disable_ro()" patchset [1], so update kpatch-build accordingly.

[1] https://lore.kernel.org/live-patching/nycvar.YFH.7.76.2005080016330.25812@cbobk.fhfr.pm/T/#t

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2021-03-18 21:58:57 -04:00
Joe Lawrence
f9d2ec1d77 kpatch-build: fix kernel_is_rhel() for rhel-8 z-stream kernels
During review of PR #1163, Josh reported:

  When trying this out, I think I found that kernel_is_rhel() is broken
  for z-stream kernels. It expects a "." after the el8, like ".el8.",
  but [rhel-8] z-stream kernels have the minor version appended to the
  major version like ".el8_3".

Tweak the regex pattern in kernel_is_rhel() to account for such z-stream
kernel versions.  At the same time, add .el9 to the regex in preparation
of rhel-9.

Reported-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2021-03-18 21:58:01 -04:00
Artem Savkov
6321c9ab5e
Merge pull request #1162 from sm00th/cold-noid
support for .cold functions with no id suffix
2021-03-09 10:26:33 +01:00
Artem Savkov
d84c734245 Bump unittest objfile submodule
Update unittest submodule pointer to include unittests for this case.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-03-05 09:20:40 +01:00
Artem Savkov
1b5a17f934 create-build-diff: support for .cold functions with no id suffix
create-build-diff expects .cold functions to be suffixed by an id, which
is not always the case. Drop the trailing '.' when searching for cold
functions.

Fixes: #1160

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-03-04 15:55:58 +01:00
Artem Savkov
09a42787d5
Merge pull request #1161 from sm00th/btf8.2
kpatch-build: check existance of Makefile.modfinal
2021-03-04 12:29:12 +01:00
Artem Savkov
fc4a56f6b2 kpatch-build: check existance of Makefile.modfinal
It turns out there is a stretch of time in kernel's history when
CONFIG_DEBUG_INFO_BTF was already added, but Makefile.modfinal wasn't
split off yet. To address those we need to either check the file's
existance or, as @liu-song-6 suggested initially, check config for
CONFIG_DEBUG_INFO_BTF_MODULES=y.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-03-03 09:13:30 +01:00
Artem Savkov
4dd3572ac5
Merge pull request #1159 from liu-song-6/workaround_modules_btf
kpatch-build: workaround pahole and CONFIG_DEBUG_INFO_BTF_MODULES
2021-03-03 08:16:05 +01:00
Song Liu
4cc2f06279 kpatch-build: workaround pahole and CONFIG_DEBUG_INFO_BTF_MODULES
With CONFIG_DEBUG_INFO_BTF_MODULES, the kernel build process adds BTF to
each in-tree modules. However, this process is broken with kpatch, with
error message like:

  Failed to parse base BTF 'vmlinux': -4001

Unblock build with CONFIG_DEBUG_INFO_BTF_MODULES with similar workaround
as the one for CONFIG_DEBUG_INFO_BTF.

Signed-off-by: Song Liu <songliubraving@fb.com>
2021-03-02 12:42:39 -08:00
Artem Savkov
73e3984ec4
Merge pull request #1158 from sm00th/dircleanup
kpatch: cleanup install directory
2021-03-01 17:07:37 +01:00
Artem Savkov
47c1bd435a kpatch: cleanup install directory
On module installation kpatch utility creates a directory with kernel
version as a name in /var/lib/kpatch which is never removed. To address
this check if any files are left in this directory after each
'uninstall' call and if not - remove it.

Signed-off-by: Artem Savkov <artem.savkov@gmail.com>
2021-02-25 15:34:03 +01:00
Artem Savkov
1f4e3d752a
Merge pull request #1156 from sm00th/clang
clang support
2021-02-24 15:17:33 +01:00
Artem Savkov
d81447fb26 Include clang unit tests
Bump submodule pointer to include clang unit-tests.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-02-19 12:41:12 +01:00
Artem Savkov
6c83b642a4 create-diff-object: make digit tail optional in kpatch_mengled_strcmp
Make kpatch_mangled_strcmp treat two strings as the same in case when
one has a digit tail and the other one doesn't.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-02-19 12:41:12 +01:00