Commit Graph

260 Commits

Author SHA1 Message Date
Josh Poimboeuf
749da4f261 kpatch-build: don't show full kpatch-build path in usage message
For interface consistency with other unix utilities.
2014-07-29 16:46:12 -05:00
Seth Jennings
392049a283 make symbol section change an error
make symbol section change an error, except when moving out of an
ignored section

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-07-28 14:09:33 -05:00
Seth Jennings
ebf55f8614 add support for replacing section syms for unbundled sections
Right now, the test patch unnecessarily includes hrtimer_nanosleep()
because the call to do_nanosleep() generates a rela the references the
unbundled .sched.text section.  This section symbol is not currently
replaced by kpatch_replace_sections_syms() as it only replaces bundled
sections symbols.

This commit adds logic to kpatch_replace_sections_syms() to replace
unbundled section symbols as well by scanning the symbol table for
symbols that start at the rela entry's offset within the matching
section.

This allows for properly rela section correlation when the functions
have moved from an unbundled section to a bundled section.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-07-28 11:10:32 -05:00
Seth Jennings
8ac20f5475 add KPATCH_IGNORE_SECTION support
This macro is for ignoring sections that may change as a side effect of
another change or might be a non-bundlable section; that is one that
does not honor -ffunction-section and create a one-to-one relation from
function symbol to section.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-07-28 11:10:32 -05:00
Seth Jennings
11f8f8da76 mark mcount sections as SAME
Right now, in the case that the mcount sections have changed, we get a
"changed section not included" error on them.  Since we rebuild them
from scratch, just mark them as SAME even if they are different so that
we don't cause an error.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-07-28 09:29:46 -05:00
Seth Jennings
85da92132f s/funcs/functions/g
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-07-28 09:29:46 -05:00
Seth Jennings
5a4756bbb8 remove sh_link from section comparison
This sh_link line currently has a bug with both operands being sec1; the
second should be sec2.  However the bug is masking a logical flaw; that
is that the sh_link is the index of either the symtab or the strtab and
that can change if sections have been added or removed by the patch.

This commit removes the comparison.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-07-25 09:35:34 -05:00
Josh Poimboeuf
9c3c9b0c0a support for gcc static local variable renaming
gcc renames static local variables by appending a period and a number.
For example, __key could be renamed to __key.31452.  Unfortunately this
number can arbitrarily change.  Try to rename the patched version of the
symbol to match the base version and then correlate them.

Fixes #313.
2014-07-24 15:08:15 -05:00
Josh Poimboeuf
402911b949 replace section symbols before correlating
The correlation logic could get confused if it compares two relas whose
symbols haven't been converted from section symbols to object or
function symbols.  So we should replace section symbols for both the
base and the patched object before correlating, so that it can compare
the function and object symbols rather than the section symbols.

This is also a prerequisite for dealing properly with gcc's renaming of
static local variables, because relas which reference static locals
usually use section symbols.
2014-07-24 14:51:57 -05:00
Seth Jennings
5321b21aa0 fixup review comments
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-07-23 11:24:02 -05:00
Seth Jennings
9a2f8c5c44 remove build pass from kpatch-build
Now that we use the vmlinux from the distro debug package we don't need
to do any build runs without -ffunction-sections -fdata-sections.

Old:
Build orig in objdir
Build patched in objdir
Build orig w/ flags in objdir2
Copy orig .o's into orig
Build patched w/ flags in objdir2
Copy patched .o's into patched

New:
Build orig w/ flags in objdir
Build patched w/ flags in objdir
Copy patched .o's into patched
Build orig w/ flags in objdir
Copy orig .o's into orig

This commit also does try to build each change object singularly since
there are cases in the kernel tree where the Makefile does not reside in
the same directory as the changed object.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-07-23 10:03:00 -05:00
Seth Jennings
84618404e0 add support for manually ignore functions
This commit adds the KPATCH_IGNORE_FUNC() macro for ignoring functions
that may change as a side effect of a change in another function.  The
WARN class of macros, for example, embed the line number in an
instruction, which will cause the function to be detected as changed
when, in fact, there has been no functional change.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-07-23 09:00:16 -05:00
Seth Jennings
bdb44e7594 fix logging in kpatch_verify_patchability()
log_normal() already prints the objname; no need to do it again

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-07-18 15:29:46 -05:00
Josh Poimboeuf
4fefa662fd create-diff-object: fix for unincluded sec->secsym
When running kpatch-build with -d, I was getting a seg fault.  It was
faulting in kpatch_dump_kelf() when trying to print sec->secsym->name
for the .smp_locks section.  It turns out that the section was included
but its section symbol wasn't included, so sec->secsym pointed to freed
memory.
2014-07-08 08:12:34 -05:00
Seth Jennings
44ad2ba733 Merge pull request #298 from jpoimboe/no-fentry-dynrela
create-diff-object: don't create __fentry__ dynrelas
2014-07-07 21:02:50 -05:00
Josh Poimboeuf
ddf4836466 kpatch-build: extract GCC version from .comment section
Extract the GCC version from the .comment section of vmlinux.  This
hopefully makes the version check more robust across various distros.

Fixes #297.
2014-07-07 20:54:57 -05:00
Josh Poimboeuf
e847026824 create-diff-object: don't create __fentry__ dynrelas
This fixes the following issue for a patch which changes a module:

  kpatch_create_mcount_sections: 1968: bad first rela in .rela.text.e_show

The first rela is "bad" because the real first rela was converted to a
dynrela and then removed from the rela list.

This is a temporary fix.  The more permanent fix should be to allow
lookups in vmlinux for patched modules so we don't create any
unnecessary dynrelas.
2014-07-07 14:03:02 -05:00
Josh Poimboeuf
817d3746b4 kpatch-build: support custom ~/.rpmmacros file
Be able to deal with a custom ~/.rpmmacros file, for which the SPECS and
BUILD directories are configurable.
2014-07-03 09:16:49 -05:00
Seth Jennings
2e93c5e1e3 support forced patching
Some functions in the kernel are always on the stack of some thread
in the system.  Attempts to patch these function will currently always
fail the activeness safety check.

However, through human inspection, it can be determined that, for a
particular function, consistency is maintained even if the old and new
versions of the function run concurrently.

This commit introduces a KPATCH_FORCE_UNSAFE() macro to define patched
functions that such be exempted from the activeness safety check.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-07-02 14:06:33 -05:00
Seth Jennings
6b428eec2f Merge pull request #291 from jpoimboe/gcc-ubuntu
kpatch-build: fix gcc version check on ubuntu
2014-07-02 08:35:19 -05:00
Josh Poimboeuf
5893a28fdf kpatch-build: fix gcc version check on ubuntu 2014-07-02 06:17:59 -05:00
Gaetan Trellu
9d72c76b1a kpatch-build: use getconf to get the processors number 2014-07-01 22:18:16 -04:00
Josh Poimboeuf
aaf1bf3e8e Merge pull request #288 from spartacus06/section-create-refactor
consolidate new section pair creation
2014-07-01 16:27:06 -05:00
Seth Jennings
1f17adec07 consolidate new section pair creation
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-07-01 16:00:51 -05:00
Seth Jennings
94ec430201 Merge pull request #286 from jpoimboe/check-gcc-version
kpatch-build: gcc version checks
2014-07-01 15:07:55 -05:00
Josh Poimboeuf
73171714bc kpatch-build: gcc version checks
Ensure the version of the locally installed gcc matches the one used to
compile the kernel, and is >= 4.8.

Fixes #246.
2014-07-01 14:24:53 -05:00
Seth Jennings
fd637ce542 Merge pull request #285 from goldyfruit/master
kpatch-build: add debian support
2014-07-01 14:02:57 -05:00
Gaetan Trellu
4e3b4825ad kpatch-build: merge the ubuntu and debian section 2014-07-01 14:41:57 -04:00
Josh Poimboeuf
df679e3192 Merge pull request #278 from spartacus06/user-hook-support-v2
add user-defined load/unload hook support
2014-07-01 13:09:33 -05:00
Seth Jennings
d4e4d14dbe fixup review comments
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-07-01 12:22:16 -05:00
Seth Jennings
1ebae501ba Merge pull request #283 from jpoimboe/mcount
create-diff-object: create __mcount_loc section
2014-07-01 11:10:59 -05:00
Gaetan Trellu
d341e3237e kpatch-build: fix SUBLEVEL in the Makefile 2014-07-01 11:16:23 -04:00
Gaetan Trellu
0459810dd3 kpatch-build: add debian support 2014-07-01 10:55:43 -04:00
Josh Poimboeuf
79bd9f03ee create-diff-object: create __mcount_loc section
For ftrace to be able to trace a patched function, it requires that the
__mcount_loc section contains a pointer to the function, and that the
first instruction of the function is "callq __fentry__".

Normally that work is done by the recordmcount script, but it ignores
functions that aren't in a few standard sections (.text and a few
others).
2014-07-01 08:29:37 -05:00
Josh Poimboeuf
403cf65b89 kpatch-build: don't remove USERSRCDIR
Fixes #279.
2014-06-30 14:20:13 -05:00
Seth Jennings
4835e3edc3 add user-defined load/unload hook support
This commit enables the ability to create user-defined hooks as part of
the normal code patch that can do preparatory work for the application
of the patch.  This work could include, but is not limited to, changing
data structure semantics.

The user may define a new function as part of the patch and mark it as a
load-time or unload-time hook with the kpatch_load_hook() and
kpatch_unload_hook() macros.  These macros are in an include file that
gets copied into the source tree at include/linux/kpatch-hooks.h at
patch build time. The signature for both hooks is "int kpatch_unload_hook(void)".

For now, the return code is ignored.  The hooks may not fail.  They also
run in stop_machine() context and may not sleep.  These hooks, more or
less, must follow all the rules of interrupt context code.
2014-06-30 13:37:26 -05:00
Josh Poimboeuf
895672953e kpatch-build: detect core dump 2014-06-27 12:08:04 -05:00
Seth Jennings
537f68b4fd create-diff-object: fixup new function handling
The original logic in the inclusion tree code worked under the
assumption that it was the only code path marking symbols for inclusion.
Therefore, if the symbol had been marked as included, it could be safely
assumed that we also already called kpatch_include_symbol() on it.  With
the special section handling marking symbols as included, however, this
assumption is not valid.

We should call kpatch_include_symbol() regardless of whether or not the
symbol has already been marked as included or not in order to possible
include the symbol's entire bundle.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-06-27 09:12:44 -05:00
Seth Jennings
d9472012a2 create-diff-object: reduce verbosity in debug mode
With the inclusion of the debug sections, the debug output is so verbose
that it becomes less useful.

This commit reduces the verbosity by skipping rela listings of debug
sections.

It includes a new helper function, is_debug_section(), to consolidate
the logic for detecting debug sections.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-06-26 10:46:57 -05:00
Seth Jennings
d13e98f7e5 Merge pull request #267 from jpoimboe/kpatch-symlink
kpatch-build: allow ~/.kpatch to already exist
2014-06-26 09:17:54 -05:00
Josh Poimboeuf
06a2075ab5 kpatch-build: allow ~/.kpatch to already exist
This is useful if ~/.kpatch is a symlink or a tmpfs mount.

- move SRCDIR/OBJDIR/OBJDIR2 initialization to the top
- create new VERSIONFILE variable
- create new clean_cache function which doesn't remove ~/.kpatch

Fixes #261.
2014-06-26 09:05:36 -05:00
Josh Poimboeuf
2362d44783 create-diff-object: include new functions 2014-06-25 16:46:08 -05:00
Josh Poimboeuf
36c98e39d6 fix review comment 2014-06-20 14:34:54 -05:00
Josh Poimboeuf
89ce1c5d79 kpatch-build: --sourcedir 2.0
In my experience this is a much more useful implementation of the
"--sourcedir" option:

- use the source tree in-place rather than first copying it to
  ~/.kpatch/src.  In my case this avoids a 5GB copy, including the
  entire .git subdirectory, and allows ccache to be reused.

- find the vmlinux and .config files in the sourcedir

- autodetect the ARCHVERSION
2014-06-20 08:05:16 -05:00
Josh Poimboeuf
3e4aa955d9 fix review comment 2014-06-19 13:01:54 -05:00
Josh Poimboeuf
eccc3eb63b kpatch-build: DEBUG for create-diff-object
Add -d option to create-diff-object when DEBUG is set.  That way for
weird kpatch-build issues we can just tell people to use the -d flag and
then provide the build log.
2014-06-19 12:30:22 -05:00
Josh Poimboeuf
2e14094844 kpatch-build: fix getopt typo for --target 2014-06-18 16:03:42 -05:00
Seth Jennings
50cb818196 Merge pull request #249 from jpoimboe/undefined-module-symbols
fix undefined symbols for future loaded modules
2014-06-18 13:28:39 -05:00
Josh Poimboeuf
9d016add40 fix review comments 2014-06-18 12:23:38 -05:00
Josh Poimboeuf
34cc258a31 fix undefined symbols for future loaded modules
When patching module A, if one of the new function's relas reference a
symbol in module B, we currently just leave it as a normal rela.  But if
module B hasn't been loaded yet, the patch module will fail to load due
to the rela's reference to an undefined symbol.

The fix is to convert these relas to dynrelas, which can be resolved
later in the module notifier when A is loaded.

Also added support for the R_X86_64_NONE relocation type, needed for
dynrelas which reference __fentry__.
2014-06-18 11:17:11 -05:00