Commit Graph

706 Commits

Author SHA1 Message Date
Josh Poimboeuf
40fbb4effc code review fix
Return 0 on rmmod error.
2014-07-09 22:41:02 -05:00
Josh Poimboeuf
e1890e627a prevent rmmod of forced modules
I found a bad bug:

- Module A is loaded, and registers function foo() with
  KPATCH_FORCE_UNSAFE.
- Module A is unloaded.  The new version of foo() is on the backtrace of
  a task, but the core module ignores it because of the force flag, so
  the unloading succeeds.
- The task returns to the new version of foo() which no longer exists.
- BOOM.

The only way I can think of to prevent this scenario is to prevent
forced modules from being unloaded (but still allow them to be
disabled).

An annoying side effect of this approach is that forced modules stay
loaded and in memory forever.  And that after "kpatch unload" of a
forced module, you can't ever load it again because the previous
instance of it is still loaded (but permanently disabled).

This is ugly but I can't really think of a better way to handle it.  If
necessary we could create a workqueue and periodically check to see if
we can safely call module_put() so that the module could be eventually
removed.
2014-07-09 22:16:29 -05:00
Seth Jennings
6c926a7692 Merge pull request #302 from goldyfruit/master
README.md: add debian support
2014-07-09 15:47:09 -05:00
Seth Jennings
d436576346 Merge pull request #304 from jpoimboe/force-fix
kmod/core: check force flag in replace case
2014-07-09 15:45:47 -05:00
Josh Poimboeuf
dfc759227a kmod/core: check force flag in replace case
When unpatching a function due to "kpatch replace", check the force flag
before doing the activeness safety check.
2014-07-09 15:06:57 -05:00
Josh Poimboeuf
57b51d0bdc add KPATCH_WARN_*_LINE macros
WARN macros are problematic because they embed the line number in an
instruction.  As a result, when a function is changed higher in a file,
the line numbers for any WARN calls below that function in the file can
result in unnecessarily changed functions.

These macros allow a patch author to hard code the line numbers in WARN
macros to prevent functions from otherwise changing and getting pulled
into a patch module unnecessarily.
2014-07-09 10:39:07 -05:00
Gaetan Trellu
dfa19166b3 README.md: add build-essential package 2014-07-08 13:25:29 -04:00
Gaetan Trellu
9dadc6ef2e README.md: add debian support 2014-07-08 13:21:47 -04: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
Josh Poimboeuf
6f38498d95 Merge pull request #299 from useidel/master
Rebase of SPEC file to current version
2014-07-07 21:09:54 -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
Seth Jennings
322b9b99ba Merge pull request #300 from jpoimboe/gcc-version-readelf
kpatch-build: extract GCC version from .comment section
2014-07-07 21:01:18 -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
Udo Seidel
5c7630ee76 Rebase of SPEC file to current version 2014-07-07 22:08:54 +02: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
Seth Jennings
690385a37d Merge pull request #294 from jpoimboe/custom-rpmbuild-dir
kpatch-build: support custom ~/.rpmmacros file
2014-07-03 09:22:52 -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
Josh Poimboeuf
11cac52533 Merge pull request #293 from spartacus06/support-forced-patching
support forced patching
2014-07-02 14:13:25 -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
Seth Jennings
6b428eec2f Merge pull request #291 from jpoimboe/gcc-ubuntu
kpatch-build: fix gcc version check on ubuntu
2014-07-02 08:35:19 -05:00
Josh Poimboeuf
dda01a5a1d Merge pull request #290 from goldyfruit/master
kpatch-build: use getconf to get the processors number
2014-07-02 06:21:12 -05:00
Josh Poimboeuf
5893a28fdf kpatch-build: fix gcc version check on ubuntu 2014-07-02 06:17:59 -05:00
Gaetan Trellu
9d72c76b1a kpatch-build: use getconf to get the processors number 2014-07-01 22:18:16 -04:00
Josh Poimboeuf
aaf1bf3e8e Merge pull request #288 from spartacus06/section-create-refactor
consolidate new section pair creation
2014-07-01 16:27:06 -05:00
Seth Jennings
1f17adec07 consolidate new section pair creation
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-07-01 16:00:51 -05:00
Seth Jennings
94ec430201 Merge pull request #286 from jpoimboe/check-gcc-version
kpatch-build: gcc version checks
2014-07-01 15:07:55 -05:00
Josh Poimboeuf
73171714bc kpatch-build: gcc version checks
Ensure the version of the locally installed gcc matches the one used to
compile the kernel, and is >= 4.8.

Fixes #246.
2014-07-01 14:24:53 -05:00
Seth Jennings
fd637ce542 Merge pull request #285 from goldyfruit/master
kpatch-build: add debian support
2014-07-01 14:02:57 -05:00
Gaetan Trellu
4e3b4825ad kpatch-build: merge the ubuntu and debian section 2014-07-01 14:41:57 -04:00
Josh Poimboeuf
df679e3192 Merge pull request #278 from spartacus06/user-hook-support-v2
add user-defined load/unload hook support
2014-07-01 13:09:33 -05:00
Seth Jennings
d4e4d14dbe fixup review comments
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-07-01 12:22:16 -05:00
Seth Jennings
1ebae501ba Merge pull request #283 from jpoimboe/mcount
create-diff-object: create __mcount_loc section
2014-07-01 11:10:59 -05:00
Josh Poimboeuf
d2201980e6 kmod/core: ftrace function_graph tracer compatibility
Steven Rostedt recommended to return "regs->ip + MCOUNT_INSN_SIZE",
which is what the function_graph tracer expects.  This fixes
function_graph tracing for a patched function.

This change also means that the function tracer will only show the
patched function once (corresponding to a trace of the original
function) rather than twice.  This is probably more in line with what a
user would expect.
2014-07-01 10:16:38 -05:00
Gaetan Trellu
d341e3237e kpatch-build: fix SUBLEVEL in the Makefile 2014-07-01 11:16:23 -04:00
Gaetan Trellu
0459810dd3 kpatch-build: add debian support 2014-07-01 10:55:43 -04:00
Seth Jennings
cae31c410b Merge pull request #284 from jpoimboe/ftrace-unregister-order
kmod/core: fix ftrace unregister order
2014-07-01 09:33:26 -05:00
Josh Poimboeuf
2dbae9ae42 kmod/core: fix ftrace unregister order
Currently, when removing a patch module, the ftrace buffer gets flooded
with traces.  This happens because we're clearing the ftrace ops filter
before unregistering the ops, which creates a small window where all
functions are being traced.

We should be doing the unregistering in the reverse order in which we
registered, meaning ops should be unregistered and _then_ the filter
should be cleared.
2014-07-01 08:52:59 -05:00
Josh Poimboeuf
79bd9f03ee create-diff-object: create __mcount_loc section
For ftrace to be able to trace a patched function, it requires that the
__mcount_loc section contains a pointer to the function, and that the
first instruction of the function is "callq __fentry__".

Normally that work is done by the recordmcount script, but it ignores
functions that aren't in a few standard sections (.text and a few
others).
2014-07-01 08:29:37 -05:00
Josh Poimboeuf
d3550bfc3a Merge pull request #282 from goldyfruit/master
core.c: add check to be sure that the kernel run with CONFIG_KALLSYMS_AL...
2014-06-30 21:28:19 -05:00
Gaetan Trellu
4a00442e1d core.c: add check to be sure that the kernel run with CONFIG_KALLSYMS_ALL option 2014-06-30 18:13:44 -04:00
Seth Jennings
26815a1ad9 Merge pull request #280 from jpoimboe/cache-rm-fix
kpatch-build: don't remove USERSRCDIR
2014-06-30 14:35:49 -05:00
Josh Poimboeuf
403cf65b89 kpatch-build: don't remove USERSRCDIR
Fixes #279.
2014-06-30 14:20:13 -05:00
Seth Jennings
4835e3edc3 add user-defined load/unload hook support
This commit enables the ability to create user-defined hooks as part of
the normal code patch that can do preparatory work for the application
of the patch.  This work could include, but is not limited to, changing
data structure semantics.

The user may define a new function as part of the patch and mark it as a
load-time or unload-time hook with the kpatch_load_hook() and
kpatch_unload_hook() macros.  These macros are in an include file that
gets copied into the source tree at include/linux/kpatch-hooks.h at
patch build time. The signature for both hooks is "int kpatch_unload_hook(void)".

For now, the return code is ignored.  The hooks may not fail.  They also
run in stop_machine() context and may not sleep.  These hooks, more or
less, must follow all the rules of interrupt context code.
2014-06-30 13:37:26 -05:00
Seth Jennings
e154296e0d Merge pull request #277 from jpoimboe/pr-err
kmod/core: use pr_err instead of printk
2014-06-29 23:23:33 -05:00
Josh Poimboeuf
b6541ab85b kmod/core: use pr_err instead of printk 2014-06-29 21:59:38 -05:00
Seth Jennings
faa37ffa2a Merge pull request #275 from jpoimboe/detect-printk-error
test: detect kernel oopses and warnings
2014-06-27 15:16:48 -05:00
Seth Jennings
37e0a1a705 Merge pull request #274 from jpoimboe/remove-test-printks
test: remove annoying printks
2014-06-27 15:16:20 -05:00
Josh Poimboeuf
f85c1c6f43 test: detect kernel oopses and warnings 2014-06-27 13:24:14 -05:00
Josh Poimboeuf
e8f396229d test: remove annoying printks
The printks in the integration tests aren't very useful and annoyingly
fill up the dmesg buffer.  Remove them by making them contingent on
unlikely conditions.
2014-06-27 13:15:02 -05:00
Seth Jennings
152bfee051 Merge pull request #273 from jpoimboe/detect-core-dump
kpatch-build: detect core dump
2014-06-27 12:16:51 -05:00