Commit Graph

1265 Commits

Author SHA1 Message Date
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
Kamalesh Babulal dde4e95fa4 kpatch-build: Build with insn support only on x86_64
kpatch-build/insn provides x86 instruction analysis, disable
the analyzer support when build on powerpc.

Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2017-07-26 14:40:25 +05:30
Josh Poimboeuf a0adebf861 Makefile: Add a rule to build core module on x86_64 only
core module is currently supported on x86_64. Trying to
build it on powerpc, triggers build failure:

make[3]: Entering directory '/root/kernel/linux'
  CC [M]  /root/upstream/kpatch/kmod/core/core.o
/root/upstream/kpatch/kmod/core/core.c:48:28: fatal error: asm/stacktrace.h: No such file or directory
 #include <asm/stacktrace.h>
                            ^
compilation terminated.
scripts/Makefile.build:294: recipe for target '/root/upstream/kpatch/kmod/core/core.o' failed
make[4]: *** [/root/upstream/kpatch/kmod/core/core.o] Error 1

Add a Makefile rule to build it, only on x86.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2017-07-26 14:40:21 +05:30
Joe Lawrence 135dcdb3d7 Merge pull request #723 from jpoimboe/kpatch-build-error-handling
kpatch-build: fix errors messages for missing files/dirs
2017-07-18 10:46:23 -04:00
Josh Poimboeuf 9a123ecc02 kpatch-build: fix errors messages for missing files/dirs
If you give kpatch-build a bad argument for the '-s' option, it shows
the following error:

  $ kpatch-build/kpatch-build -s foo
  ERROR: source dir  not found.

The supplied 'foo' argument isn't printed as intended.

Also fix some other options which have a similar issue.
2017-07-17 22:59:37 -05:00
Joe Lawrence b39865a64d Merge pull request #722 from jpoimboe/fix-dynrela-writes
kmod/core: fix dynrela writes for kernel 4.11+
2017-07-17 13:59:35 -04:00
Josh Poimboeuf a4dec316f3 kmod/core: fix dynrela writes for kernel 4.11+
Starting with kernel 4.11, CONFIG_DEBUG_SET_MODULE_RONX has been
replaced with CONFIG_ARCH_HAS_SET_MEMORY.  This fixes the following
error:

  kpatch: write to 0xffffffffc0d7650e failed for symbol copy_mnt_ns

Fixes #721.
2017-07-17 09:48:24 -05:00
Joe Lawrence 4960f09fe2 Merge pull request #719 from aliceinwire/small_fix
fix style
2017-07-13 15:42:13 -04:00
Alice Ferrazzi 9d6e1ef535 fix style 2017-07-13 19:01:14 +00:00
Joe Lawrence d760e1228c Merge pull request #718 from aliceinwire/output_argument
added output argument for choose where to save the livepatch file
2017-07-13 14:52:59 -04:00
Alice Ferrazzi d1d94a5e5a added output argument for choose where to save the livepatch file 2017-07-13 18:15:02 +00:00
Joe Lawrence b59d617de4 Merge pull request #717 from jpoimboe/local-syms-any-order
lookup: allow local symbols to be in any order
2017-07-07 16:28:41 -04:00
Josh Poimboeuf c8c474ca0e lookup: allow local symbols to be in any order
With #650, we found that using -ffunction-sections and -fdata-sections
sometimes causes GCC to output the local symbols in a different order in
the symbol table.  So don't assume they're in the same order, and
instead search all the locals.

This requires two passes: once going through the lookup table symbols
and once going through the .o symbols.  This is needed to make sure
there aren't any extra symbols in one of the files.

I also reorganized the code a bit to simplify it.
2017-07-06 12:44:50 -05:00
Joe Lawrence 2ef755bbb9 Merge pull request #712 from jpoimboe/fix-uninitialized-warnings
lookup: silence maybe-uninitialized warnings for -O2
2017-06-05 13:06:30 -04:00
Josh Poimboeuf c6763e218f lookup: silence maybe-uninitialized warnings for -O2
When compiling with -O2, it fails with:

  gcc -MMD -MP -O2 -I../kmod/patch -Iinsn -Wall -g -Werror -c -o lookup.o lookup.c
  lookup.c: In function ‘lookup_open’:
  lookup.c:132:21: error: ‘file_sym’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     table->local_syms = file_sym;
     ~~~~~~~~~~~~~~~~~~^~~~~~~~~~
  lookup.c:83:30: note: ‘file_sym’ was declared here
    struct object_symbol *sym, *file_sym;
                                ^~~~~~~~
  lookup.c:129:27: error: ‘child_sym’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
    if (in_file && !child_sym->name) {
                    ~~~~~~~~~^~~~~~
  lookup.c:85:27: note: ‘child_sym’ was declared here
    struct sym_compare_type *child_sym;
                             ^~~~~~~~~
  cc1: all warnings being treated as errors
  Makefile:17: recipe for target 'lookup.o' failed
  make[1]: *** [lookup.o] Error 1
  make[1]: Leaving directory '/home/jpoimboe/git/kpatch/kpatch-build'
  Makefile:14: recipe for target 'build-kpatch-build' failed
  make: *** [build-kpatch-build] Error 2

As far as I can tell, these are false positive warnings.  When in_file
is 1, file_sym and child_sym are properly initialized.  But silence the
warnings anyway so Gentoo users can build with -O2.

Fixes: #675
2017-06-05 11:11:55 -05:00
Jessica Yu 5a04c3395a Merge pull request #705 from vincentbernat/fix/ubuntu-get-source
kpatch-build: retrieve source package instead of linux-source
2017-05-18 20:23:21 -07:00
Josh Poimboeuf 8e51cdd724 Merge pull request #707 from vincentbernat/fix/lookup-vmlinux
create-diff-object: only check if kernel object starts with "vmlinux"
2017-05-18 21:40:30 -05:00
Vincent Bernat 998c794c7a create-diff-object: only check if kernel object starts with "vmlinux"
On Debian/Ubuntu, the `vmlinux` from `-dbg` package has a version number
appended to it. For example:
`/usr/lib/debug/boot/vmlinux-3.13.0-117-generic`. Make it work
nonetheless.
2017-05-18 08:18:14 +02:00
Vincent Bernat 0f717abf0c kpatch-build: retrieve source package instead of linux-source
On Ubuntu Trusty, HWE kernels don't come with a linux-source
package. Use dget to retrieve the source package instead. This is not
the case anymore with Xenial as the linux-source package is also
provided for the HWE kernels. For Debian, backports always come with the
linux-source package.
2017-05-17 23:24:32 +02:00
Josh Poimboeuf 8c558d367c Merge pull request #704 from jpoimboe/eh_frame
elf: add .eh_frame* sections to debug section list
2017-05-13 08:03:52 -05:00
Josh Poimboeuf 2b39f7d8d8 elf: add .eh_frame* sections to debug section list
SUSE-based kernels have a DWARF unwinder, so they build with the gcc
'-fasynchronous-unwind-tables' flag, which adds .eh_frame and
.eh_frame_hdr sections.  Treat those sections like the other debug
sections.

Fixes: #703
2017-05-11 14:02:08 -05:00
Jessica Yu 45b89ece75 Merge pull request #696 from jpoimboe/no-dynrelas-for-exported-symbols
create-diff-object: don't create dynrelas for exported vmlinux symbol…
2017-04-21 13:56:20 -07:00
Josh Poimboeuf 012ccece85 create-diff-object: don't create dynrelas for exported vmlinux symbols used by modules
Joe saw the following errors when loading Linux commit 128394eff343
("sg_write()/bsg_write() is not fit to be called under KERNEL_DS"):

  Skipped dynrela for copy_user_generic_unrolled (0xffffffffa0475942 <- 0xffffffff813211e0): the instruction has been changed already.
  Skipped dynrela for copy_user_generic_unrolled (0xffffffffa0475a57 <- 0xffffffff813211e0): the instruction has been changed already.

That is known issue #580, but it can be avoided by leaving
'copy_user_generic_unrolled' as a normal relocation instead of
converting it to a dynrela, because it's an exported symbol.

Also remove the manual check for '__fentry__' because it's covered by
the exported symbol check.

Also remove a duplicate comment about unexported global object symbols
being in another .o in the patch object.

Fixes #695.
2017-04-20 16:56:43 -05:00
Jessica Yu ea3fe27bea Merge pull request #694 from joe-lawrence/author_guide3
Author guide notes
2017-04-20 14:37:47 -07:00
Joe Lawrence 596cd45683 readme: update 'oops stack traces' taint reference 2017-04-20 17:11:33 -04:00
Joe Lawrence 29d11709c3 doc: more unexpected changed function examples 2017-04-20 17:11:25 -04:00
Joe Lawrence e124028b65 doc: shadow variable notes 2017-04-20 11:17:54 -04:00
Joe Lawrence dd18205539 doc: code removal blurb 2017-04-20 11:17:51 -04:00
Joe Lawrence 2ae4f5af4a doc: function prototype change workaround suggestion 2017-04-20 10:47:18 -04:00
Josh Poimboeuf 81ba0afc7e Merge pull request #693 from bryant1410/master
Fix broken headings in Markdown files
2017-04-19 17:42:33 -05:00
Santiago Castro 2b47cf8536 Fix broken Markdown headings 2017-04-18 00:23:37 -03:00
Jessica Yu 253b0e30b7 Merge pull request #692 from joe-lawrence/author_guide2
Author guide fixups
2017-03-27 11:30:32 -07:00
Joe Lawrence 81c4f63642 doc: add locking semantic example 2017-03-27 13:36:35 -04:00
Joe Lawrence de4042304c doc: add data semantic example to author guide 2017-03-27 11:42:28 -04:00
Joe Lawrence d072845816 doc: clarify (un)load hook execution context 2017-03-27 11:42:23 -04:00
Josh Poimboeuf ee31823402 Merge pull request #691 from flaming-toast/spellfix
kpatch-build: fix small typo
2017-03-21 17:50:30 -05:00
Jessica Yu f2b205b534 kpatch-build: fix small typo 2017-03-21 15:25:38 -07:00
Jessica Yu 87e264dfa2 Merge pull request #690 from joe-lawrence/author_guide
Add author guide examples
2017-03-15 20:42:16 -07:00
Joe Lawrence d90b9afbd9 doc: add shadow variable example to patch author guide
Add shadow variable examples and text.
2017-03-15 14:50:31 -04:00
Joe Lawrence d7aae34a0d doc: add (un)load hook example to patch author guide
Describe the kpatch (un)load hooks a little more and add in an example
from a recent CVE fix.
2017-03-14 15:48:34 -04:00
Josh Poimboeuf 810f924382 Merge pull request #689 from jpoimboe/0.4
bump version to 0.4.0
2017-03-13 14:10:18 -05:00
Josh Poimboeuf 07daab89b7 bump version to 0.4.0
This release has many fixes and improvements since 0.3.4.  The '0.3' was
bumped to '0.4' because of commit 0bb5c106ef ("kmod: restructure
kpatch sysfs tree"), which broke the ABI between the kpatch core module
and the kpatch script, as it changed the sysfs layout.

Other notable changes since 0.3.4:

- The tools underlying kpatch-build have been made more modular, in
  preparation for making create-diff-object more generally useful to
  other use cases (kernel livepatch, Xen live patching, user space
  patching).
- Support for all new upstream kernels up to 4.10.
- KASLR support.
- Many other bug fixes and improvements.
2017-03-13 12:49:42 -05:00
Jessica Yu 36682c9d91 Merge pull request #688 from joe-lawrence/doc_updates
README.md updates
2017-03-10 16:33:08 -08:00
Joe Lawrence 252ba99ea7 readme: update RHEL-based distributions
* remove the Fedora release number
* add part of the $(uname -r) to kernel package specifications
* add patchutils as an optional package to satisfy kpatch-test
* update to the latest ccache rpm URL @ dl.fedoraproject.org
2017-03-10 16:50:08 -05:00
Joe Lawrence 2596ef8f17 readme: add fentry limitation
Make note that patching functions without a fentry call can't be
patched, including lib.a archives.
2017-03-10 14:43:58 -05:00