Commit Graph

315 Commits

Author SHA1 Message Date
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
Seth Jennings
39200f2d9a Merge pull request #132 from jpoimboe/debug-keep-logfile
kpatch-build: don't delete logfile in debug mode
2014-04-21 16:27:53 -05:00
Josh Poimboeuf
cfd1ce3b34 kpatch-build: don't delete logfile in debug mode 2014-04-21 16:26:23 -05:00
Seth Jennings
4fb8d76eb3 Merge pull request #130 from jpoimboe/cdo-log-obj-name
create-diff-object logging improvements
2014-04-17 14:41:59 -05:00
Josh Poimboeuf
9b038039dd create-diff-object: removed unused function
kpatch_find_changed_functions isn't called by anybody, so remove it.
2014-04-15 19:17:40 -05:00
Seth Jennings
3775692aa0 Merge pull request #131 from jpoimboe/tmpdir-name
kpatch-build: put kpatch-build in the tmp dir name
2014-04-15 17:17:21 -05:00
Seth Jennings
56d036004f Merge pull request #129 from jpoimboe/kpatch-load-file
kpatch: allow kpatch load/unload/info for files
2014-04-15 17:09:34 -05:00
Seth Jennings
c7a59142b5 Merge pull request #128 from jpoimboe/fentry
kmod/core: require fentry
2014-04-15 17:09:06 -05:00
Josh Poimboeuf
0684c2f772 kpatch-build: put kpatch-build in the tmp dir name 2014-04-15 16:57:56 -05:00
Josh Poimboeuf
37a66ee57c create-diff-object: show object name in log messages
For log_normal and DIFF_FATAL messages, prefix them with the object name
to give more context, which is useful for patches which change multiple
objects.  Also, no need to add the function and line number to
DIFF_FATAL messages, as the error strings already give enough
information.

Example messages:

  meminfo.o: changed function: meminfo_proc_show
  cmdline.o: no changed functions were found
2014-04-15 16:49:59 -05:00
Josh Poimboeuf
44c4ecd3ff kpatch: allow kpatch load/unload/info for files
A user may want to load a module without having to install it to the
initrd.  In fact, 99% of the time I think that will be the typical usage
of "kpatch load", with a given file as an argument rather than a DB
module.

Have "kpatch load" and other commands take a file as input.  If the file
is not found, then check the DB.
2014-04-15 14:59:47 -05:00
Josh Poimboeuf
991b25b067 kmod/core: require fentry
Only compile the core module if the compiler supports -mfentry.
2014-04-15 14:40:03 -05:00
Seth Jennings
27980527cd Merge pull request #127 from jpoimboe/pr_err
kmod/core: use pr_err instead of printk
2014-04-15 14:28:42 -05:00
Josh Poimboeuf
e6cad4f0b1 kmod/core: use pr_err instead of printk 2014-04-15 14:21:19 -05:00
Seth Jennings
2fd20a7a30 Merge pull request #124 from jpoimboe/taint
kmod/core: taint kernel with TAINT_USER
2014-04-15 13:52:47 -05:00
Seth Jennings
2802086a37 Merge pull request #126 from jpoimboe/rm-kpatch-service
remove systemd service unit file
2014-04-15 13:52:42 -05:00
Seth Jennings
fc42abebd1 Merge pull request #125 from jpoimboe/patch-module-terminology
update patch module terminology
2014-04-15 13:52:19 -05:00
Josh Poimboeuf
ac53b4e7a0 remove systemd service unit file
Now that we're using dracut instead of systemd to load modules at boot
time, the systemd unit file is no longer needed.
2014-04-15 13:50:18 -05:00
Josh Poimboeuf
a7efb05c81 update patch module terminology
Try to be more consistent with the terminology.  In various places we
call it a "hotpatch module", "hot patch module", or "patch module".  How
about we just call it a "patch module" everywhere?
2014-04-15 13:47:56 -05:00
Seth Jennings
afd3669746 Merge pull request #123 from lulinqing/patch-1
Fix issue #122 (subcommand unload not recognized)
2014-04-15 13:34:24 -05:00
Josh Poimboeuf
56645d346d kmod/core: taint kernel with TAINT_USER
For now, taint with TAINT_USER when loading a patch module so that the
user can always detect when a kpatch module has been previously loaded.
Eventually we will want a dedicated TAINT_KPATCH flag in the kernel.
2014-04-15 13:34:01 -05:00
Seth Jennings
18a583b6bf Merge pull request #120 from jpoimboe/revert-115
Revert "kpatch-build: prevent die if only part of objects have no change...
2014-04-15 11:41:51 -05:00
Linqing Lu
9470c385d8 Fix issue #122 (subcommand unload not recognized) 2014-04-15 12:12:15 +08:00
Seth Jennings
6006cb074b Merge pull request #121 from jpoimboe/dracutdir
fix DRACUTDIR to be in /usr/lib/dracut
2014-04-14 12:51:27 -05:00
Seth Jennings
8195a2f79a Merge pull request #119 from jpoimboe/load-into
kpatch: change wording of "load to" to "load into"
2014-04-14 12:41:04 -05:00
Seth Jennings
ba5899b312 Merge pull request #118 from jpoimboe/kpatch-load-2
contrib: change kpatch-apply-all to kpatch-load-all
2014-04-14 12:40:45 -05:00
Josh Poimboeuf
ea945f6121 fix DRACUTDIR to be in /usr/lib/dracut
Unforunately the dracut module doesn't work if installed in
/usr/local/lib/dracut.  It must always be installed in
/usr/lib/dracut regardless of the install prefix.
2014-04-14 12:39:19 -05:00
Josh Poimboeuf
e00d1394c4 Revert "kpatch-build: prevent die if only part of objects have no change"
This reverts commit ab29b1ff59.

Reverting this commit because it causes kpatch-build to ignore any
errors reported by create-diff-object, treating all errors as meaning
that no changes occurred, which is a dangerous assumption to make.
2014-04-14 12:34:44 -05:00
Josh Poimboeuf
68e4cff461 kpatch: change wording of "load to" to "load into" 2014-04-14 12:30:11 -05:00
Josh Poimboeuf
3083d4ef85 contrib: change kpatch-apply-all to kpatch-load-all 2014-04-14 12:27:55 -05:00