Commit Graph

539 Commits

Author SHA1 Message Date
Josh Poimboeuf
b58e77ae9c kmod/core: move kpatch_write_relocations call
Write the relocations _after_ calling kpatch_calculate_old_addr() so
that we'll have a reference to the affected modules.
2014-06-13 11:57:15 -05:00
Josh Poimboeuf
c61fb88a23 kmod/core: add ftrace helper functions
Move all the ftrace filtering and registering logic into a couple of new
helper functions.  Change kpatch_num_registered to kpatch_num_patched,
which now tracks the number of patched functions rather than the number
of patch modules.

This simplifies the code a bit and will also prevent a future loaded
module scenario where ftrace_ops can be registered with an empty filter,
resulting in _all_ kernel functions getting registered with ftrace.
2014-06-13 11:57:14 -05:00
Josh Poimboeuf
dfc2641de2 kmod/core: use single quotes
Use single quotes when printing the name of a patch module, rather than
double quotes.  This is more consistent with other printk messages, and
looks better too!
2014-06-13 11:56:17 -05:00
Josh Poimboeuf
3ad35bd4f4 kmod/core: protect find_module with module_mutex 2014-06-13 11:56:17 -05:00
Josh Poimboeuf
6d951dc996 kmod/core: fix error path for kpatch_verify_symbol_match failure
If kpatch_verify_symbol_match() fails, set the num_funcs variable so
that the ftrace rollback only removes the filter for the affected
functions.
2014-06-13 11:56:17 -05:00
Josh Poimboeuf
579ee5f499 kmod/core: fix kpatch_put_modules call in error path
If kpatch_ftrace_add_func fails, num_funcs will be one less than what it
needs to be for kpatch_put_modules to work properly.  Instead give it
the full array size, and it can figure out which modules to put based on
whether func->mod is nonzero.
2014-06-13 11:56:16 -05:00
Josh Poimboeuf
31bd3a1538 kmod/core: fix kpatch_put_modules call order
kpatch_put_modules() should be called _after_ removing the ftrace
filters.
2014-06-13 11:55:16 -05:00
Josh Poimboeuf
3ca8106987 Merge pull request #238 from spartacus06/kpatch-build-module-support
kpatch-build module support
2014-06-05 16:36:07 -05:00
Seth Jennings
fac9d70612 kpatch-build: adjust indentation
The previous commit did not adjust the indentation to ease with
reviewing.  This commit corrects the indentation.  Purely whitespace
change.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-06-05 15:01:11 -05:00
Seth Jennings
d166fb4379 module patching support for kpatch-build
This commit adds support for module patching with kpatch-build.
It introduces a new option, -t/--targets, that allows the user to
specify kernel make targets that are impacted by the patch.  These
targets will be examined by kpatch-build for changes.

While this approach requires the user to provide more information to
kpatch-build about what exactly has changed, it is better that
rebuilding the entire source tree (make vmlinux && make modules) which
would dramatically increase the runtime and disk space requirements of
using kpatch-build.

Future improvements could include a script that will independently
generate the targets list file.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-06-05 14:55:37 -05:00
Seth Jennings
d026f9d866 Merge pull request #235 from jpoimboe/verbose-fix
__verbose rela fix
2014-06-04 16:26:50 -05:00
Josh Poimboeuf
0f908fb805 kmod/core: support R_X86_64_64 for module patching 2014-06-04 13:44:27 -05:00
Seth Jennings
ba7038052f Merge pull request #237 from jpoimboe/activeness-safety-print-func
kmod/core: print func name on activeness safety failure
2014-06-04 13:41:54 -05:00
Seth Jennings
322dac3507 Merge pull request #236 from jpoimboe/new-functions
create-diff-object: support adding new functions
2014-06-04 12:40:11 -05:00
Josh Poimboeuf
cb78565295 kmod/core: print func name on activeness safety failure 2014-06-04 12:20:49 -05:00
Josh Poimboeuf
aebb618755 create-diff-object: support adding new functions
New functions (sym->status == NEW) shouldn't be added to the
.kpatch.patches section.
2014-06-04 12:09:17 -05:00
Josh Poimboeuf
a16bd618a5 create-diff-object: include relas for non-bundled sections
With test/integration/data-read-mostly.patch, create-diff-object
includes the __verbose section but not the .rela__verbose section, which
is a bug, resulting in the following printk during the integration
tests:

  [13740.801920] dynamic debug error adding module: (null)

If a non-bundled section is included, its rela section should also be
included.  Also add support for converting those relas to dynrelas.
2014-06-04 11:48:23 -05:00
Josh Poimboeuf
76157dce4a kmod/core: add support for R_X86_64_64 dynrelas
Needed for relocations to data sections.
2014-06-04 11:48:19 -05:00
Seth Jennings
f6c8745a42 Merge pull request #234 from jpoimboe/isra-fix
create-diff-object: more special section fixes
2014-06-04 11:22:09 -05:00
Josh Poimboeuf
3ffe135512 create-diff-object: bundling for .text.unlikely symbols
With -ffunction-sections, some section names are given a prefix of
".text.unlikely." rather than just ".text.".
2014-06-04 10:39:22 -05:00
Josh Poimboeuf
a91c7eb250 create-diff-object: add support for gcc-mangled .part 2014-06-04 09:38:13 -05:00
Josh Poimboeuf
566ee5ffa4 create-diff-object: .isra fix
When renaming a foo.isra.1 function, there might also be a foo_bar
function which would be falsely matched with the current strchr logic.
Instead of matching the "foo" prefix, match "foo.isra".
2014-06-04 09:37:36 -05:00
Seth Jennings
ed0a3897b2 Merge pull request #233 from jpoimboe/debug-xtrace
kpatch-build: show all bash commands with DEBUG option
2014-06-04 07:57:35 -05:00
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