Commit Graph

209 Commits

Author SHA1 Message Date
Xie XiuQi
6b446cba67 create-diff-object: fix a potential overflow for rela type
rela.type should be unsigned int instead of unsighed char.

/usr/include/gelf.h:#define GELF_R_TYPE(info)   ELF64_R_TYPE (info)
/usr/include/elf.h:#define ELF64_R_TYPE(i)      ((i) & 0xffffffff)

Signed-off-by: Xie XiuQi <xiexiuqi@huawei.com>
2015-01-19 22:43:26 +08:00
Colin Ian King
a41ce8d409 Fix memory leak on dest buffer on early return path
dest is allocated but not freed on an early return path
where dest is not used

Signed-off-by: Colin Ian King <colin.king@canonical.com>
2014-10-20 09:42:44 +01:00
Seth Jennings
a31a31f184 Merge pull request #457 from jpoimboe/warn-fix
warn detection fix
2014-10-08 11:24:35 -05:00
Josh Poimboeuf
fca189152a fix review comment 2014-10-08 11:16:09 -05:00
Seth Jennings
664fb2a8a2 Merge pull request #453 from jpoimboe/rs-special-static
make _rs a "special" static local variable
2014-10-08 10:58:11 -05:00
Josh Poimboeuf
ea819a18b0 warn detection fix
The current WARN detection logic catches the majority of cases, but
there are still a lot of outliers which it doesn't catch (thanks, gcc).

I looked at a much larger sample of WARN calls and came up with a more
generic algorithm.
2014-10-07 22:01:14 -05:00
Josh Poimboeuf
128bc9fb31 fix review comments
- rela sections don't have secsyms
- add some comments
2014-10-07 19:47:38 -05:00
Josh Poimboeuf
027e2b3b4e fix review comment 2014-10-07 16:47:25 -05:00
Josh Poimboeuf
4c7fb9119a detect and ignore WARN-only changes
WARN-only function changes are very common, and a serious PITA for patch
authors.  Detect and ignore them.

Fixes #454.
2014-10-07 11:56:41 -05:00
Josh Poimboeuf
c799ecc55f make _rs a special static local
The _rs variable is used for printk ratelimiting, similar to __warned,
which makes it a logical candidate to be "special": don't correlate it,
yet don't mark a function as changed just because it references it.
2014-10-07 08:09:20 -05:00
Josh Poimboeuf
fe846f4d56 refactor is_special_static
Make is_special_static()'s implementation more generic to make it easier
to add special static variables in the future
2014-10-07 08:09:20 -05:00
Josh Poimboeuf
c705c767af change special_static_prefix to is_special_static
We no longer need to return the prefix, so change it to a boolean
function.
2014-10-07 08:09:20 -05:00
Josh Poimboeuf
0e8f1ae02d use kpatch_mangled_strcmp in rela_equal
Use kpatch_mangled_strcmp() to compare the prefixes of special static
locals.
2014-10-07 08:09:20 -05:00
Josh Poimboeuf
050d7933d7 refactor rela_equal
Make it easier to read and reduce the indent levels
2014-10-07 08:09:20 -05:00
Seth Jennings
bb6edd16f9 Merge pull request #452 from jpoimboe/module-call-external
allow patched modules to call external functions
2014-10-07 00:04:43 -05:00
Seth Jennings
31852c0dfa Merge pull request #451 from jpoimboe/sections-syms-fix
section reference replacement for references inside symbols
2014-10-07 00:01:20 -05:00
Josh Poimboeuf
f5de932b8d allow patched modules to call external functions
When patching a kernel module, if we can't find a needed dynrela symbol,
we currently assume it's exported.  However, it's also possible that
it's provided by another .o in the patch module.  Add support for that.

Fixes #445.
2014-10-06 23:16:13 -05:00
Josh Poimboeuf
2a29d8704e fix review comment 2014-10-06 22:56:53 -05:00
Josh Poimboeuf
3dd442b12d section reference replacement for references inside symbols
Currently unbundled section references are only replaced if the start of
the symbol is referenced.  It's also useful to support replacement of
references which point to inside the symbol.
2014-10-06 22:52:01 -05:00
Josh Poimboeuf
bb35e37c47 small replace_sections_syms refactor
Move this code block to a more logical place, outside of the symbol
loop.
2014-10-06 22:16:22 -05:00
Josh Poimboeuf
fb49e254cf improve static local variable correlation
Improve the static local variable correlation logic, for the case where
a static local is used by multiple functions.  For each usage of the
variable, look for a corresponding usage in the base object.  If we find
at least one matching usage, consider it a twin.
2014-10-06 14:38:46 -05:00
Josh Poimboeuf
f7c0e6849e allow static locals to be used by two functions
Allow static locals to be used by two functions.  This is possible if
the static's containing function is inlined.  We only need to find one
of them to do the correlation.
2014-10-03 16:02:16 -05:00
Josh Poimboeuf
03995e5223 make __func__ a special static local
The __func__ static local variable should be deemed "special", because
it doesn't need to be correlated and should be included when needed by
an include function.

I don't have a test case for F20, but this fixes the following types of
issues when doing a full-tree recompile on RHEL 7:

    ERROR: cifssmb.o: object size mismatch: __func__.49322
    ERROR: btmrvl_main.o: kpatch_correlate_static_local_variables: 982: static local variable __func__.44657 not used
    ERROR: iwch_qp.o: .rodata.__func__.46024 section header details differ
2014-10-03 12:27:27 -05:00
Seth Jennings
c6506ec549 Merge pull request #436 from jpoimboe/descriptor
make "descriptor" a special static local variable
2014-10-02 23:11:00 -05:00
Josh Poimboeuf
51799dff2c remove "no changed functions" messages
When patching a shared header file, don't spam the user with hundreds of
lines of "no changed functions" messages.  We expect the user to be
proactive with verifying that the right functions are being patched
anyway, so this message isn't strictly necessary.
2014-10-01 14:12:25 -05:00
Josh Poimboeuf
e27ffadce1 make "descriptor" a special static local variable
The "descriptor" static local variables and their containing __verbose
section are used for dynamic debug printks.  They should be considered
as special static local variable symbols because they have the same
requirements: they should never be correlated and they should only be
included if referenced by an included function.
2014-10-01 11:11:54 -05:00
Seth Jennings
88aae05894 Merge pull request #428 from jpoimboe/full-tree-recompile
full tree recompilation support
2014-09-15 21:22:08 -05:00
Josh Poimboeuf
a20940892a code review fixes 2014-09-15 21:11:13 -05:00
Josh Poimboeuf
33cd945b14 new .fixup group size algorithm
The fixup_group_size() function assumes that all .fixup rela groups end
with a jmpq instruction.  That assumption turns out to be false when you
take into account the ____kvm_handle_fault_on_reboot() macro which is
used by kvm.

This is a new, more reliable method.  It turns out that each .fixup
group is referenced by the __ex_table section.  The new algorithm goes
through the __ex_table relas to figure out the size of each .fixup
group.

Also the .fixup section is now processed before __ex_table, because it
needs to access the original __ex_table relas before the unused ones
have been stripped.

Fixes the following error:

  ERROR: vmx.o: fixup_group_size: 1554: can't find jump instruction in .fixup section
2014-09-15 14:54:57 -05:00
Josh Poimboeuf
dbecef6e91 replace all unbundled section references with symbols
Currently we're checking for several special cases when deciding whether
to convert unbundled section references to their corresponding symbol
references.  We do it for all unbundled text sections as well as three
specific data sections.

There's no reason I can think of for why we shouldn't just do it for
_all_ unbundled sections.
2014-09-15 12:01:34 -05:00
Josh Poimboeuf
bfe7fca5bd rename global "objname" variable to "childobj"
There are two distinct usages of "objname" as a variable name:

- the parent object being patched (e.g. vmlinux)
- the child object being analyzed (e.g. meminfo.o)

The name of the global objname variable conflicts with several
functions' usage of a local objname variable, resulting in some error
messages of e.g., "ERROR: vmlinux:" instead of "ERROR: meminfo.o:".

Rename the global objname variable to childobj.
2014-09-15 11:36:02 -05:00
Josh Poimboeuf
ba7c905b3a process special sections after checking for changes
There's no need to process special sections if we're returning due to no
functions changing.

Also this means we don't have to deal with extra-special usage of the
.fixup section (here's looking at you arch/x86/lib/copy_user_64.S -- we
can't patch functions in .S files anyway).
2014-09-15 11:17:37 -05:00
Josh Poimboeuf
d41365fc0e process special sections after inclusion logic
The special sections should be processed after all the other inclusion
logic has run, so that should_keep_rela_group() can work properly.
Otherwise it might remove a needed rela group from a special section.
2014-09-12 14:03:10 -05:00
Seth Jennings
93398c21ca Merge pull request #412 from jpoimboe/key-warned
support for__key and __warned special static local vars
2014-09-11 14:24:49 -05:00
Seth Jennings
a82b3d8fa0 Merge pull request #415 from jpoimboe/mangled-strcmp
fix the mangled function strcmp
2014-09-11 13:30:17 -05:00
Seth Jennings
671a30fb99 Merge pull request #413 from jpoimboe/static-fix
skip data sections when looking for users of static locals
2014-09-11 13:22:51 -05:00
Josh Poimboeuf
1553764be6 add other users of kpatch_mangled_strcmp 2014-09-11 08:27:09 -05:00
Josh Poimboeuf
0da57e8807 fix the mangled function strcmp
Fix the mangled function strcmp so that it compares all of the string
except for the numbered parts.  foo.isra.35 should match foo.isra.1, but
not foo.isra.35.part.36.

Fixes #352.
2014-09-10 21:25:30 -05:00
Josh Poimboeuf
24ea032f9f allow the user to ignore a rela section
If the user specifies KPATCH_IGNORE_SECTION for a rela section, ignore
the corresponding text section instead of corrupting memory.

Fixes #381.
2014-09-10 17:05:17 -05:00
Josh Poimboeuf
b2f47f9ef3 add another user of is_text_section 2014-09-09 15:11:09 -05:00
Josh Poimboeuf
0537ff6a6f skip data sections when looking for users of static locals
It's possible for a static local variable's data section to have
a relocation which refers to the variable symbol itself.  Fix the logic
which searches for the user of a static local variable by only looking
in text sections (i.e. functions).

Fixes #411.
2014-09-09 14:43:42 -05:00
Josh Poimboeuf
db91697542 don't convert section references to syms for debug sections
This fixes a seg fault in the test suite caused by a debug section
referencing an un-included unbundled symbol (though its section was
included).  The symbol was a __warned symbol and the section was
.data.unlikely.

For debug sections, there is no need to replace section references with
symbols because we don't compare debug sections.
2014-09-09 13:36:23 -05:00
Josh Poimboeuf
2982962549 support for__key and __warned special static local vars
Add support for the __key and __warned "special" static local variables.
I'm calling them that for lack of a better term, analagous to the
kernel's special sections that we have to deal with.

__warned: Used by WARN_ONCE et al as an indicator as to whether a
message has already been printed.  I think it makes sense (and is much
easier) to reset this counter for a given function when replacing the
function, since the user may expect the new function to warn again.

__key: Used by lockdep as an identifier for a given lock initialization
code path (see http://lwn.net/Articles/185666/ for more info).  I think
it makes sense (and is much easier) to create a new key for a given
function when replacing the function, because the locking semantics may
have changed, so it makes sense for lockdep to use a new key to validate
the new locking behavior.

So for both __warned and __key static variables, the new version of the
variable should be used when referenced by an included function.

Made the following changes to support these special variables:

- Ignore their suffixes when comparing them in rela_equal, so that gcc
  renaming them will not result in a function being marked as changed
  just because it referenced a renamed static local

- Don't ever correlate them, so that their new versions will be included
  if a changed or new function uses their corresponding symbols

Fixes #402.
2014-09-09 13:36:20 -05:00
Josh Poimboeuf
57ee537053 Merge pull request #408 from cormander/show-all-errors
die on create-diff-object when all objects have processed
2014-09-09 10:51:36 -05:00
Corey Henderson
3d9a140bfa oops, use sym->name, not sym->sec->rela->name 2014-09-08 22:44:55 -04:00
Corey Henderson
55c981d794 Give more generic failure message, and include ERROR in output 2014-09-08 22:28:00 -04:00
Corey Henderson
3e14e1859f change in wording per jpoimboe 2014-09-08 22:21:20 -04:00
Corey Henderson
96b4e099d8 Be more specific about the bad first instruction 2014-09-08 22:04:18 -04:00
Seth Jennings
3343eed007 Merge pull request #380 from jpoimboe/shadow-variables
add support for shadow variables
2014-09-08 14:17:37 -05:00
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