Commit Graph

1794 Commits

Author SHA1 Message Date
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
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
Joe Lawrence 30a7dd677b
Merge pull request #1032 from sm00th/lphook
kmod/patch: check for RHEL8 when setting HAVE_SIMPLE_ENABLE
2019-08-22 15:44:25 -04:00
Joe Lawrence bcdffc1200
Merge pull request #1033 from sm00th/integration_prs
test/integration: add an ability to check specific repo/commit
2019-08-22 15:44:02 -04:00
Joe Lawrence e4525ce311 kpatch-build: sanity check patched filenames
Run the input patch(es) through lsdiff and then verify that no obviously
unsupported files are directly modified (e.g. assembly .S files).

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2019-08-22 11:44:02 -04:00
Artem Savkov f6fd787468 test/integration: add an ability to check specific repo/commit
Add an ability to run vagrant integration tests on specified
repos/commits.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-08-22 15:31:11 +02:00
Artem Savkov 36120b9b08 kmod/patch: check for RHEL8 when setting HAVE_SIMPLE_ENABLE
Make sure we don't set HAVE_SIMPLE_ENABLE on rhel8 before rhel8.2

Fixes: b913b4b ("livepatch-patch-hook: skip klp_(un)register_patch() for RHEL-7.8+ kernels")
Fixes: #1031

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-08-22 15:17:58 +02:00
Josh Poimboeuf 35f9361474
Merge pull request #1028 from jpoimboe/core-file-msg
kpatch-build: update core file error message
2019-08-21 13:05:18 -05:00
Artem Savkov 2a29bc7dea
Merge pull request #1029 from sm00th/tag_0.8.0
Bump version to v0.8.0
2019-08-21 16:11:12 +02:00
Artem Savkov 68de3903dd Bump version to v0.8.0
Increment version to v0.8.0 due to manual signaling logic being removed
from kpatch util. Full list of changes:

- kpatch.ko atomic replace fixes
- Fixes for potential problems found by covscan
- Remove manual signaling logic from kpatch utility
- Don't strip callback symbols
- Allow dynamic debug static keys

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-08-21 13:12:47 +02:00
Josh Poimboeuf e187de3fe4 kpatch-build: update core file error message
Recent distros don't require you to set 'ulimit -c unlimited'.  Instead
they place core files in a distro-specific location.  Update the SIGSEGV
error message accordingly.

Fixes: #1025

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-08-20 16:18:59 -05:00
Joe Lawrence 6f5edcd573
Merge pull request #1024 from joe-lawrence/remove-signal
kpatch: remove manual signaling logic
2019-08-19 10:50:55 -04:00
Joe Lawrence a23c82d9e6
Merge pull request #1026 from jpoimboe/ppc-replace-sections-syms-callbacks-fix
create-diff-object: Don't strip callback symbols
2019-08-19 10:50:36 -04:00
Joe Lawrence 2e9cfa2fb3
Merge pull request #1027 from jpoimboe/ignore-descriptor-static-key
create-diff-object: allow dynamic debug static keys
2019-08-19 10:50:13 -04:00
Josh Poimboeuf c9fa73bb9a
Merge pull request #986 from euspectre/old-replace-fix
Patch replacement fixes for the old KPatch core
2019-08-15 16:05:13 -05:00
Josh Poimboeuf 2975775768 create-diff-object: allow dynamic debug static keys
While static keys (jump labels) are currently broken in livepatch, a
broken dynamic debug static key is harmless since it just disables
dynamically enabled debug printks in the patched code.

Fixes: #1021

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-08-15 16:01:55 -05:00
Josh Poimboeuf b13aca7cde create-diff-object: Don't strip callback symbols
We saw the following panic on ppc64le when loading the macro-callbacks
integration test:

  livepatch: enabling patch 'kpatch_macro_callbacks'
  Oops: Exception in kernel mode, sig: 4 [#1]
  LE SMP NR_CPUS=2048 NUMA pSeries
  Modules linked in: kpatch_macro_callbacks(OEK+) rpcsec_gss_krb5 auth_rpcgss nfsv4 dns_resolver nfs lockd grace fscache sunrpc sg pseries_rng xts vmx_crypto xfs libcrc32c sd_mod ibmvscsi scsi_transport_srp ibmveth dm_mirror dm_region_hash dm_log dm_mod [last unloaded: kpatch_gcc_static_local_var_6]
  CPU: 2 PID: 17445 Comm: insmod Kdump: loaded Tainted: G           OE K  --------- -  - 4.18.0-128.el8.ppc64le #1
  NIP:  d00000000bb708e0 LR: c0000000001fd610 CTR: d00000000bb708e0
  REGS: c00000040e98f640 TRAP: 0700   Tainted: G           OE K  --------- -  -  (4.18.0-128.el8.ppc64le)
  MSR:  800000000288b033 <SF,VEC,VSX,EE,FP,ME,IR,DR,RI,LE>  CR: 28008228  XER: 20040003
  CFAR: c0000000001fd60c IRQMASK: 0
  GPR00: c0000000001fd5c0 c00000040e98f8c0 c000000001662a00 c000000733525400
  GPR04: 0000000000000800 0000000000000800 c0000000015e2c00 c0000007335254a8
  GPR08: 0000000000000001 d00000000bb708e0 c0000007eeb68400 0000000000000000
  GPR12: d00000000bb708e0 c000000007fad600 0000000000000001 aaaaaaaaaaaaaaab
  GPR16: 000000000000ff20 000000000000fff1 000000000000fff2 d00000000bb90000
  GPR20: 00000000000000a9 c00000040e98fc00 c000000000d8a728 c00000040e98fc00
  GPR24: d00000000bb73f88 00000000006080c0 d00000000bb73a38 c000000733525400
  GPR28: 0000000000000001 c000000733525400 ffffffffffffffed c0000007eeb60900
  NIP [d00000000bb708e0] callback_info.isra.0+0x7c/0x66c [kpatch_macro_callbacks]
  LR [c0000000001fd610] __klp_enable_patch+0x130/0x230
  Call Trace:
  [c00000040e98f8c0] [c0000000001fd5c0] __klp_enable_patch+0xe0/0x230 (unreliable)
  [c00000040e98f940] [c0000000001fd7d8] klp_enable_patch+0xc8/0x100
  [c00000040e98f980] [d00000000bb7079c] patch_init+0x460/0x4cc [kpatch_macro_callbacks]
  [c00000040e98fa20] [c000000000010108] do_one_initcall+0x58/0x248
  [c00000040e98fae0] [c00000000023b860] do_init_module+0x80/0x330
  [c00000040e98fb70] [c0000000002416a4] load_module+0x3994/0x3d00
  [c00000040e98fd30] [c000000000241cf4] sys_finit_module+0xc4/0x130
  [c00000040e98fe30] [c00000000000b388] system_call+0x5c/0x70
  Instruction dump:
  7cea482a 48000235 e8410018 48000014 3c620000 e8638160 48000221 e8410018
  38210060 e8010010 7c0803a6 4e800020 <0000ae18> 00000000 3c4c0001 3842ae18

The problem was introduced by a recent fix:

  e8f7f2dfe8 ("create-diff-object/ppc64le: Fix replace_sections_syms() for bundled symbols")

We didn't notice the fact that there's a hack in
kpatch_include_callback_elements() which reverts the work of
kpatch_replace_sections_syms() for callback function symbols.

The problem is that that revert is only partial, causing the callback
pointers to point to the .TOC data which is located 8 bytes before the
start of the function code.  This happens because
kpatch_include_callback_elements() makes the same assumption that
kpatch_replace_sections_syms() had previously made: that bundled symbols
are always located at the start of their corresponding sections.

kpatch_include_callback_elements() mysteriously strips references to the
callback function symbols, replacing them with section symbols.  In this
case it replaced a 'pre_patch_callback' function reference with a
'.text.unlikely.pre_patch_callback' section reference.  But it didn't
adjust the rela->addend accordingly.

Joe discovered the reasoning for why kpatch_include_callback_elements()
removes function symbol references in the commit log for 7dfad2fb76
("fix dynrela corruption in load/unload hooks"):

  In the case of the hook functions, we strip the FUNC symbol to prevent
  it from being added to the kpatch.funcs section as a patched function.

But that justification doesn't really make sense, at least not with the
current code.  Callbacks aren't added to .kpatch.funcs anyway.  They're
classifed as NEW.  Only CHANGED functions are added to .kpatch.funcs.

So remove that hack, fixing this bug in the process.

This does have a side effect of showing the callback functions as new
functions, because their symbols are now included.

Before:

  aio.o: found callback: post_unpatch_callback
  aio.o: found callback: pre_patch_callback
  aio.o: found callback: pre_unpatch_callback
  aio.o: new function: callback_info.isra.0

After:

  aio.o: found callback: post_unpatch_callback
  aio.o: found callback: pre_patch_callback
  aio.o: found callback: pre_unpatch_callback
  aio.o: new function: callback_info.isra.0
  aio.o: new function: pre_patch_callback
  aio.o: new function: post_patch_callback
  aio.o: new function: pre_unpatch_callback
  aio.o: new function: post_unpatch_callback

But anyway they _are_ new functions, so the new output seems more
correct to me.

Fixes: e8f7f2dfe8 ("create-diff-object/ppc64le: Fix replace_sections_syms() for bundled symbols")
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-08-15 15:08:31 -05:00
Josh Poimboeuf 14cc8a013d create-diff-object: add is_callback_section() helper
This simplifies the code a bit.  Also this helper will be needed for
subsequent patches.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-08-15 14:08:29 -05:00
Josh Poimboeuf 5665d06853 create-diff-object: fix kpatch_replace_sections_syms() comment
The existing comment is wrong.  It confusingly conflates the function's
offset, which is 8 bytes from the beginning of the section, with the
function's localentry offset which is 8 bytes from the beginning of the
function.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-08-15 14:02:09 -05:00
Joe Lawrence 3335abcc66 kpatch: remove manual signaling logic
Ever since upstream v5.1 (specifically commits 0b3d52790e1c ("livepatch:
Remove signal sysfs attribute") and cba82dea3061 ("livepatch: Send a
fake signal periodically") the kpatch utility script's
signal_stalled_processes() functionality has been redundant.

Remove code from the script that manually signals stalled processes.  If
the sysfs signal interface is still present, use that, otherwise let
(newer) kernels handle the fake signals on their own.

Fixes: #1022

Signed-off-by: Joe Lawrence joe.lawrence@redhat.com
2019-08-15 12:06:40 -04:00
Josh Poimboeuf 2fede60e8f
Merge pull request #1019 from sm00th/integration_7_7
test/integration: add  rhel-7.7 rebased patches
2019-08-14 10:40:24 -05:00
Josh Poimboeuf fb2fc0fcd6
Merge pull request #1023 from joe-lawrence/remove-testmod
test: remove testmod/
2019-08-14 10:39:21 -05:00
Josh Poimboeuf 578e3c7e6f
Merge pull request #1020 from joe-lawrence/rhel-7.8-API
livepatch-patch-hook: skip klp_(un)register_patch() for RHEL-7.8+ ker…
2019-08-14 10:38:55 -05:00
Joe Lawrence b3ea0171ff test: remove testmod/
Remove test/testmod/ as it has been unmaintained for years now.

Fixes: issue #1017

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2019-08-13 11:50:40 -04:00
Joe Lawrence b913b4bae0 livepatch-patch-hook: skip klp_(un)register_patch() for RHEL-7.8+ kernels
RHEL-7.8 backported upstream kernel commit 958ef1e39d24 ("livepatch:
Simplify API by removing registration step"), so add it to the kernels
using the simple registration API.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2019-08-12 17:03:07 -04:00
Artem Savkov 0e0cee369a test/integration: add rhel-7.7 rebased patches
Added integration-test patches rebased against rhel-7.7 GA kernel. No
conflicts, some fuzz.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-08-12 14:36:16 +02:00
Artem Savkov 1fe8fe66c2
Merge pull request #1018 from sm00th/co7_ccache
tests/integration: fix dependency ccache on centos 7
2019-08-09 17:47:41 +02:00
Artem Savkov e2fdd33d4f tests/integration: fix dependency ccache on centos 7
Standard centos7 repos don't contain ccache so we have to install it
from epel just like we do on rhel7.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-08-09 16:31:19 +02:00
Joe Lawrence c4fafedf3b
Merge pull request #1014 from sm00th/covscan-fixes
Covscan fixes
2019-08-06 09:59:21 -04:00
Artem Savkov f1263a4292 create-diff-object: section size check in rela_insn()
Without this check we are risking returning uninitialized insn var.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-08-05 12:11:43 +02:00
Artem Savkov 7129bb48c9 create-diff-object: free hint variable on failure
Make sure we are freeing previously allocated "hint" variable on error
before exiting.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-08-05 12:11:43 +02:00
Artem Savkov 054915e957 create-diff-object: remove unneeded var initialization in kpatch_regenerate_special_section()
group_size variable is assigned right after we enter for loop without
ever being read so there is no need to initialize it to 0 beforehand.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-08-05 12:11:43 +02:00
Artem Savkov 1722f14221 create-diff-object: make sure sym->sec is not null in kpatch_replace_sections_syms()
Check that sym->sec is not null before dereferencing it.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-08-05 12:11:29 +02:00
Artem Savkov 9049abd0f5 create-diff-object: remove unused variables
"funcs" in kpatch_create_patches_sections() and "entries" in
kpatch_create_kpatch_arch_section() were only used by sizeof, replaced
those with corresponding types.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-08-05 12:10:47 +02:00
Artem Savkov 9c1aa2d492 lookup: exit on error in make_modname()
Actually exit on strdup error instead of just printing a warning message
in make_modname().

Found by covscan, see issue #984 for full log.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-08-05 12:10:47 +02:00
Artem Savkov 79728dddaf kpatch-elf: add a couple mission section checks
There were 2 insances where return value of find_section_by_name wasn't
checked before dereference.

Found by covscan, see issue #984 for full log.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-08-05 12:10:47 +02:00
Artem Savkov 04c0831705 create-kpatch-module: check symtab in main()
Make sure symtab section was found before dereferencing it.

Found by covscan, see issue #984 for full log.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-08-05 12:10:47 +02:00
Artem Savkov 5cd9833b0d create-klp-module: check symtab in main()
Make sure symtab section was found before dereferencing it.

Found by covscan, see issue #984 for full log.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-08-05 12:10:47 +02:00
Artem Savkov bba18e3612 create-klp-module: remove unused variable in create_klp_arch_sections()
Only user of "entries" variable was sizeof and the value was never
actually used. Use struct name directly instead.

Found by covscan, see issue #984 for full log.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-08-05 12:10:47 +02:00
Artem Savkov 38efb307c2 create-diff-object: check symtab in main()
Make sure symtab section was found before dereferencing it.

Found by covscan, see issue #984 for full log.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-08-05 12:10:47 +02:00
Artem Savkov dba95bae62 create-diff-object: check mallor retval in kpatch_create_mcount_sections()
newdata variable is allocated through malloc call and requires a NULL
check.

Found by covscan, see issue #984 for full log.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-08-05 12:10:47 +02:00
Artem Savkov deb7719280 create-diff-object: check ORC_STRUCT_SIZE correctness in kpatch_regenerate_orc_sections()
Since ORC_STRUCT_SIZE is used for division in
kpatch_regenerate_orc_sections() we need to make sure that it is
properly set.

Found by covscan, see issue #984 for full log.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-08-05 12:10:47 +02:00
Artem Savkov f0d071def7 create-diff-object: check fixupsec in fixup_group_size()
Make sure fixup section was found before dereferencing it.

Found by covscan, see issue #984 for full log.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-08-05 12:10:47 +02:00
Artem Savkov f367438b19 create-diff-object: null checks in rela_equal()
Make sure rela_toc(1|2) are not null before dereferencing them in
rela_equal().

Found by covscan, see issue #984 for full log.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-08-05 12:10:47 +02:00
Joe Lawrence d60579e8d4
Merge pull request #1013 from steils/dwarf-gz
kpatch-build: check if gcc supports -gz=none
2019-07-31 14:02:50 -04:00
Stefan Strogin 14b094484e
kpatch-build: check if gcc supports -gz=none
The flag -gz[=type] was added in GCC 5. To support older GCC versions
check if the flag is supported before adding it to KCFLAGS.

Fixes: #1012

Signed-off-by: Stefan Strogin <steils@gentoo.org>
2019-07-31 11:16:16 +03:00
Joe Lawrence ea0e6f0144
Merge pull request #1011 from steils/dwarf-gz
create-diff-object: disable DWARF compression explicitly
2019-07-30 09:28:11 -04:00
Stefan Strogin fe6e3f51bf
create-diff-object: disable DWARF compression explicitly
On some systems the linker produces compressed debug sections by
default. It is not supported by create-diff-object for now.

Fixes: #877

Signed-off-by: Stefan Strogin <steils@gentoo.org>
2019-07-29 13:20:20 +03:00