Commit Graph

1725 Commits

Author SHA1 Message Date
Josh Poimboeuf
64f07c6c72 test/unit: Fix symtab generation for ppc64le
The ppc64le unit tests are failing because the lookup code is getting
confused by the "[<localentry>: 8]" string in the readelf symbol table
output.

Remove the string so the lookup code can parse it correctly.
kpatch-build already uses the same sed, so they should match.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-07-22 14:48:25 -05:00
Artem Savkov
535e917679
Merge pull request #1000 from sm00th/tag-v0.7.0
Bump version to v0.7.0
2019-07-18 16:34:30 +02:00
Artem Savkov
24d73f0b7b Bump version to v0.7.0
Increment version to v0.7.0 due to changed behavior of kpatch.service and
kpatch load subcommand. Full list of changes:

- Multiple memory leak fixes in kpatch-build
- livepatch-patch-hook compatability fixes for kernels 5.1+
- Making kpatch-build compatible with custom gcc names
- Added rhel-rebased integration tests
- kpatch.service will no longer unload modules on stop
- kpatch load will no longer fail if a module is already loaded and enabled
- kpatch-build will now check for *_fixup section changes on ppc64le and will
  fail on such changes
- Add support for R_X86_64_PLT32
- don't allow jump labels
- ppc64le-specific kpatch-build fixes

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-07-18 12:36:17 +02:00
Josh Poimboeuf
e5535a935c
Merge pull request #997 from jpoimboe/jump_label-warn
create-diff-object: Don't allow jump labels
2019-07-17 11:08:53 -05:00
Josh Poimboeuf
ef98dd7544 test/unit: Bump unit tests to latest
Needed to make the unit tests pass again after adding jump label error
detection.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-07-17 09:03:17 -05:00
Josh Poimboeuf
4f4870dd05 create-diff-object: Don't allow jump labels
Create an error if a patched function uses a jump label.  We need this
until upstream livepatch supports them with a .klp.arch section.

Fixes #946.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-07-17 09:03:17 -05:00
Josh Poimboeuf
a5ac1fe232
Merge pull request #998 from jpoimboe/unit-test-env-override-fix
test/unit: Fix env override for Make 3.x
2019-07-17 08:57:36 -05:00
Josh Poimboeuf
b7edef7360 test/unit: Fix env override for Make 3.x
Make 3.8 doesn't support the "file" function, which is used by the unit
test Makefile to output the contents of a custom env file, if one
exists.  Use shell instead.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-07-16 21:58:41 -05:00
Josh Poimboeuf
9940c1d5a1 test/unit: add test object file for #990
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-07-16 16:16:24 -05:00
Joe Lawrence
06e871ff2c
Merge pull request #995 from jpoimboe/dynamic-debug-fix
create-diff-object: Support dynamic debug on newer kernels
2019-07-16 16:27:55 -04:00
Joe Lawrence
0f818a75f9
Merge pull request #996 from jpoimboe/dont-rebase-submodule
test/unit: Don't automatically rebase submodule
2019-07-16 16:27:42 -04:00
Josh Poimboeuf
20b7ab02c4 test/unit: Don't automatically rebase submodule
"make unit" automatically rebases the submodule, which causes a lot of
surprises.  Instead, just print a warning if it's out of date.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-07-15 18:49:00 -05:00
Josh Poimboeuf
7b367a4ef5 create-diff-object: Support dynamic debug on newer kernels
After Linux commit 47cdd64be483 ("dynamic_debug: refactor
dynamic_pr_debug and friends"), the name of the static local variable
used for dynamic printks is no longer "descriptor".

Make the is_special_static() check broader such that it doesn't care
about the variable name, and just whitelists any variable in the
__verbose section.

Fixes #990.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-07-15 18:20:21 -05:00
Josh Poimboeuf
3b936efa10 test/unit: add test object files for #975
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-07-15 18:11:48 -05:00
Joe Lawrence
061b079c33
Merge pull request #992 from jpoimboe/remove-overlapping-integration-test
Remove convert-global-local integration test
2019-07-08 09:26:35 -04:00
Joe Lawrence
cbf0e88936
Merge pull request #989 from jpoimboe/R_X86_64_PLT32
Add support for R_X86_64_PLT32
2019-07-06 08:51:43 -04:00
Josh Poimboeuf
946f636ca5 Remove convert-global-local integration test
This test is no longer needed.  I had previously converted it to a unit
test and forgot to remove its integration test counterpart.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-07-05 16:22:25 -05:00
Josh Poimboeuf
b5745d7ea6 Add support for R_X86_64_PLT32
Starting with binutils 2.31, the Linux kernel may have R_X86_64_PLT32
relocations. Make sure we support them. This should be as simple as
treating R_X86_64_PLT32 exactly like R_X86_64_PC32 everywhere. For more
details see upstream commit torvalds/linux@b21ebf2.

This also fixes the following issue seen on Fedora 29:

```
$ kpatch-build/kpatch-build -t vmlinux ./test/integration/fedora-27/convert-global-local.patch
Using cache at /home/jpoimboe/.kpatch/src
Testing patch file(s)
Reading special section data
Building original source
Building patched source
Extracting new and modified ELF sections
ERROR: slub.o: 1 function(s) can not be patched
slub.o: function __kmalloc has no fentry/mcount call, unable to patch
/home/jpoimboe/git/kpatch/kpatch-build/create-diff-object: unreconcilable difference
ERROR: 1 error(s) encountered. Check /home/jpoimboe/.kpatch/build.log for more details.
```

Fixes #975.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-07-05 11:45:50 -05:00
Joe Lawrence
2f343f1861
Merge pull request #980 from kamalesh-babulal/fixup
ppc64le: Feature fixup
2019-07-03 09:15:41 -04:00
Kamalesh Babulal
bb444c2168 create-diff-object: Check for *_fixup sections changes
Currently we do not support changes to functions referring to any of the
*_fixup sections on ppc64le. This patch introduces check for such
changes during the patchability check, where we abort building the
patch module.

This patch implements the phase 1 fix of 3 phases discussed at
https://github.com/dynup/kpatch/issues/974:
"
Phase 1 fix:

For kernel versions which don't have livepatch-specific powerpc code
(currently all kernel versions), kpatch-build needs to assert an error
if it detects that one of the following sections refers to a patched
function: __ftr_fixup, __mmu_ftr_fixup, __fw_ftr_fixup.
"

Suggested-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2019-06-25 14:46:55 +05:30
Joe Lawrence
8e3daab9f7
Merge pull request #981 from joe-lawrence/kpatch-service-load-all
kpatch script: don't fail if module already loaded+enabled
2019-06-23 20:36:13 -04:00
Joe Lawrence
1d2dffec7a kpatch script: don't fail if module already loaded+enabled
For "kpatch load" invocations, don't set failing return status if the
kpatch module is already loaded and enabled.  Make note of the existing
livepatch module and then verify that is has completed its transition
before continuing.  This allows the user to more gracefully re-run
"kpatch load" commands to pick up new kpatch modules.

Fixes: #979
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2019-06-20 17:25:28 -04:00
Artem Savkov
d3a50c4156
Merge pull request #978 from sm00th/integration-rhel
test/integration: add patches rebased for recent rhel minor releases
2019-06-19 14:11:33 +02:00
Kamalesh Babulal
09a5686277 create-diff-object: Add support for __spec_barrier_fixup
Add support for __spec_barrier_fixup (barrier nospec fixup) special
section on ppc64le.

Suggested-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2019-06-19 13:24:25 +05:30
Kamalesh Babulal
a2fb8719b7 create-diff-object: Fix lwsync group size
Fix the size of special group __lwsync_fixup on ppc64le.

Suggested-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2019-06-19 13:24:22 +05:30
Artem Savkov
76ebcd2fa4 test/integration: add patches rebased for recent rhel minor releases
This commit contains centos-7 patches rebased and adjusted to work with
recent rhel minors so that integration tests actually pass on those.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-06-14 10:53:57 +02:00
Joe Lawrence
48a388a2c8
Merge pull request #973 from joe-lawrence/ppc64le-symtab-localentry
kpatch-build: remove localentry data from ppc64le symtab
2019-06-13 10:12:49 -04:00
Joe Lawrence
ff78bad23b kpatch-build: remove localentry data from ppc64le symtab
commit f8213c87f64a ("lookup: Fix format string for symtab_read() on
PPC64LE") fixed the symbol table lookup when readelf adds ppc64le
"[<localentry>: 8]" info for functions like so:

  23: 0000000000000008    96 FUNC    LOCAL  DEFAULT [<localentry>: 8]    4 cmdline_proc_show

however, it seems that readelf 2.30-57.el8 displays this in a slightly
different format:

  24493: c000000000587970    96 FUNC    LOCAL  DEFAULT    2 cmdline_proc_show    [<localentry>: 8]

Instead of adding more cases to kpatch-build's lookup.c scanf format,
let's just delete this information from the symtab file with a quick and
dirty sed regex.  This allows us to handle both observed cases (and
perhaps others) while removing the arch-specific scanf formatting in
lookup.c

Fixes: f8213c87f64a ("lookup: Fix format string for symtab_read() on PPC64LE")
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2019-06-12 10:56:06 -04:00
Josh Poimboeuf
b34c6da5bb
Merge pull request #972 from joe-lawrence/kpatch-service-stop
contrib/service: don't unload modules on stop
2019-06-12 08:59:11 -05:00
Joe Lawrence
8909e63c54 contrib/service: don't unload modules on stop
The kpatch.service file shouldn't unload patch modules on service stop
(this is also executed by systemd on reboot).  Patch modules may not be
designed to be safely unloaded and/or may patch kernel routines that
need to continue to run throughout system bring down.

Suggested-by: disaster123
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2019-06-10 16:55:54 -04:00
Joe Lawrence
288568653a
Merge pull request #970 from wwheart/master
kpatch-elf: fix Segmentation fault when d_type not set properly
2019-06-10 11:17:19 -04:00
Joe Lawrence
04977cb736
Merge pull request #971 from kamalesh-babulal/readelf
lookup: Fix format string for symtab_read() on PPC64LE
2019-06-10 11:16:37 -04:00
Kamalesh Babulal
f8213c87f6 lookup: Fix format string for symtab_read() on PPC64LE
commit 767d9669bd13 ("kpatch-build: use readelf instead of eu-readelf")
replaced eu-readelf with readelf for constructing symbol table.  The
format of symbol table entries differs a little on Power when the symbol
is a function with binding type LOCAL.  For example, consider:

23: 0000000000000008    96 FUNC    LOCAL  DEFAULT [<localentry>: 8]    4 cmdline_proc_show

An extra column preceding index of the symbol denoting symbol value to
be local entry point offset of the function is printed, with the
current sscanf format string in lookup::symtab_read the values will
mismatch ending with in accurate lookup table getting constructed. This
patch fixes it by introducing an Power specific format string for
function symbols with bind type LOCAL.

Fixes: 767d9669 ("kpatch-build: use readelf instead of eu-readelf")
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2019-06-04 12:22:02 +05:30
chenzefeng
23c232d3c1 kpatch-elf: fix Segmentation fault when d_type not set properly
kpatch-elf::create_section_pair would create new rela section, and the
relasec->data->d_type is not set, which is a random value, and it will
use in kpatch-elf::kpatch_write_output_elf
	data->d_type = sec->data->d_type;
which would cause Segmentation fault in kpatch_write_output_elf::elf_update.

Program received signal SIGSEGV, Segmentation fault.
(gdb) bt
0  0x00007ffff7bcd8d2 in __elf64_updatefile at elf64_updatefile.c
1  0x00007ffff7bc9bed in write_file at elf_update.c
2  0x00007ffff7bc9f16 in elf_update at elf_update.c
3  0x000000000040ca3d in kpatch_write_output_elf at kpatch-elf.c
4  0x0000000000409a92 in main at create-diff-object.c

Signed-off-by: chenzefeng <chenzefeng2@huawei.com>
2019-06-03 11:29:59 +08:00
Joe Lawrence
0cdc2a3757
Merge pull request #965 from joe-lawrence/altinstr_replacement
kpatch-build: ensure that .altinstr_replacement section is included
2019-05-31 13:51:27 -04:00
Joe Lawrence
ceac47c0e0
Merge pull request #969 from wwheart/master
test: use readelf instead of eu-readelf
2019-05-31 13:50:23 -04:00
chenzefeng
d91b416b00 test: use readelf instead of eu-readelf
readelf is more standard, using readelf insteaded

test/difftree.sh: the symbol name may be with "FILE", which may be
get a incorrect count, here add "awk".

test/unit/Makefile.include: use "readelf -s --wide" instead of
"eu-readelf -s".

Signed-off-by: chenzefeng <chenzefeng2@huawei.com>
2019-05-30 17:45:44 +08:00
Joe Lawrence
5d8b069e12
Merge pull request #968 from wwheart/master
kpatch-build: use readelf instead of eu-readelf
2019-05-29 10:08:54 -04:00
chenzefeng
767d9669bd kpatch-build: use readelf instead of eu-readelf
readelf is more standard, using readelf insteaded we should solve there
issues:

First, using "readelf -s", the symbol name would truncated by 25 chars,
to solve this issue, add option "--wide".

Second, the size may be mixed of decimal and hex, we get the size by "%s",
and use strtoul(size, NULL, 0) to convert the size.

Third, the symbol type is SHN_UNDE, the Ndx display "UND", so changed to
compare with "UND".

Signed-off-by: chenzefeng <chenzefeng2@huawei.com>
2019-05-28 20:36:45 +08:00
Joe Lawrence
13b0014671 kpatch-build: ensure that .altinstr_replacement section is included
.altinstr_replacement section may have relocation symbols which need to
be included, therefore we should call kpatch_include_symbol() to ensure
that its section is included as well.

The special section processing should also occur before
kpatch_print_changes() to provide accurate logging info.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2019-05-17 10:31:04 -04:00
Josh Poimboeuf
7aa371aa37
Merge pull request #962 from sm00th/fixup-section-fix
Update fixup-section patches
2019-05-15 09:41:02 -05:00
Joe Lawrence
92b9c7d73b
Merge pull request #961 from kamalesh-babulal/shell_check
kpatch, kpatch-build: Use -n instead of ! -z
2019-05-15 10:23:38 -04:00
Joe Lawrence
d40ecd6835
Merge pull request #960 from wwheart/master
kpatch-elf: fix the unexpected elf class
2019-05-15 10:22:41 -04:00
Joe Lawrence
66dfd9ab5b
Merge pull request #958 from kirawrath/master
Making kpatch-build compatible with custom gcc names
2019-05-15 10:21:38 -04:00
Artem Savkov
5dfe17cb02 Update fixup-section patches
These patches previously would try to dereference a userspace pointer
directly which can cause issue on some systems. Since the aim of these
patches is to check fixup section changes we can don't need to do any
meaningful changes to the function, so change the patches to just add
asm("nop") instead.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-05-15 10:28:45 +02:00
chenzefeng
3bfc85732d kpatch-elf: fix the unexpected elf classes
kpatch-elf::kpatch_write_output_elf will call the gelf_getclass()
to acquire the output elf's class. But the input parameter kelf->elf
is NULL, the gelf_getclass(kelf->elf) will return ELFCLASSNONE, not
the value we expect ELFCLASS32 or ELFCLASS64.

the gelf_getclass function code:
int
gelf_getclass (Elf *elf)
{
  return elf == NULL || elf->kind != ELF_K_ELF ? ELFCLASSNONE : elf->class;
}

the gelf_newehdr fuction code:
void *
gelf_newehdr (Elf *elf, int class)
{
  return (class == ELFCLASS32
          ? (void *) INTUSE(elf32_newehdr) (elf)
          : (void *) INTUSE(elf64_newehdr) (elf));
}

Luckily, when we create a patch for x86_64 or powerpc64, if we pass the
ELFCLASSNONE for the function gelf_newehdr, it will return elf64_newehdr,
so don't cause the fault. But it's better to use the gelf_getclass(elf)
instead of gelf_getclass(kelf->elf).

Signed-off-by: chenzefeng <chenzefeng2@huawei.com>
2019-05-15 14:10:47 +08:00
Kamalesh Babulal
13e03de0d4 kpatch, kpatch-build: Use -n instead of ! -z
make check using shellcheck version 0.6.0 suggests following
improvements:
In kpatch/kpatch line 160:
        if [[ ! -z "$checksum" ]] && [[ -e "$SYSFS/${modname}/checksum"]] ; then
              ^-- SC2236: Use -n instead of ! -z.

In kpatch-build/kpatch-build line 953:
[[ ! -z "$UNDEFINED" ]] && die "Undefined symbols: $UNDEFINED"
   ^-- SC2236: Use -n instead of ! -z.

'-n' and '! -z' are used interchangeably across the scripts, let's use
'-n' consistently to check a non-empty string instead of using negation.

Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2019-05-12 21:26:45 +05:30
Joe Lawrence
bfe1c74d4f
Merge pull request #957 from wwheart/master
create-diff-object: remove unneeded condition
2019-05-10 17:06:54 -04:00
Joe Lawrence
d304740269
Merge pull request #959 from kirawrath/systemctl_check
Testing systemctl existence before executing it
2019-05-10 17:04:30 -04:00
Bruno Loreto
d33e1149d1 Testing systemctl existence before executing it
Since commit c9614c4298 kpatch has support for upstart systems,
which means we should test the existence of `systemctl` before executing
it.

The command `command` is POSIX compliant, and should be widely
available.

Signed-of-by: Bruno Loreto <loretob@amazon.com>
2019-05-10 15:02:56 +02:00