Commit Graph

1274 Commits

Author SHA1 Message Date
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
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