Commit Graph

496 Commits

Author SHA1 Message Date
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
631fea5b7a Merge pull request #229 from jstancek/vdso_doc
readme: patches for vdso are not supported
2014-06-03 09:10:24 -05: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
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
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
Seth Jennings
0ef39f8b0b Merge pull request #216 from jstancek/issue203
fix vmlinux parameter for kpatch-build
2014-05-27 12:45:32 -05:00
Jan Stancek
e89f6fa679 fix vmlinux parameter for kpatch-build
It was missing in getopt arguments.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
2014-05-27 19:33:46 +02: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
Josh Poimboeuf
6aee215b04 Merge pull request #213 from jpoimboe/test-combined
test: add much quicker combined test option
2014-05-27 09:51:57 -05:00
Josh Poimboeuf
d7f209f838 test: add much quicker combined test option
Combine all the patch modules into a single kpatch-COMBINED.ko for a
much quicker test which still gives 95% or so of the coverage compared
to the full test suite.  Use "make quick" for use this new option.
2014-05-27 09:40:24 -05:00
Seth Jennings
82f095167e Merge pull request #211 from useidel/master
rebased SPEC file to current version
2014-05-27 09:05:14 -05:00
Jincheng Miao
827a143caf kmod/patch: export patched functions information via sysfs
This feature is implemented as:
```
[root@localhost kpatch]# insmod ./kpatch-meminfo.ko
[root@localhost kpatch]# ls /sys/kernel/kpatch/patches/kpatch_meminfo/functions/meminfo_proc_show/
new_addr  old_addr
[root@localhost kpatch]# cat /sys/kernel/kpatch/patches/kpatch_meminfo/functions/meminfo_proc_show/new_addr
0xffffffffa05211e0
[root@localhost kpatch]# cat /sys/kernel/kpatch/patches/kpatch_meminfo/functions/meminfo_proc_show/old_addr
0xffffffff8125d0e0
```

The patch module init function will allocate and init kpatch_func_obj with
customized kobj_type func_ktype. The attribute new_addr and old_addr of
kpatch_func_obj is attached to this func_ktype, so that these files could
be created by kobject_add automatically.

Signed-off-by: Jincheng Miao <jincheng.miao@gmail.com>
2014-05-27 21:56:56 +08:00
Josh Poimboeuf
54111376c0 Merge pull request #212 from spartacus06/remove-inventory-test-framework
remove inventory based testing
2014-05-27 08:05:16 -05: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
Udo Seidel
d6af58d3ab rebased SPEC file to current version 2014-05-24 14:51:11 +02:00
Josh Poimboeuf
ae24942c9e Merge pull request #209 from spartacus06/symbol-location-verification
Symbol location verification
2014-05-24 07:11:59 -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
Josh Poimboeuf
4fb7930d34 Merge pull request #208 from spartacus06/fix-symbol-migration
fix symbol migration
2014-05-23 15:54:37 -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
Seth Jennings
9261bcc642 Merge pull request #206 from jpoimboe/symtab-sh-info
create-diff-object: fix symtab sh_info field
2014-05-23 14:25:54 -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