Commit Graph

24 Commits

Author SHA1 Message Date
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
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
Joe Lawrence
9ae97c5d29 livepatch-patch-hook: skip klp_(un)register_patch() for v5.1+ kernels
In v5.1, upstream kernel commit 958ef1e39d24 ("livepatch: Simplify API
by removing registration step") removed klp_(un)register_patch().  We
only need to call klp_enable_patch() now.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2019-05-01 09:35:32 -04:00
chenzefeng
8a319e0133 livepatch-patch-hook: fix memleak in the function patch_exit
reason: after the function klp_unregister_patch, the lpatch must
	be freed, otherwise, it would cause memory leak.

Signed-off-by: chenzefeng <chenzefeng2@huawei.com>
2019-04-30 20:48:16 +08:00
Balbir singh
8ef31a0e92 trivial: __powerpc__ should be __powerpc64__
Since the codeset supports just the 64 bit variant, lets move
to __powerpc64__ and use it. I checked the ABI doc as well
and the kernel/gcc.

Signed-off-by: Balbir singh <bsingharora@gmail.com>
2018-06-07 17:33:06 +10:00
Josh Poimboeuf
d04f5723bc kpatch-build: RHEL kernel-alt support
Deal with a few RHEL kernel-alt quirks for ppc64le:

- The RPM and spec names are "kernel-alt".

- 7.6 ALT is based on 4.14 but it doesn't have the 'immediate' flag.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-06-01 22:15:52 -05:00
Artem Savkov
355927287d livepatch-patch-hook: fix non-rhel builds
Preprocessor doesn't stop unwinding macroses in #if clauses if one of
the conditions is false resulting in the following error when trying to
build on non-rhel system:

patch/livepatch-patch-hook.c:53:48: error: missing binary operator before token "("
       RHEL_RELEASE_CODE <= RHEL_RELEASE_VERSION(7, 5))

Fix by using 2 levels of #ifs instead of &&. The same way HAVE_CALLBACKS
does.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-05-31 12:28:03 +02:00
Josh Poimboeuf
a3ee369448 livepatch-patch-hook: add RHEL immediate check
The 'immediate' flag removal is going to be backported to RHEL 7.
Adjust the check accordingly.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-05-29 17:54:59 -05:00
Mike Rapoport
dd1bfbecd5 livepatch-patch-hook: make callbacks addition depend on the kernel version
Since commit 926e4e0c7d ("kmod: add support
for in-kernel livepatch hooks") livepatch-patch-hook.c unconditionally
creates callbacks. This causes build error for kernels older than 4.15:

make -C /home/rppt/git/linux M=/home/rppt/.kpatch/tmp/patch livepatch-proc-vmalloc-live.ko
make[1]: Entering directory '/home/rppt/git/linux'
  CC [M]  /home/rppt/.kpatch/tmp/patch/patch-hook.o
In file included from /home/rppt/.kpatch/tmp/patch/patch-hook.c:21:0:
/home/rppt/.kpatch/tmp/patch/livepatch-patch-hook.c:82:23: error: field ‘callbacks’ has incomplete type
  struct klp_callbacks callbacks;
                       ^
/home/rppt/.kpatch/tmp/patch/livepatch-patch-hook.c: In function ‘patch_init’:
/home/rppt/.kpatch/tmp/patch/livepatch-patch-hook.c:395:10: error: ‘struct klp_object’ has no member named ‘callbacks’
   lobject->callbacks = object->callbacks;
          ^
scripts/Makefile.build:302: recipe for target '/home/rppt/.kpatch/tmp/patch/patch-hook.o' failed
make[2]: *** [/home/rppt/.kpatch/tmp/patch/patch-hook.o] Error 1
Makefile:1687: recipe for target 'livepatch-proc-vmalloc-live.ko' failed
make[1]: *** [livepatch-proc-vmalloc-live.ko] Error 2
make[1]: Leaving directory '/home/rppt/git/linux'
Makefile:20: recipe for target 'livepatch-proc-vmalloc-live.ko' failed
make: *** [livepatch-proc-vmalloc-live.ko] Error 2

Introduce HAVE_CALLBACKS to allow conditional compilation of the callbacks
addition.

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
2018-04-16 20:06:38 +03:00
Joe Lawrence
55650e16af
Merge pull request #780 from joe-lawrence/livepatch-hooks
kmod: add support for in-kernel livepatch hooks
2018-04-02 14:49:07 -04:00
Joe Lawrence
4d5febd4a8 sparse: quiet latest trivial complaints
Fixes sparse warnings:

  kmod/core/core.c:142:20: warning: symbol 'trace' was not declared. Should it be static?

  livepatch-patch-hook.c:73:18: warning: symbol 'lpatch' was not declared. Should it be static?

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2018-03-23 16:20:45 -04:00
Joe Lawrence
926e4e0c7d kmod: add support for in-kernel livepatch hooks
Upstream 4.15 kernels provide support for pre and post (un)patch
callbacks, inspired by the kpatch load hooks.  Add support for them
in the livepatch-patch-hook.

At the same time, convert the kpatch hooks to use the same API.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2018-03-23 10:32:14 -04:00
Kamalesh Babulal
d651cd994c livepatch-patch-hook: Add upper bound kernel version for immediate flag
Effective Kernel v4.16, the immediate flag is removed by upstream
kernel commit d0807da78e11 ("livepatch: Remove immediate feature").
Add an upper bound kernel version check for inclusion of the
immediate flag.

Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2018-03-17 15:00:55 +05:30
Josh Poimboeuf
2e85ec5672 kpatch-build: add support for CONFIG_LIVEPATCH on RHEL
Fix the version checks for when we enable CONFIG_LIVEPATCH on RHEL.  It
will be based on the latest upstream code.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2017-10-18 06:33:27 -05:00
Josh Poimboeuf
d44a4b9df5 livepatch-patch-hook: clean up version checks
Clean up the kernel version checks a little bit.  Use 'HAVE_*' naming
everywhere for consistency.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2017-10-18 06:32:53 -05:00
Kamalesh Babulal
c14e6e9118 kpatch-build: Add PPC64le livepatch support
This patch adds support for livepatch hook based module
creation for PPC64le. It introduces PPC64le architecture
bits:
- Add relocation type of R_PPC64_ADDR64 while parsing powerpc ELF.
- Introduce .toc sections mainpulation.
- Skip kpatch specific details for livepatch hook.

Also remove the definition of rela_insn() for powerpc. The only
call site is been guarded by #ifdef x86.

Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2017-07-26 14:40:37 +05:30
Jessica Yu
355996e366 livepatch-patch-hook: ensure compatibility with kernels < 4.7 and >= 4.7
Use dynrelas when kernel version is < 4.7 and klp relas otherwise.
2017-01-23 12:43:39 -08:00
Joe Lawrence
e7937196b7 kmod: let kernel apply TAINT_LIVEPATCH
Upstream commit 2992ef29ae01 ("livepatch/module: make TAINT_LIVEPATCH
module-specific") v4.9+ modified the kernel to add the TAINT_LIVEPATCH
flag on module load.  To support this feature, add the "livepatch"
module info in the {k,live}patch modules and drop the add_taint() in the
core module.
2017-01-12 16:05:53 -05:00
Chris J Arges
eb55adc52d use livepatch 4.5 features in Ubuntu Xenial kernel
Some features were backported into the 4.4 kernel which change the fields
of the livepatch structures. Ensure we can work with either v4.5 or greater,
or Ubuntu 4.4.0-7 or greater.
2016-12-16 07:05:53 -06:00
Chris J Arges
b64ab2b5e4 livepatch-patch-hook: add support for livepatch sympos
Support patching objects that have duplicated function names. This feature was
introduced upstream in Linux v4.5.

This patch appends the symbol position to the symbol structure when
lookup_local_symbol is called. This pos variable is then used when creating the
funcs and dynrelas sections. Finally, incorporate sympos into the livepatch
patch hook only if the kernel version is greater than v4.5. In other cases the
older format is used.

Fixes: #493

Signed-off-by: Chris J Arges <chris.j.arges@canonical.com>
2016-02-16 10:31:44 -06:00
Jessica Yu
9e223369ea livepatch-patch-hook: check for object->name before calling strcmp
Fixes issue #494. A null pointer dereference can result with patch
modules for multiple objects since the "vmlinux" patch object's "name"
field is null. strcmp therefore crashes trying to compare object->name
if the current object is vmlinux and the supplied "name" argument is
not. Check that object->name is not null before invoking strcmp.
2015-10-14 13:01:42 -07:00
Seth Jennings
0325e43d93 add naming convention documentation and fixes
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2015-01-22 11:39:34 -06:00
Seth Jennings
923d36ffbc review fixups
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2015-01-22 10:35:11 -06:00
Seth Jennings
f1903de1eb add livepatch API support
Adds a new patch module scaffold for use when building against a kernel
with CONFIG_LIVE_PATCHING=y.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2015-01-21 18:28:31 -06:00