Commit Graph

516 Commits

Author SHA1 Message Date
Josh Poimboeuf
e782399536 kpatch-build: show all bash commands with DEBUG option 2014-06-04 07:39:07 -05:00
Josh Poimboeuf
7f5581ec17 Merge pull request #232 from spartacus06/improve-kpatch-unload
improve kpatch unload checking
2014-06-03 16:12:33 -05:00
Seth Jennings
870cfa899c improve kpatch unload checking
Currently, kpatch unload passes the raw argument to basename since the
user may pass a path into the subcommand. This makes the argument hard
to validate.  This can be improved since the set of acceptable inputs is
already known, namely the list of loaded patch modules.

This commit changes the kpatch unload subcommand to accept only the
module name, since kpatch should already be aware of it since it is
loaded.  It is then trivial to validate the user input since, if it is
not the name of a loaded module, it is invalid.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-06-03 15:55:41 -05:00
Seth Jennings
91f3a1d501 Merge pull request #231 from jpoimboe/unload-all-error
kpatch: a few minor script cleanups
2014-06-03 14:38:43 -05:00
Josh Poimboeuf
d2b765fea5 kpatch: consistent naming: module vs patch
Try to be more consistent with the naming of patch modules.  They are
patch modules, where patch is the adjective and module is the noun.  So
calling them patches is confusing.
2014-06-03 13:13:22 -05:00
Josh Poimboeuf
22f0d38f86 kpatch: improve "unload --all" error message
In the case of "kpatch unload --all", just show the usage help instead
of this:

  # kpatch unload --all
  basename: unrecognized option '--all'
  Try 'basename --help' for more information.
  unloading patch module:
  basename: unrecognized option '--all'
  Try 'basename --help' for more information.
  rmmod: ERROR: Module  is builtin.
  kpatch: failed to unload patch --all
2014-06-03 13:13:05 -05:00
Seth Jennings
88cac305be Merge pull request #230 from jpoimboe/isra
create-diff-object: support gcc function name mangling
2014-06-03 12:22:39 -05:00
Josh Poimboeuf
6be51b012e fix review comments 2014-06-03 12:16:51 -05:00
Josh Poimboeuf
9ee3f36aea Merge pull request #227 from spartacus06/module-patching-support
Module patching support
2014-06-03 12:12:35 -05:00
Seth Jennings
15b22cf01b review changes for module support PR
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-06-03 11:36:51 -05:00
Josh Poimboeuf
72e260f50c create-diff-object: support gcc function name mangling
Fixes #189.
Fixes #228.
2014-06-03 11:26:03 -05:00
Seth Jennings
7fdc142d18 Merge pull request #205 from terrywang/doc
Add missing dependencies & vmlinux symbolic link for Ubuntu
2014-06-03 10:47:47 -05:00
Seth Jennings
631fea5b7a Merge pull request #229 from jstancek/vdso_doc
readme: patches for vdso are not supported
2014-06-03 09:10:24 -05:00
Terry Wang
1b182d92b2 readme: add missing dependencies for Ubuntu 2014-06-03 23:01:47 +10:00
Jan Stancek
65d4c4977f readme: patches for vdso are not supported
Signed-off-by: Jan Stancek <jstancek@redhat.com>
2014-06-03 13:52:37 +02:00
Seth Jennings
5b62d5f169 add module for testing module patching
A simple kernel module for testing basic kernel module patching.

Just run doit.sh from test/testmod.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-06-02 20:34:38 -05:00
Seth Jennings
5f00b0b05f add module patching support to core module
This commit adds support for patching modules.  If a patch or dynrela is
determined to be for a kernel module, the old_offset/src is not used and
the symbol location is looked up using kallsyms.  The module being
patched is also references to keep if from disappearing from underneath
us.

This commit introduces early and limited support.  The kernel module to
be patched must already be loaded or the patch module will not apply.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-06-02 20:34:37 -05:00
Seth Jennings
3f864cc864 add module patching support to create-diff-object
This commit adds module patching support to create-diff-object by:

1) generalizing the vmlinux CLI parameter
2) adding the kernel object name to each patch and dynrela
3) adding slightly different logic for vmlinux/module in the dynrela
creation

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-06-02 20:34:37 -05:00
Seth Jennings
6b7013daa1 exclude UNDEF global syms from lookup_global_symbol
Don't return a result for an UNDEF symbol

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-06-02 20:34:37 -05:00
Seth Jennings
870b6fb95b invert logic to reduce indentation
No functional change.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-06-02 15:57:12 -05:00
Seth Jennings
d79046c295 avoid replicating dynrela logic
Rather than keep the logic in sync between the counting and processing
code in kpatch_create_dynamic_rela_sections() just do a "dumb" count
establishing an upper bound and allocating the buffer, then determine
the actual size (i.e. number of dynrelas) in the processing section.

No functional change intended.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-06-02 15:57:12 -05:00
Seth Jennings
ec5293d681 avoid replicating strip logic
Just create a strip feild in the struct symbol the is marked if the
symbol needs to be stripped.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-06-02 15:57:12 -05:00
Seth Jennings
aa8c5da5ba change struct kpatch_patch s/old_addr/old_offset
Make old addresses relative to the start address of the relocatable
kernel or module.

This commit has no functional effect; it just prepares the code for
future acceptance of the module patching support.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-06-02 15:57:12 -05:00
Seth Jennings
13f02e61ea Merge pull request #224 from jpoimboe/distro-specific-vmlinux
kpatch-build: make VMLINUX variable distro-specific
2014-06-02 14:29:01 -05:00
Seth Jennings
5501c7211c Merge pull request #226 from jpoimboe/dont-replace-sec-with-sec
create-diff-object: don't replace section ref with section ref
2014-06-02 14:28:09 -05:00
Josh Poimboeuf
3641662601 create-diff-object: don't replace section ref with section ref
Don't replace a section reference with a section reference (duh).

Fixes #225.
2014-06-02 14:25:29 -05:00
Seth Jennings
a705c223fc Merge pull request #222 from jpoimboe/special-section-fixes
special section fixes
2014-05-30 15:25:41 -05:00
Josh Poimboeuf
401680a7c9 create-diff-object: tracepoint & jump label fixes
The current approach of trying to include the tracepoint-related
sections doesn't work at all.  The new tracepoints don't show up in
"perf list".

And also, with one patch (issue #219) I've seen a panic in
jump_label_del_module().  I suspect it's because the kernel is confused
by dynamic relocations' changing of the jump table after it was
registered with the jump table code.

I think the best approach for now is to just always exclude these
sections.  It should be harmless, with the only consequence being that
tracepoints and jump labels can't be enabled in patched functions (which
is already the case with the current code anyway).

Fixes #221.
2014-05-30 15:20:08 -05:00
Josh Poimboeuf
4f78ad65c9 create-diff-object: improved error message 2014-05-30 15:20:08 -05:00
Josh Poimboeuf
4a95a16911 create-diff-object: support .data..read_mostly and .data.unlikely
Support patching functions which uses these sections by converting
references to these sections to symbol object references.

Fixes #219.
2014-05-30 15:20:08 -05:00
Josh Poimboeuf
00e9dc3b1d create-diff-object: fix section to symbol conversion
For a rela with type X86_64_PC32, the addend of the needed symbol is
relative to the address of the instruction _after_ the one which is the
target of the relocation.
2014-05-30 15:20:08 -05:00
Josh Poimboeuf
cba7fd1f49 insn: get it to compile in create-diff-object 2014-05-30 15:19:57 -05:00
Josh Poimboeuf
ecc5141676 insn: import insn disassembler code from kernel
We need a disassembler library to help with converting data section
relocation references to their corresponding symbols.  Unfortunately,
the only library I could find that's widely available in enterprise
Linux distros was libopcodes, which is part of binutils.  But its
interface is far too clunky for our needs.

The best alternative I can find is to just copy the kernel's
disassembler library code from arch/x86/lib.
2014-05-30 15:16:06 -05:00
Seth Jennings
26a75e5207 Merge pull request #223 from jpoimboe/dynrela-loc-check
kmod/core: validate dynrela destination address
2014-05-30 15:01:26 -05:00
Josh Poimboeuf
e7bd541c97 kpatch-build: make VMLINUX variable distro-specific
As discussed in #205.
2014-05-30 11:48:20 -05:00
Josh Poimboeuf
ecf6173869 kmod/core: validate dynrela destination address
Ensure that dynrela destination addresses are within the patch module's
memory.

Also, use the module address ranges to check whether set_memory_rw() is
needed.
2014-05-30 09:24:38 -05:00
Josh Poimboeuf
303928f634 create-diff-object: ensure no data sections are included
When a changed function needs relocations for special data sections like
.data..percpu or .data..read_mostly, it's possible for those sections to
get included.  We try to avoid that situation by converting section
references to data symbol references in kpatch_replace_sections_syms(),
but the conversion success rate isn't 100%, and we could be forgetting
about some other sections, so ensure that it never happens in
kpatch_verify_patchability().
2014-05-30 08:12:47 -05:00
Seth Jennings
ad8f2299ef Merge pull request #218 from jpoimboe/struct-def-change-error
kpatch-build: better error message for struct def change
2014-05-28 16:18:53 -05:00
Josh Poimboeuf
eb44c06918 kpatch-build: better error message for struct def change
Fixes #109.
2014-05-28 13:48:55 -05:00
Seth Jennings
2225bd83cc Merge pull request #180 from ryanmiao/print_funcs
export funcs via sysfs
2014-05-27 23:24:49 -05:00
Seth Jennings
52c0cd108d Merge pull request #217 from jpoimboe/check-page-rw
kmod/core: ensure page is RO before changing its permissions
2014-05-27 23:23:26 -05:00
Josh Poimboeuf
625fcdfb72 kmod/core: ensure page is RO before changing its permissions
Make sure we leave the page's execution permissions in the same state we
found them.
2014-05-27 21:58:15 -05:00
Josh Poimboeuf
ab941fb90a kmod/core: make loc variable a u64
So less casting is needed.
2014-05-27 21:49:45 -05:00
Josh Poimboeuf
80c1e8ac83 kmod/core: move dynamic relocation writes to new function
Unclutter kpatch_register a little bit.
2014-05-27 21:47:50 -05:00
Seth Jennings
23f2cdfec2 Merge pull request #214 from jpoimboe/special-sections
generic support for special sections
2014-05-27 15:18:48 -05:00
Josh Poimboeuf
98617df3ef Merge pull request #215 from jstancek/issue202
correlate symbols also by type
2014-05-27 12:49:42 -05:00
Josh Poimboeuf
92a4ca2621 create-diff-object: support tracepoints and related sections
Add support for the following special sections:

- __jump_table
- __tracepoints
- __tracepoints_ptrs
- __tracepoints_strings

Fixes #157.
2014-05-27 12:47:45 -05:00
Josh Poimboeuf
698cc1c137 create-diff-object: support fixup and related sections
Add support for the following sections:

- .fixup
- __ex_table
- .altinstructions
- .altinstr_replacement

Fixes #187.
2014-05-27 12:47:45 -05:00
Josh Poimboeuf
317d957f2c create-diff-object: generic special section support
Abstract out the common functionality for dealing with special sections
into a new kpatch_process_special_sections() function.

The base sections are partitioned into "groups".  Only those groups
whose relas reference a changed function are kept.  The only difference
in the logic for handling each special section is determining the size
of a given group.  Each section has its own group_size() callback for
this.  It's a callback instead of an integer because one of the
soon-to-be-supported special sections requires that its group sizes be
dynamically determined.
2014-05-27 12:47:45 -05:00
Josh Poimboeuf
d74f78342a create-diff-object: improve error message 2014-05-27 12:47:45 -05:00