Commit Graph

98 Commits

Author SHA1 Message Date
Seth Jennings
d026f9d866 Merge pull request #235 from jpoimboe/verbose-fix
__verbose rela fix
2014-06-04 16:26:50 -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
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
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
72e260f50c create-diff-object: support gcc function name mangling
Fixes #189.
Fixes #228.
2014-06-03 11:26:03 -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
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
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
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
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
23f2cdfec2 Merge pull request #214 from jpoimboe/special-sections
generic support for special sections
2014-05-27 15:18:48 -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
Josh Poimboeuf
b1131bfeb6 create-diff-object: fix symbol section indexes
For a local non-included function or object which is needed by an
included function, its symbol table entry will still refer to a local
section index.  Instead it should be changed to SHN_UNDEF.
2014-05-27 12:47:45 -05:00
Josh Poimboeuf
0ebbed244e create-diff-object: percpu support
The -fdata-sections gcc flag doesn't work with objects in the
.data..percpu section.  Any function which uses a percpu variable
references this section, causing the section to get incorrectly included
in the patch module.

Manually convert these section references to object symbol references so
that the needed symbol can be found in vmlinux.

Also, the core module symbol verification code will fail when looking up
a percpu variable, because sprint_symbol doesn't think a percpu address
is a valid kernel address.  So rewrite the symbol verification code to
use kallsyms_on_each_symbol() instead.  It's not ideal performance-wise:
it seems to cost about 1ms per symbol lookup.  I think that's acceptable
for now.  In the future we may want to try to get a better upstream
kallsyms interface.
2014-05-27 12:47:42 -05:00
Jan Stancek
ff88218d9e correlate symbols also by type
Both unpatched and patched objects may contain FILE
symbol with empty name. This is unexpected for
create-diff-object and could correlate 2 symbols
with same (empty) name but different types:
  sym 00, type 0, bind 0, ndx 00, name  (SAME)
  ...
  sym 425, type 4, bind 0, ndx 65521, name  (SAME)
  ...
  signal.o: changed function: do_rt_tgsigqueueinfo
  signal.o: changed function: do_rt_sigqueueinfo
  signal.o: changed function: get_signal_to_deliver
  signal.o: signal.o: changed section .rela__jump_table not selected for inclusion
  signal.o: 1 unsupported section change(s)
  /root/kpatch/kpatch-build/create-diff-object: unreconcilable difference

Introduce condition to match symbols also by type.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
2014-05-27 19:25:34 +02:00
Seth Jennings
be4ee611c1 remove inventory based testing
The inventory based testing for create-diff-object was introduced at a
time when create-diff-object only needed the two object files to operate.
Now, it requires vmlinux as well.  This makes the inventory testing (a
unit testing framework for create-diff-object) obsolete and difficult to
update in it's current form.

This commit removes the inventory test framework.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-05-26 16:51:53 -05:00
Seth Jennings
a5d986ee96 review fixups
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-05-23 23:41:28 -05:00
Seth Jennings
505e948af0 symbol location verification support
This commit introduces functionality to verify the location of symbols
used in both the patch and dynrelas sections.  It adds significant
protection from mismatches between the base and running kernels.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-05-23 16:39:56 -05:00
Seth Jennings
08dc2ae78c change matching criteria for NULL sym
Right now the matching criteria for the NULL sym is type LOCAL and shndx
UNDEF.  Unfortunately, that would also match any new LOCAL symbol
added to the symbol table with uninit'd sym.* fields i.e. the upcoming
__kpatch_strings and .kpatch.strings symbols.

Change the matching criteria to be symbols that have a zero-length name;
a property unique to the NULL sym.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-05-23 16:39:55 -05:00
Seth Jennings
46a7a0b7b8 fix symbol migration
kpatch_migrate_included_symbols() is called from
kpatch_reorder_symbols() now, not kpatch_migrate_included_elements().
The difference is the kpatch_reorder_symbols() is operating on the
output kpatch_elf structure, and thus all symbols are by definition
included.

Remove the check and rename the function since it is redundant.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-05-23 15:46:41 -05:00
Josh Poimboeuf
2022ed1140 create-diff-object: fix symtab sh_info field
This fixes the weird ld errors we've been seeing lately.

According to the "ELF-64 Object File Format" spec, the symtab sh_info
field should contain "Index of first non-local symbol (i.e., number of
local symbols)".
2014-05-23 14:20:08 -05:00
Seth Jennings
847ddaa2e2 delay element reindexing and symbol reordering
Right now, reindexing of the included sections and symbols is done
when they migrate to the output kpatch_elf structure.  However, due
to recently added features, the section and symbol list is not
final at this point, leading to constant tracking of the indexes for
addition sections and symbols added after this point.  Additionally,
symbols have to be in a particular order, adding to the complexity.

This commit delays the reindexing and symbol reordering until the
section and symbol lists are finalized, removing the need to
track indexes and placeholders in the symbol list.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-05-22 16:28:51 -05:00
Seth Jennings
b95f0f53af add teardown/free functions for kpatch_elf data structures
Because create-diff-object is a one-shot program (not a long lived
process) we haven't really bothered with cleaning up and freeing any
allocated memory.  However, freeing data when it passes out of the
logical scope does have debugging benefits.

This commit adds two new functions for tearing down and freeing the
primary struct kpatch_elf data structures.  The idea is the if a stale
pointer still references the old data structure that has passed out of
the logical scope, an issue will be more immediately apparent (i.e. NULL
references).

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-05-20 12:44:31 -05:00
Seth Jennings
b6e77846e8 remove redundant rela buffer rebuild
We rebuild the rela section data buffer in kpatch_create_rela_section()
just to rebuild it again later in kpatch_rebuild_rela_section_data()
before writing the output ELF file.

This commit removes the redundant rebuild while retaining the update
for the section header data.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-05-20 12:44:31 -05:00
Seth Jennings
170c8b1ba1 fix review comments
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-05-20 12:44:31 -05:00
Seth Jennings
21fc274448 dynrelas support, obsoleting link-vmlinux-syms
This adds dynamic linking support for the patch modules.  It is the
first step toward supporting patching module code and relocatable
kernels.

Rela entries that reference non-included local and non-exported global
symbols are converted to "dynrelas".  These dynrelas are relocations
that are done by the core module, not the kernel module linker.  This
allows the core module to apply offsets to the base addresses found
in the base vmlinux or module.

Signed-off-by: Seth Jennings <sjenning@redhat.com>

Conflicts:
	kpatch-build/kpatch-build
2014-05-20 12:44:31 -05:00
Seth Jennings
fd8176faf8 rename .patches section to .kpatch.patches
Adding .kpatch to the section name more clearly documents that these
are kpatch related sections.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-05-20 12:44:30 -05:00
Seth Jennings
6b7d576341 merge add-patches-section functionality into create-obj-diff
In preparation for dynamic symbol linking, the symbol lookup logic
is going to move into create-diff-obj anyway.  We might as well
minimize the code duplication and pull this into create-diff-obj.
This avoids having to re-parse the ELF file modify it in-place.

Signed-off-by: Seth Jennings <sjenning@redhat.com>

Conflicts:
	kpatch-build/kpatch-build
2014-05-20 12:44:30 -05:00
Seth Jennings
b49bfac8fa fix included syms pointing to non-included sections
Right now, there is a case where a symbol is included but not its
section.  This is the case when the symbol is a rela dependency of
another section by the symbol section (the object or function) has not
changed.  When we migrate the included symbols over to the output kelf
structure however, these symbols are still referencing their old
non-included section via their sec fields.  This is a bug.

This commit adds code to the symbol migration to test whether the
symbol's section was also included.  If so, it updates the symbol's
section index.  If not it sets the section index to UNDEF and its sec
field to NULL.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-05-20 12:44:30 -05:00
Josh Poimboeuf
5e25365244 Revert #186 (add dynamic symbol linking support)
We merged PR #186 a little too hastily.  It seg faults with the new
parainstructions-section.patch in the integration test suite.  Reverting
it for now until we get it figured out.

This reverts commit e1177e3a03.
This reverts commit 880e271841.
This reverts commit 2de5f6cbfb.
This reverts commit 38b7ac74ad.
This reverts commit 108cd9f95e.
2014-05-15 17:34:16 -05:00
Josh Poimboeuf
59e9011a30 Merge pull request #188 from spartacus06/fix-list-corruption
fix list corruption in special section handlers
2014-05-15 15:44:10 -05:00
Seth Jennings
2b92531df2 fix list corruption in special section handlers
The kpatch_regenerate_* functions use a local list_head to construct the
new list.  While the local list_head is copied to the sec->relas after
it is built, the neighboring nodes in the list are not updated, leading
to list corruption.

This commit uses list_replace() which updates the neighbor nodes properly.

Regression introduced by PR #117 5d36dd1.

Fixes #185.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-05-15 15:27:53 -05:00
Seth Jennings
e1177e3a03 fix review comments
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-05-15 13:42:27 -05:00
Seth Jennings
880e271841 dynrelas support, obsoleting link-vmlinux-syms
This adds dynamic linking support for the patch modules.  It is the
first step toward supporting patching module code and relocatable
kernels.

Rela entries that reference non-included local and non-exported global
symbols are converted to "dynrelas".  These dynrelas are relocations
that are done by the core module, not the kernel module linker.  This
allows the core module to apply offsets to the base addresses found
in the base vmlinux or module.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-05-15 13:29:15 -05:00
Seth Jennings
2de5f6cbfb rename .patches section to .kpatch.patches
Adding .kpatch to the section name more clearly documents that these
are kpatch related sections.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-05-15 13:28:24 -05:00
Seth Jennings
38b7ac74ad merge add-patches-section functionality into create-obj-diff
In preparation for dynamic symbol linking, the symbol lookup logic
is going to move into create-diff-obj anyway.  We might as well
minimize the code duplication and pull this into create-diff-obj.
This avoids having to re-parse the ELF file modify it in-place.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-05-15 13:26:41 -05:00
Seth Jennings
a78bb8bcb3 cleanup logic in rela comparison
Per review comments.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-05-12 08:48:33 -05:00