Commit Graph

291 Commits

Author SHA1 Message Date
Josh Poimboeuf
4dee89269c add support for shadow variables
This adds support for shadow variables, which allow you to add new
"shadow" fields to existing data structures.

To allow patches to call the shadow functions in the core module, I had
to add a funky hack to use --warn-unresolved-symbols when linking, which
allows the patched vmlinux to link with the missing symbols.  I also
added greps to the log file to ensure that only unresolved symbols to
kpatch_shadow_* are allowed.  We can remove this hack once the core
module gets moved into the kernel tree.

Fixes #314.
2014-09-08 13:36:37 -05:00
Josh Poimboeuf
ae4ad2b4f1 change format of "ignoring" messages
Change the "ignoring" message formatting to be consistent with the
"changed function:" message to make it a little easier to read.
2014-08-28 15:30:43 -05:00
Terry Wang
9fcd8ba732 kpatch-build: add Oracle Linux 7 and CentOS 7 support 2014-08-19 17:38:47 +10:00
Seth Jennings
7b82b59a68 Merge pull request #360 from flaming-toast/func-sysfs-fix
kpatch-patch-hook: fix incorrect old_offsets for loadable modules
2014-08-15 21:33:45 -05:00
Jessica Yu
6a69f5f91a consolidate variables func->old_offset and func->old_addr to just old_addr
To reduce redundancy, remove/change the old_offset fields in the
kpatch_func and kpatch_patch_func structs to just old_addr. Since
old_offset is being used as a placeholder for old_addr, might as well
consolidate it to just one variable.
2014-08-15 23:42:26 -07:00
Josh Poimboeuf
543ad11ccd create-diff-object: allow new data to be included
Allow the inclusion of new global variables.
2014-08-14 01:12:27 -05:00
Seth Jennings
26ef7bfcb1 always include .rodata.str1.* sections
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-08-13 21:26:34 -05:00
Seth Jennings
f466a60708 fix use-after-free error
Don't use rela after you just freed it!

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-08-13 17:08:42 -05:00
Seth Jennings
7dfad2fb76 fix dynrela corruption in load/unload hooks
In kpatch_create_dynamic_rela_sections() the dest field is filled in
with either the function symbol or the section symbol that contains the
function depending on whether or not the sym field of the base section
is NULL or not (around line 2153).

In the case of the hook functions, we strip the FUNC symbol to prevent
it from being added to the kpatch.funcs section as a patched function.
However we weren't unbundling the stripped symbol from the section.
This resulted in the sym field pointing to the null symbol (index 0),
corrupting the dynrelas rela section.

Before:

Relocation section [14] '.rela.kpatch.dynrelas' for section [13] '.kpatch.dynrelas' at offset 0x8b8 contains 6 entries:
  Offset              Type            Value               Addend Name
  000000000000000000  X86_64_64       000000000000000000      +9
  0x0000000000000018  X86_64_64       000000000000000000      +8 .kpatch.strings
  0x0000000000000020  X86_64_64       000000000000000000      +0 .kpatch.strings
  0x0000000000000030  X86_64_64       000000000000000000      +9
  0x0000000000000048  X86_64_64       000000000000000000      +8 .kpatch.strings
  0x0000000000000050  X86_64_64       000000000000000000      +0 .kpatch.strings

This commit unbundles the stripped symbol from the section so that the
section symbol is used in the dynrelas rela section.

After:

Relocation section [14] '.rela.kpatch.dynrelas' for section [13] '.kpatch.dynrelas' at offset 0x8b8 contains 6 entries:
  Offset              Type            Value               Addend Name
  000000000000000000  X86_64_64       000000000000000000      +9 .text.kpatch_load_aio_max_nr
  0x0000000000000018  X86_64_64       000000000000000000      +8 .kpatch.strings
  0x0000000000000020  X86_64_64       000000000000000000      +0 .kpatch.strings
  0x0000000000000030  X86_64_64       000000000000000000      +9 .text.kpatch_unload_aio_max_nr
  0x0000000000000048  X86_64_64       000000000000000000      +8 .kpatch.strings
  0x0000000000000050  X86_64_64       000000000000000000      +0 .kpatch.strings

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-08-13 13:40:29 -05:00
Seth Jennings
e020127eea allow patches that only contains hook functions
Fixes #357

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-08-13 11:28:43 -05:00
Josh Poimboeuf
7b4ee86197 kpatch-gcc: fix for .tmp_* objects on RHEL 7
On RHEL 7 I see the following error when trying to patch meminfo.o:

    cp: cannot stat ‘/home/user/.kpatch/obj/fs/proc/.tmp_meminfo.o’: No such file or directory

It turns out that on RHEL 7, a given object foo.o is compiled as
.tmp_foo.o before then being linked as foo.o.  I have no idea why.  The
fix is to record .tmp_foo.o as foo.o in the changed_objs file.
2014-08-12 21:21:53 -05:00
Seth Jennings
e1e694db4b review fixups
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-08-11 22:41:09 -05:00
Seth Jennings
a0e6dce9af cleanup kpatch_correlate_symbols()
This commit inverts some logic to reduce the max indentation

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-08-11 17:24:05 -05:00
Seth Jennings
bf86555e06 add correlation and compare support for GROUP sections
GROUP section are rare and are a mechanism in the ELF to indicated that
certain groups of section must be included or excluded (stripped)
together.

It is valid to have more than one of these section with the same
".group" name.  This currently messes up the section correlation code
with correlates based solely on name.

This commit adds additional correlation criteria for GROUP sections;
namely, the section content must be the same.  Changing of groups
sections (i.e. reindexing of the section indexes the GROUP section
includes in their section data) is not supported and will result in a
"new/changed section not included" error.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-08-11 17:24:05 -05:00
Seth Jennings
e483cda793 support renaming of mangled functions in unbundled sections
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-08-08 15:20:31 -05:00
Josh Poimboeuf
a600f1d117 kpatch-build: don't link unchanged objects
The FILES variable can contain unchanged objects, so don't use it to
determine which objects to link.  Instead, just use all the objects that
were placed in the output directory by create-diff-object.
2014-08-08 14:22:17 -05:00
Josh Poimboeuf
1b9868ed33 kpatch-gcc: exclude system_certificates.o
Fixes the following issue when running kpatch-build against the latest
upstream kernel:

    system_certificates.o: no changed functions were found
2014-08-08 14:18:46 -05:00
Josh Poimboeuf
e7cf064c62 kpatch-gcc: split up object exclusion list 2014-08-08 14:18:27 -05:00
Seth Jennings
fb5dbc2fc5 allow for unchanged objects
There are situations in which an object may be rebuilt but have no
functional changes, such as a change to an included header file.

This commit changes kpatch-build to tolerate individual unchanged
objects so long as there is, in the end, at least one changed object.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-08-08 10:26:36 -05:00
Seth Jennings
b98fafcfb2 restructure building process
Right now, we do three build passes: one to build the original tree
(full) build, one to build the patch tree (diff build), then one to
rebuild original objects that where changed by the patch (diff build).

This is going to be a problem when we try to support (near) full tree
rebuilds due to changes in commonly included header files.

This commit changes the build process to intercept calls to gcc by make
using the CROSS_COMPILE environment variable and, during the patched
build phase, copies the original object for any object that is about to
rebuilt due to a change.

This reduces the number of build passes to the minimum possible (two).

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-08-07 17:25:05 -05:00
Seth Jennings
191e389b43 fix bad Module.symvers path
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-08-07 17:24:53 -05:00
Seth Jennings
9b86df0eee Merge pull request #344 from jpoimboe/verbose
__verbose special section support
2014-08-04 16:58:01 -05:00
Josh Poimboeuf
b4b0f76e4c compare __func__ references by value
Fixes the following error:

    kpatch_correlate_static_local_variables: 850: found another static local variable matching __func__.49968 in patched .rela__verbose
2014-08-04 13:17:18 -05:00
Josh Poimboeuf
1bb9b81db1 detect .rodata.* bundled sections
Detect .rodata.* bundled sections so that .rodata.__func__.* relocation
references can be converted to refer to their corresponding object
symbols.

Fixes the following error:

    kpatch_correlate_static_local_variables: 830: static local variable __func__.49968 not used
2014-08-04 13:17:18 -05:00
Josh Poimboeuf
f1775ec73d don't correlate __verbose statics
The __verbose section stores several static local structs named
"descriptor".  These structs contain information related to dynamic
debugging printks and are specific to the patched object, so they
shouldn't be correlated with their base object counterparts.

Fixes the following error:

    kpatch_correlate_static_local_variables: 830: static local variable descriptor.49967 not used
2014-08-04 13:17:18 -05:00
Seth Jennings
c93b723dfb Merge pull request #329 from terrywang/ubuntu-mirror
kpatch-build and README.md update
2014-08-04 12:07:29 -05:00
Terry Wang
a56d48e19d kpatch-build: remove unneeded comments readme: roll back unneeded changes 2014-07-30 20:08:17 +10:00
Seth Jennings
aa6f510bc0 Merge pull request #339 from jpoimboe/module-name-fixes
module name fixes
2014-07-29 20:59:39 -05:00
Josh Poimboeuf
4f91924d7e kpatch-build: truncate long patch names
Otherwise the module name listed in /proc/modules is corrupted due to an
array buffer overrun.
2014-07-29 17:02:48 -05:00
Josh Poimboeuf
a0756a5f1d kpatch-build: convert spaces in patch name to '-' 2014-07-29 17:02:10 -05:00
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
Terry Wang
cde33f13ed kpatch-build: use close archive mirror for Ubuntu for speed 2014-07-25 21:08:20 +10: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