Commit Graph

1309 Commits

Author SHA1 Message Date
Simon Ruderich
554e8839e3 Makefile: add check target to run shellcheck 2017-10-13 08:52:16 +02:00
Simon Ruderich
14706bcd4d Makefile: add missing .PHONY targets 2017-10-13 08:51:23 +02:00
Simon Ruderich
0b8a53163d kpatch-build: make gcc version check distribution independent
gcc --version varies too much for sane comparisons with vmlinux's
.comment section. Therefore compile a test file and compare its .comment
section.

Also fix gcc 4.8 check which used a lexicographically comparison which
will break for gcc versions >= 10. Instead check for the required
compiler options.

Closes #565.
2017-10-12 17:17:56 +02:00
Simon Ruderich
fa6a6dd821 kpatch-build: further shell code cleanup
- Replace grep | wc -l with grep -c.
- Use find -print0 and xargs -0 to handle non-alphanumeric filenames
  (shouldn't be an issue for us but it's good practice).
- Replace expr with $(( )).

Found by shellcheck.
2017-10-11 09:36:05 +02:00
Simon Ruderich
f796dc6014 kpatch-build: cleanup quoting of $UBUNTU_ABI
The double quotes are confusing as they don't quote $UBUNTU_ABI and thus
have no real effect. As $UBUNTU_ABI is a number simply remove them and
put $UBUNTU_ABI into the surrounding quotes.

Found by shellcheck.
2017-10-10 12:19:29 +02:00
Simon Ruderich
60e5125cb0 kpatch, kpatch-build: further shell code cleanup
- Replace echo $(cmd) with just cmd.
- Replace $@ inside quotes with $*.
- Always die if cd fails.
- Ensure rm -rf "$TEMPDIR"/* never expands to rm -rf /*.

Found by shellcheck.
2017-10-07 10:12:40 +02:00
Simon Ruderich
08fa04bb0d kpatch, kpatch-build, kpatch-gcc: quote all variables
Without proper quoting kpatch fails if the argument contains spaces, the
other scripts might be affected as well.

Not all new quotes are strictly necessary but they were added for
consistency with the existing code and to prevent copy & paste errors in
the future.

There's one conversion which is not straight-forward:

-       grepname=$grepname\\\.o
+       grepname="$grepname\.o"

There are different quoting rules with and without the double quotes.
2017-10-07 10:12:40 +02:00
Josh Poimboeuf
9017bfd32d Merge pull request #743 from joe-lawrence/valgrind_create_klp_module
kpatch-build: create-klp-module: set default arguments.no_klp_arch
2017-10-06 10:02:15 -05:00
Joe Lawrence
edfdaedd48 kpatch-build: create-klp-module: set default arguments.no_klp_arch
Valgrind complains about an uninitialized variable in
create-klp-module.c:

 ==4412== Conditional jump or move depends on uninitialised value(s)
 ==4412==    at 0x402846: main (create-klp-module.c:497)

This warning refers to main()'s struct arguments stack variable,
precisely its .no_klp_arch member.  Initialize the entire structure to
zero to avoid complaint.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2017-10-06 10:51:52 -04:00
Josh Poimboeuf
f4271491af Merge pull request #742 from joe-lawrence/valgrind_elf_update
kpatch-build: clear Elf_Data d_buf buffer on allocation
2017-10-04 11:54:56 -05:00
Joe Lawrence
321bbf9417 kpatch-build: clear Elf_Data d_buf buffer on allocation
Valgrind complains about uninitialized bytes passed to pwrite64(buf)
from kpatch_write_output_elf()'s call to elf_update():

  ==32378== Syscall param pwrite64(buf) points to uninitialised byte(s)
  ==32378==    at 0x5141A03: __pwrite_nocancel (in /usr/lib64/libc-2.23.so)
  ==32378==    by 0x4E46846: ??? (in /usr/lib64/libelf-0.168.so)
  ==32378==    by 0x4E42B88: elf_update (in /usr/lib64/libelf-0.168.so)
  ==32378==    by 0x40C57A: kpatch_write_output_elf (kpatch-elf.c:895)
  ==32378==    by 0x40926F: main (create-diff-object.c:2851)
  ==32378==  Address 0x28d52300 is 0 bytes inside a block of size 56 alloc'd
  ==32378==    at 0x4C2BBAD: malloc (vg_replace_malloc.c:299)
  ==32378==    by 0x40B86A: create_section_pair (kpatch-elf.c:707)
  ==32378==    by 0x406CAE: kpatch_create_patches_sections (create-diff-object.c:2109)
  ==32378==    by 0x4090C5: main (create-diff-object.c:2815)

These are fields which we don't need to populate (like a
funcs[index].new_addr value that will be filled by relocation).  The
easiest way to appease valgrind and not clutter the code is to just
zero-out this entire buffer on allocation.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2017-10-03 16:42:28 -04:00
Josh Poimboeuf
c194d6f44f Merge pull request #741 from joe-lawrence/discarded_sections
kpatch-build: ignore .discard sections
2017-10-03 14:50:09 -05:00
Joe Lawrence
9b2e37baf7 kpatch-build: ignore .discard sections
Fixes #711.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2017-10-03 15:28:52 -04:00
Josh Poimboeuf
7460abd932 Merge pull request #740 from joe-lawrence/testing_updates
Testing updates
2017-09-25 12:30:39 -05:00
Joe Lawrence
eda8357743 testing: simplify combined integration test
Now that kpatch-build can accept multiple patches on the command line,
ditch the combinediff and associated logic in the integration test
script.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2017-09-25 09:17:07 -04:00
Joe Lawrence
2f8170e962 testing: rebase patches for CentOS 7.4 kernel-3.10.0-693.el7
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2017-09-22 17:02:33 -04:00
Joe Lawrence
d580ffd71b Merge pull request #739 from jpoimboe/printk_once
doc: document workaround for printk_once() and friends
2017-09-22 16:09:55 -04:00
Josh Poimboeuf
8bc0b5cf39 doc: document workaround for printk_once() and friends
I couldn't find a good place in the document for this, so I just added
an "Other issues" section at the end.

Fixes #738.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2017-09-22 14:52:09 -05:00
Joe Lawrence
10b37a16a4 Merge pull request #737 from jpoimboe/bundling
kpatch-build: do symbol/section bundling in create-diff-object
2017-09-21 10:32:19 -04:00
Josh Poimboeuf
b72027c44e kpatch-build: do symbol/section bundling in create-diff-object
kpatch-elf.c is used by binaries other than create-diff-object, but
create-diff-object is the only one that cares about "bundling".  Move
the bundling to create-diff-object.

Fixes #700.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2017-09-20 23:57:31 -05:00
Josh Poimboeuf
5888f316e6 create-klp-module: support unbundled symbols
The create_klp_relasecs_and_syms() function assumes that all dest
symbols are bundled, i.e. each symbol is located at offset 0 in its own
section.

However that may not always be the case.  Unbundled symbols can occur,
for example, when combining two .o files which have the same bundled
symbol.  They will be combined into the same section and will no longer
be considered "bundled".

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2017-09-20 23:57:31 -05:00
Josh Poimboeuf
6c8e90e640 create-kpatch-module: support unbundled symbols
The create_dynamic_rela_sections() function assumes that all dest
symbols are bundled, i.e. each symbol is located at offset 0 in its own
section.

However that may not always be the case.  Unbundled symbols can occur,
for example, when combining two .o files which have the same bundled
symbol.  They will be combined into the same section and will no longer
be considered "bundled".

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2017-09-20 23:57:24 -05:00
Josh Poimboeuf
b8d5f479fd Merge pull request #733 from joe-lawrence/multiple_patches
kpatch-build: support multiple .patch files
2017-09-20 17:18:02 -05:00
Joe Lawrence
c0105ea467 kpatch-build: set default module prefix accordingly
Use kpatch-<modname>.ko or livepatch-<modname>.ko depending on the type
of module we're building.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2017-09-20 16:30:00 -04:00
Joe Lawrence
139cfb38d4 kpatch-build: allow list of patches on command line
It can be convenient to build a patchset into a single kpatch module, so
teach kpatch-build to accept a list of .patch files on the commandline.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2017-09-20 16:30:00 -04:00
Joe Lawrence
8dc25d79d1 kpatch-build: let user specify kpatch module name
Add commandline option to specify the kpatch module name, else derive it
from the .patch filename.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2017-09-20 16:30:00 -04:00
Joe Lawrence
9836f994dc Merge pull request #736 from jpoimboe/kpatch-gcc-bug
kpatch: fix kpatch-build matching changed object bug
2017-09-14 09:06:44 -04:00
chen xiaoguang
ec98604f80 kpatch: fix kpatch-build matching changed object bug
When there is a ".." in the source object path, kpatch-gcc can't handle
it correctly.  kpatch-gcc is called for objects which were recompiled
and writes the changed objects to "changed_objs". But if the path of the
input obj is something like:

  arch/x86/kvm/../../../virt/kvm/.tmp_kvm_main.o

then it will fall into the "*.*.o" branch of the kpatch-gcc case
statement and kpatch-build will report "ERROR: no changed objects
found."

Use Joe's suggestion to revert d526805619 ("kpatch-gcc: update
ignorelist to avoid foo/.lib_exports.o files") and instead add a
"*/.lib_exports.o" pattern.

Fixes #735.

[ cleaned up changelog - jpoimboe@redhat.com ]

Cc: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: chen xiaoguang <xiaoggchen@tencent.com>
2017-09-13 21:08:54 -05:00
Joe Lawrence
3a12270abe Merge pull request #734 from jpoimboe/cswtch
create-diff-object: treat "CSWTCH.*" as a special static local
2017-09-11 16:22:49 -04:00
Josh Poimboeuf
dea77c42dc create-diff-object: treat "CSWTCH.*" as a special static local
Normally, kpatch doesn't complain if you remove or rename a function.
This is a feature, because sometimes you have to rename a function in
order to patch it, if for example it doesn't have an fentry call.  In
the object code, it's treated as a new function.  You could get the same
result by copying/pasting the original function and giving the copy a
new name.  But renaming it makes it much easier to review the patch.

In RHEL 7.4, I tried to rename l2cap_config_rsp() to
l2cap_config_rsp_kpatch(), but it failed with:

  ERROR: l2cap_core.o: reference to static local variable CSWTCH.347 in l2cap_config_rsp was removed

This particular error is an easy fix, because the CSWTCH.* symbols are
read-only and are created by GCC.  So they shouldn't be correlated
anyway.

In the future, we will need a more general fix to allow the removal of
functions which use *any* static local variables.  Either automatically,
or by adding a manual annotation.  This can be handled when we rewrite
the static local variable handling in #545.
2017-09-11 14:55:35 -05:00
Joe Lawrence
1719f9ee13 Merge pull request #732 from gktrk/variable-make-jobs
kpatch-build: allow the number of make jobs to be specified using CPUS
2017-09-07 10:46:30 -04:00
Göktürk Yüksek
fc54e0e6c3
kpatch-build: allow the number of make jobs to be specified using CPUS
Instead of always using the maximum number of CPUs available, allow
user to tune the number of make jobs using the command line argument
('-j', '--jobs').
2017-09-06 19:35:37 -04:00
Joe Lawrence
1ad31af49b Merge pull request #730 from jpoimboe/rename-mangled-string-sections
create-diff-object: rename mangled string sections
2017-08-24 15:14:20 -04:00
Josh Poimboeuf
b1095f485e create-diff-object: handle .LCx symbol renames
If an .LCx symbol gets renamed or changes sections, or if its section
gets renamed, kpatch-build will get confused.

They aren't *real* symbols, just string constants.  So no need to
correlate and compare them.

Fixes #714.
Fixes #727.
2017-08-22 10:30:09 -05:00
Joe Lawrence
4a08e612a0 Merge pull request #728 from rudis/cppflags
kpatch-build: respect CPPFLAGS
2017-08-22 09:08:56 -04:00
Simon Ruderich
8ab170d402 kpatch-build: use implicit make rules
This removes duplicate code which is already handled by make internally
and also respects CPPFLAGS.

LDFLAGS are general linker flags, LDLIBS should be used for the
libraries itself. Therefore switch to LDLIBS which is put after the
object files in the command line (which is not true for LDFLAGS).
2017-08-22 03:21:00 +02:00
Josh Poimboeuf
91ed518c60 Merge pull request #731 from joe-lawrence/ubuntu_404
readme: add Ubuntu apt-security 404 note
2017-08-21 08:04:09 -05:00
Joe Lawrence
676b77e936 Merge pull request #729 from rudis/uname
Makefile.inc: replace uname -p with uname -m
2017-08-18 19:56:19 -04:00
Joe Lawrence
a970c9eaef readme: add Ubuntu apt-security 404 note
Fixes #710
2017-08-18 19:38:18 -04:00
Simon Ruderich
78bfbcc4a5 Makefile.inc: replace uname -p with uname -m
uname -p returns "unknown" on many systems effectively breaking the
build. Replace it with uname -m which yields the correct architecture.
2017-08-18 18:12:56 +02:00
Joe Lawrence
e09078b7ea Merge pull request #726 from rudis/master
kpatch-build: check if DEBUG_INFO is enabled
2017-08-17 09:45:36 -04:00
Simon Ruderich
3578e9a6d8 kpatch-build: check DEBUG_KERNEL to guard against missing debug information
Without this option kpatch-build dies with "ERROR: can't find special
struct alt_instr size.".

DEBUG_KERNEL was most likely a typo.
2017-08-17 09:43:09 +02:00
Josh Poimboeuf
4b2f20e3e6 Merge branch 'pr/650' 2017-07-27 15:24:28 -05:00
Josh Poimboeuf
339938c0a9 kpatch-build: clarify ppc64le comments
Clarify some of the comment wording in the new ppc64le code.
2017-07-27 15:23:26 -05:00
Kamalesh Babulal
e3ccff0cab kpatch-build: Support gcc-6 function prologue
With gcc-6 the function prologue is changeg by
moving the toc base resolution func - 0x8 bytes:

        .globl my_func
        .type my_func, @function
        .quad .TOC.-my_func
my_func:
        .reloc ., R_PPC64_ENTRY ; optional
        ld r2,-8(r12)
        add r2,r2,r12
        .localentry my_func, .-my_func

Add support for function prologue, along with gcc-5.

Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2017-07-27 12:56:00 +05:30
Kamalesh Babulal
77f8fd09f1 kpatch-build: ppc64le - Add special section support
Add support for ppc64le specific special sections:

- __ftr_fixup
- __mmu_ftr_fixup
- __fw_ftr_fixup
- __lwsync_fixup

This patch also add #ifdef guards for architecture specific
special sections.

Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2017-07-26 14:41:08 +05:30
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
Kamalesh Babulal
c9e4230d88 kpatch-build: Rename fentry instances to func_profiling
symbol->has_fentry_call is x86 specfic. Rename it to more
generic name, representing the general idea of calling
profiling function at function entry.

This patch converts all instance of symbol->has_fentry_call
to symbol->has_func_profiling and also renames functions:
kpatch_check_fentry_calls() -> kpatch_check_func_profiling_calls()
kpatch_find_fentry_calls() -> kpatch_find_func_profiling_calls()

Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2017-07-26 14:40:33 +05:30
Kamalesh Babulal
afafc239e5 kpatch-build: Create find_special_section_data helper
Move special section data checks to helper function
find_special_section_data(). Special section data will differ
between architectures and all architecture specific and common
checks can be handled better within a helper function.

Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2017-07-26 14:40:31 +05:30
Kamalesh Babulal
665c2222ce kpatch-build: PPC64le - gcc profiling support check
gcc -mprofile-kernel support is required on ppc64le for livepatch
to work. Check should be performed on the gcc, instead of relying
on the verion number.

This check is already performed during the kernel build by:
<linux-sources>/arch/poweprc/tools/gcc-check-mprofile-kernel.sh
Bail out, during the kernel build. Incase the gcc lacks the support
for -mprofile-kernel, instead of duplicating the check in kpatch-buid.

Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2017-07-26 14:40:28 +05:30