Commit Graph

344 Commits

Author SHA1 Message Date
Josh Poimboeuf
ac324f40f8 Merge pull request #161 from spartacus06/revert-jump-table
Revert "create-diff-object: support for __jump_table"
2014-04-30 14:31:09 -05:00
Seth Jennings
16221237dd Revert "create-diff-object: support for __jump_table"
This reverts commit 5852ddb6a2.

The __jump_table section is more complex than the initial analysis
determined.  The __jump_table has three relocs per entry that must
be pulled in together and one of the relocs is to symbols contained
in the __tracepoints section whose rela section references the
__tracepoint_strings section.  So it's more complex and should just
fail rather than appear that it is being handled properly.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-30 14:23:03 -05:00
Seth Jennings
2f9f2e1ee2 Merge pull request #158 from jpoimboe/cdo-jump-table
create-diff-object: support for __jump_table
2014-04-30 11:00:58 -05:00
Josh Poimboeuf
5852ddb6a2 create-diff-object: support for __jump_table
Almost a line-for-line copy/paste of the smp locks function.  The only
differences are the section name, and an offset increment of 8 instead
of 4.

Fixes #157.
2014-04-29 16:21:03 -05:00
Josh Poimboeuf
065619ec68 Merge pull request #155 from spartacus06/ubuntu-doc
update docs for Ubuntu support
2014-04-29 13:40:42 -05:00
Seth Jennings
86ee4d188f update docs for Ubuntu support
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-29 13:33:02 -05:00
Seth Jennings
ad87448c9f Merge pull request #151 from jpoimboe/cdo-error-order
create-diff-object: better reachability error message
2014-04-29 12:26:28 -05:00
Josh Poimboeuf
a397818257 create-diff-object: better reachability error message
If a patch changes a single function which is in a special section that
we don't support, create-diff-object reports "no changed functions were
found".  Give a clearer error message in that case, by checking
reachability errors before unchanged errors and by printing all
reachability errors errors instead of the first one it encounters.

Fixes #150.
2014-04-29 12:24:01 -05:00
Josh Poimboeuf
cde0f8d062 Merge pull request #153 from spartacus06/ubuntu-support
Ubuntu support for kpatch-build
2014-04-29 11:31:38 -05:00
Seth Jennings
5e6a4ff042 Merge pull request #152 from jpoimboe/revert-init-fix
Revert "fail on changed init section"
2014-04-29 11:24:41 -05:00
Seth Jennings
6236c3a196 Ubuntu support for kpatch-build
At this point the module does build (i.e. kpatch-build is correct);
however, the addresses in the generated vmlinux don't match that
of the running kernel so the modules fail to load with an ftrace
registration error. So that is something to be investigated.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-29 11:14:36 -05:00
Josh Poimboeuf
d07fe1d8b1 Revert "fail on changed init section"
This reverts commit 7b15e23149.

It seems that there was no bug to start with, so apparently the commit
didn't fix anything.

Fixes #103.
2014-04-29 11:08:12 -05:00
Seth Jennings
96ea05ebea Merge pull request #148 from jpoimboe/kpatch-build-patch-dry-run
kpatch-build: test patch with --dry-run
2014-04-28 21:19:58 -05:00
Seth Jennings
1555a033d0 Merge pull request #149 from jpoimboe/readme
readme: add irc channel info
2014-04-28 21:17:36 -05:00
Josh Poimboeuf
d854e7f695 readme: add irc channel info
Fixes #142.
2014-04-28 21:13:50 -05:00
Josh Poimboeuf
897b17d9de kpatch-build: test patch with --dry-run
During the test whether the patch applies, if it partially applies, the
patch utility returns an error but leaves the source tree in a partially
patched state.  Use --dry-run instead.
2014-04-28 20:41:51 -05:00
Seth Jennings
9d476546ed Merge pull request #147 from jpoimboe/integration-tests
create integration test framework
2014-04-28 13:34:25 -05:00
Seth Jennings
89c42870ae Merge pull request #139 from jpoimboe/disable-before-unload
safe kpatch unload
2014-04-28 13:33:53 -05:00
Josh Poimboeuf
e19b0ad978 test: make load/unload errors fatal
No need to accumulate errors if the load or unload fails.  Leaving the
testprog failure non-fatal so that the test will then call unload to
clean up after itself.
2014-04-28 13:32:00 -05:00
Josh Poimboeuf
0858e8b054 add include linux/module.h to kpatch.h
Needed for the module and kobject structs.
2014-04-28 13:24:04 -05:00
Josh Poimboeuf
0d2ab160fe create integration test framework
This is a basic integration test framework for kpatch, which tests
building, loading, and unloading patches, as well as any other related
custom tests.

The kpatch-test script looks for test input files in the
tests/integration directory.  It expects certain file naming
conventions:

- foo.patch - patch that should build successfully

- bar-FAIL.patch - patch that should fail to build

- foo-LOADED.test - executable which tests whether the foo.patch module
  is loaded.  It will be used to test that loading/unloading the patch
  module works as expected.

Any other *.test files will be executed after all the patch modules have
been built from the *.patch files.  They can be used for more custom
tests above and beyond the simple loading and unloading tests.

I just have one test here, but many more to come eventually.  I'm
constantly doing manual testing of patches and am planning on automating
them with this framework.
2014-04-26 16:23:05 -05:00
Josh Poimboeuf
0bbddf629a Merge pull request #145 from spartacus06/parainstructions-support
add .parainstructions support
2014-04-25 23:27:19 -05:00
Josh Poimboeuf
b7a2862f90 safe kpatch unload
Currently the patch module calls kpatch_unregister in the patch module
exit path.  If the activeness safety check fails in kpatch_unregister,
it's too late for the patch module to stop exiting, so all it can do is
panic.

Prevent this scenario by requiring the user to disable the patch module
via sysfs before allowing the module to be unloaded.  The sysfs write
will fail if the activeness safety check fails.  An rmmod will fail if
the patch is still enabled.

Also add support for this new unloading model in "kpatch unload".
2014-04-25 23:05:26 -05:00
Seth Jennings
6ea92f1fc5 add .parainstructions support
Following in the same solution, regenerate [.rela].parainstructions
sections if table entries contain relocations that reference changed
functions (if any).

Fixes #135

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-25 16:00:22 -05:00
Josh Poimboeuf
8ed5aa06ea Merge pull request #144 from spartacus06/smp-locks
fix smp_lock support
2014-04-25 14:16:06 -05:00
Seth Jennings
e444b2cbb8 fix smp_lock support
The initial commit had a bug where the offset field of the
.rela.smp_locks entries was not updated to reflect the correct
offset in the truncated .smp_locks section.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-25 14:07:51 -05:00
Josh Poimboeuf
477115adc6 Merge pull request #143 from spartacus06/smp-locks
add smp_locks support
2014-04-25 11:00:58 -05:00
Seth Jennings
30757f027f add smp_locks support
This commit uses the same approach as the bug table support,
mangling the .smp_locks and .rela.smp_locks sections so that
they only contain entries for changed functions (if any).

Fixes #107

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-25 10:46:24 -05:00
Seth Jennings
5aa743324e Merge pull request #141 from ryanmiao/for-issue-140
Adding preempt_mask.h to core.c
2014-04-25 08:43:33 -05:00
Jincheng Miao
6c2d6444b1 Adding preempt_mask.h to core.c
When compiling core.c, it may report error like:
"error: implicit declaration of function ‘in_nmi’"

Adding header file in_nmi defined could avoid this.

Signed-off-by: Jincheng Miao <jincheng.miao@gmail.com>
2014-04-25 12:08:04 +08:00
Seth Jennings
32d6609c19 Merge pull request #137 from jpoimboe/unpatch-safety-fix
fix activeness safety check when unpatching
2014-04-24 17:06:40 -05:00
Josh Poimboeuf
fe6ace4fc7 kmod/core: error handling review fixes
Some fixes from the code review for better readability.
2014-04-24 14:22:51 -05:00
Seth Jennings
531702f0a6 Merge pull request #136 from jpoimboe/readme
readme: document WARN macro behavior
2014-04-23 15:26:52 -05:00
Josh Poimboeuf
f3f39c0587 fix activeness safety check when unpatching
When unpatching, the activeness safety logic should check for the new
function on the stack, not the old one.

Fixes #64.
2014-04-23 14:37:35 -05:00
Josh Poimboeuf
48cc3a409e kmod/core: move a couple of functions
Move kpatch_get_*_func a little higher in the file where they will be
needed for the next commit.
2014-04-23 14:37:35 -05:00
Josh Poimboeuf
2984b53d21 kmod: add new kpatch_module struct
Put funcs, num_funcs, and mod in their own struct called kpatch_module.
This allows us to keep patch module specific variables in one place (and
we'll have more of these variables soon).
2014-04-23 14:36:15 -05:00
Josh Poimboeuf
ff28767295 kmod: error handling cleanup
Cleanup the error handling a little bit and make the flow a little
clearer.
2014-04-23 14:36:15 -05:00
Josh Poimboeuf
7cb574aa22 readme: document WARN macro behavior
Document the WARN behavior, along with a few other updates about the
taint flag and kprobes incompatibility.

Fixes #112.
2014-04-23 14:34:05 -05:00
Josh Poimboeuf
892c630ce3 Merge pull request #108 from mhiramathitachi/issue-65
Fix the Issue #65: NMI handler live patching
2014-04-23 13:55:38 -05:00
Masami Hiramatsu
42e0779c0c kmod/core: Support live patching on NMI handlers
Support live patching on NMI handlers. This adds checks for
possible inconsistency of live patching on NMI handlers.
The inconsistency problem means that any concurrent execution
of old function and new function, which can lead unexpected results.

Current kpatch checks possible inconsistency problem with
stop_machine, which can cover only threads and normal interrupts.
However, beacuse NMI can not stop with it, stop_machine is not
enough for live patching on NMI handlers or sub-functions which are
invoked in the NMI context.

To check for possible inconsistency of live patching on those
functions, add an atomic flag to count patching target functions
invoked in NMI context while updating kpatch hash table. If the
flag is set by the target functions in NMI, we can not ensure
there is no concurrent execution on it.

This fixes the issue #65.

Changes from v5:
 - Fix to add a NULL check in kpatch_get_committed_func().

Changes from v4:
 - Change kpatch_operation to atomic_t.
 - Use smp_rmb/wmb barriers between kpatch_operation and kpatch_status.
 - Check in_nmi() first and if true, access kpatch_operation.

Changes from v3:
 - Fix kpatch_apply/remove_patch to return 0 if succeeded.

Changes from v2:
 - Clean up kpatch_get_committed_func as same style of kpatch_get_func.
 - Rename opr to op in kpatch_ftrace_handler.
 - Consolidate in_nmi() and kpatch_operation check into one condition.
 - Fix UNPATCH/PATCH mistype in kpatch_register.

Changes from v1:
 - Rename inconsistent_flag to kpatch_status.
 - Introduce new enums and helper functions for kpatch_status.
 - Use hash_del_rcu instead of hlist_del_rcu.
 - Rename get_committed_func to kpatch_get_committed_func.
 - Use ACCESS_ONCE for kpatch_operation to prevent compiler optimization.
 - Fix to remove (!func || func->updating) condition from NMI check.
 - Add more precise comments.
 - Fix setting order of kpatch_status and kpatch_operation.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
2014-04-23 10:58:45 +09:00
Masami Hiramatsu
79ca5dbfa7 kmod/core: Handle registering error and unroll it
Handle registering error to unroll the ftrace filter.
This also introduces get_kpatch_func() and
kpatch_remove_funcs_from_filter() for holding up
redundant loops.

Changes from v2:
 - Rebased on the latest kpatch.

Changes from v1:
 - Rename get_kpatch_func to kpatch_get_func.
 - Fix function definition style issue.
 - Do not jump to a label in "if" block.
 - Rollback the ftrace user counter if we hit an error.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
2014-04-23 10:58:45 +09:00
Josh Poimboeuf
2e607644e1 Merge pull request #133 from spartacus06/bugtable
Add support for bug table and data in .bss sections
2014-04-22 15:30:46 -05:00
Seth Jennings
99ae097b08 Merge pull request #134 from jpoimboe/find-core-module-git-tree
kpatch: look for core module in git dir
2014-04-22 11:10:23 -05:00
Seth Jennings
47d4109f7e fixup review comments
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-22 11:01:01 -05:00
Josh Poimboeuf
d1d79084a3 readme: recommend use of the kpatch utility
The kpatch utility is now user friendly enough that it can be used
instead of direct insmods.  We should encourage people to use it, since
we will soon be adding user space functionality above and beyond
insmod/rmmod when loading and unloading.
2014-04-21 21:44:40 -05:00
Josh Poimboeuf
ed31d7af3d kpatch: look for core module in git dir
Allow "kpatch load" to find the core module when kpatch is run directly
from the git tree.  This gives the user the option to use the kpatch
utility directly without having to do a "make install".
2014-04-21 21:38:00 -05:00
Seth Jennings
ab07805166 add info to expected rela sym error
While debugging the code for the bug table logic, I found it useful to
know which rela section and entry the error occurred on.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-21 17:40:38 -05:00
Seth Jennings
7cfcce1ed6 add bug table support
This commit adds a new function to properly handle the bug table.
It works by going through .rela__bug_table, after the changed
function symbols have already been marked, and rewrites the section
including only the relocations pertaining to bug entries for
changed functions.

The __bug_table section itself is not modified resulting in
"blank" bug entries: ones whose IP and filename pointers will
not be relocated and, therefore, will be zero.  While a waste
of space, it simplifies the code not to remove these blank
entries. They do no harm.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-21 17:40:38 -05:00
Seth Jennings
3753f06de4 use d_size instead of sh_size
The section header size is calculated at output time by libelf
and we use it as a read-only value from read files.

With the next patch we are changing the size of the .rela__bug_table
section.  Lets use d_size instead since it is the value that tells
libelf how to calculate sh_size at output time.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-21 17:40:38 -05:00
Seth Jennings
09262d4d67 support .bss.* bundling
Allow bundling of .bss.* sections that are the result of -fdata-sections
so that rela sections referencing data in bss sections by section symbol
can be replaced with the object symbol so it can be linked to the existing
data object in the kernel.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-21 17:40:38 -05:00