Commit Graph

1119 Commits

Author SHA1 Message Date
Josh Poimboeuf
c56c411b2a kmod/core: TAINT_USER -> TAINT_LIVEPATCH
Ok, technically it's not livepatch.  But it's close enough, and more
accurate than TAINT_USER.
2016-04-14 16:28:49 -05:00
Jessica Yu
d2d1f639b2 Merge pull request #590 from euspectre/paravirt-alt-reloc-fix
kmod/core: Skip relocations of already altered instructions
2016-04-11 10:41:37 -07:00
Evgenii Shatokhin
8dac9d0871 kmod/core: Skip relocations of already altered instructions
When a patch module is loaded, the kernel facilities like alternatives
and paravirt may alter some of its instructions. This happens before
Kpatch core module is notified and tries to apply dynrelas to it. If an
instruction to apply a dynrela to has already been changed by these
facilities, an incorrect instruction might be written as a result.

The core module now detects such conditions and does not apply dynrela
to the changed instructions.

Suggested by Josh Poimboeuf in the discussion of
https://github.com/dynup/kpatch/issues/580.

Changes in v.2:
* Used pr_notice to give more emphasis to the messages.
* Added an explanation message.

Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
2016-04-11 15:11:35 +03:00
Jessica Yu
7eda8dab6d Merge pull request #588 from euspectre/kpatch-service-enable0
contrib/service: allow to turn the service off at boot time
2016-04-05 15:18:15 -07:00
Evgenii Shatokhin
20eddbac0c contrib/service: allow to turn the service off at boot time
It may be convenient to be able to turn off the automatic loading of
the patches that kpatch.service does. This helps, for example, if a
buggy patch is installed and crashes the system at boot.

This commit allows to specify kpatch.enable=0 in the kernel command
line. In this case, the binary patches will not be loaded automatically,
and the users should be able to remove or replace the offending patches
after the system boots.

Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
2016-04-04 16:52:40 +03:00
Jessica Yu
b156a786a6 Merge pull request #583 from euspectre/kpatch-build-livepatch-fix
kpatch-build: fix building of livepatch-based patches
2016-03-22 09:40:28 -07:00
Evgenii Shatokhin
6a76da9236 kpatch-build: fix building of livepatch-based patches
kpatch-build currently requires Module.symvers for the Kpatch core
module unconditionally and fails if it is not found. This does not allow
using kpatch-build to prepare livepatch-based patches.

This patch fixes the problem.

Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
2016-03-22 16:14:07 +03:00
Jessica Yu
f80c2cf47e Merge pull request #582 from libin2015/process-the-patch-name
kpatch-build: process the patch name correctly
2016-03-01 15:30:36 -08:00
Li Bin
441ab87643 kpatch-build: process the patch name correctly
Process the patch name correctly that only concern the fuffix with
.patch or .diff. Otherwise if the patch name is not end with .patch
or .diff but has it as substring, the fuffix will be removed
unreasonably.

Signed-off-by: Li Bin <huawei.libin@huawei.com>
2016-02-27 11:24:27 +08:00
Josh Poimboeuf
706b63ad99 Merge pull request #581 from jpoimboe/new-version
bump version to 0.3.2
2016-02-17 15:37:18 -06:00
Josh Poimboeuf
a24b13cfb1 bump version to 0.3.2 2016-02-17 15:36:40 -06:00
Josh Poimboeuf
c85bb50ff7 Merge pull request #579 from flaming-toast/core_fix
kmod: core: use new module core_layout struct
2016-02-17 15:34:37 -06:00
Jessica Yu
85a055665e kmod: core: use new module core_layout struct
Commit 7523e4dc5057 upstream ("module: use a structure to encapsulate
layout") uses a new field to access module memory. Account for this change
and ensure backwards compatibility with kernel versions < 4.5
2016-02-17 13:13:46 -08:00
Josh Poimboeuf
83beb356ed Merge pull request #573 from arges/493
livepatch-patch-hook: add support for livepatch sympos structures
2016-02-17 08:57:06 -06:00
Chris J Arges
b64ab2b5e4 livepatch-patch-hook: add support for livepatch sympos
Support patching objects that have duplicated function names. This feature was
introduced upstream in Linux v4.5.

This patch appends the symbol position to the symbol structure when
lookup_local_symbol is called. This pos variable is then used when creating the
funcs and dynrelas sections. Finally, incorporate sympos into the livepatch
patch hook only if the kernel version is greater than v4.5. In other cases the
older format is used.

Fixes: #493

Signed-off-by: Chris J Arges <chris.j.arges@canonical.com>
2016-02-16 10:31:44 -06:00
Jessica Yu
08f55afa0a Merge pull request #575 from arges/packaging
Changes to make packaging easier
2016-02-10 12:12:45 -08:00
Chris J Arges
e9b9654602 Makefile: add BUILDMOD parameter to select building kmod core
In some cases when packaging it may not be useful to build kmod/core at
package build time (for example if using DKMS). Add a parameter 'BUILDMOD'
that when set to 'yes' will build kmod/core.

Signed-off-by: Chris J Arges <chris.j.arges@canonical.com>
2016-02-10 09:55:45 -06:00
Chris J Arges
3c8f5f7bfa Makefile: determine kernel release in Makefile
Don't assume we are building for the current kernel. In addition print out
a proper package necessary for building the module.

Signed-off-by: Chris J Arges <chris.j.arges@canonical.com>
2016-02-10 09:46:38 -06:00
Chris J Arges
06ad01b784 Makefile: make libexec a parameter
Some distributions prefer not to use /usr/libexec. To make things easier
for packaging, allow this directory to be set easily via environment
variables.

Signed-off-by: Chris J Arges <chris.j.arges@canonical.com>
2016-01-12 20:12:59 -06:00
Chris J Arges
053622b902 kpatch-build: allow external LDFLAGS
When building binaries such as create-diff-object it would be useful
to be able to pass LDFLAGS when running make from the command line.
2016-01-11 14:26:50 -06:00
Seth Jennings
b8c224c6c0 Merge pull request #569 from terrywang/fedora-23
readme: add support for Fedora 23
2015-12-07 09:11:27 -06:00
Terry Wang
580acabdc0 readme: update Fedora support information 2015-12-05 00:07:52 +11:00
Terry Wang
85c5cc224f readme: remove out-dated Fedora 21 2015-12-01 13:58:49 +11:00
Terry Wang
701e5c0a34 readme: add support for Fedora 23 2015-11-26 23:59:55 +11:00
Seth Jennings
b60d3acddb Merge pull request #560 from euspectre/get-kernel-version
Get kernel version from vmlinux if the kernel source tree is used
2015-11-18 15:28:42 -06:00
Seth Jennings
b781c0a843 Merge pull request #564 from jpoimboe/more-static-fixes
create-diff-object: static local uncorrelation/correlation fixes
2015-11-18 15:15:27 -06:00
Josh Poimboeuf
792a4fc537 Merge pull request #563 from jpoimboe/gcc-check
revert gcc check changes
2015-11-18 15:13:30 -06:00
Josh Poimboeuf
02d3c193ed create-diff-object: static local uncorrelation/correlation fixes
The uncorrelation logic is incomplete.  For bundled symbols, in addition
to uncorrelating the sections, it should also uncorrelate the section
symbols and any rela sections.

Similarly the correlation logic needs to correlate section symbols.  (It
already correlates rela sections.)
2015-11-18 14:56:02 -06:00
Josh Poimboeuf
707435ec62 Revert "kpatch-build: fix gcc_version_check"
This reverts commit 9fedd0d283.
2015-11-18 14:44:45 -06:00
Josh Poimboeuf
7b48c4ce12 Revert "kpatch-build: fix gcc_version_check: both "GNU" and "GCC" are possible"
This reverts commit 5737028667.
2015-11-18 14:44:26 -06:00
Josh Poimboeuf
f4b5eded0c Merge pull request #561 from euspectre/gcc-gnu-fix
kpatch-build: fix gcc_version_check: both "GNU" and "GCC" are possible
2015-11-18 10:28:18 -06:00
Josh Poimboeuf
129fb4a22b Merge pull request #551 from libin2015/reduce-dependency-on-bash-version
kpatch-build: reduce dependency on bash version >4.0
2015-11-17 08:35:52 -06:00
Evgenii Shatokhin
e169d82192 kpatch-build: get kernel version from vmlinux if source tree is used
If a kernel SRPM is used to get the kernel sources, the target kernel
version is determined from the name of the SRPM.

One cannot obtain the target kernel version this way if the source tree
is used instead of an SRPM, so let us extract that information from
vmlinux.

Signed-off-by: Evgenii Shatokhin <eshatokhin@odin.com>
2015-11-17 16:41:16 +03:00
Evgenii Shatokhin
5737028667 kpatch-build: fix gcc_version_check: both "GNU" and "GCC" are possible
This fix is an addition to 9fedd0d283 "kpatch-build: fix
gcc_version_check".

On some systems, the GCC version stored in vmlinux may have the
following format:
  (GNU) 4.8.3 20140911 (Red Hat 4.8.3-9)
while GCC returns
  (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9)

As a result, binary patches cannot be built, although the compiler is
the same.

gcc_version_check() now takes this into account.

Signed-off-by: Evgenii Shatokhin <eshatokhin@odin.com>
2015-11-17 16:25:28 +03:00
Seth Jennings
f152d00a62 Merge pull request #559 from jpoimboe/patch-author-guide
doc: patch author guide, first take
2015-11-16 15:27:34 -06:00
Josh Poimboeuf
85b7a76acc doc: patch author guide, first take
Been wanting to write this forever, have to start somewhere...
2015-11-16 15:23:16 -06:00
Seth Jennings
f8d00bd232 Merge pull request #550 from libin2015/fix-find-parent-obj
kpatch-build: fix find_parent_obj
2015-11-16 13:29:35 -06:00
Seth Jennings
3d49e37f11 Merge pull request #548 from libin2015/fix-gcc-version-check
kpatch-build: fix gcc_version_check
2015-11-16 13:15:41 -06:00
Seth Jennings
aab5240df8 Merge pull request #555 from jpoimboe/static
create-diff-object: more static local variable rework
2015-11-16 11:55:36 -06:00
Seth Jennings
c7fd8673e9 Merge pull request #554 from jpoimboe/section-sym-gah
create-diff-object: handle reference to end of section
2015-11-16 10:37:32 -06:00
Seth Jennings
232b2a108d Merge pull request #549 from jpoimboe/trap-sighup
kpatch-build: cleanup on SIGHUP
2015-11-16 09:49:21 -06:00
Seth Jennings
c4967bc02b Merge pull request #557 from jpoimboe/deprecate-replace
kpatch: deprecate the replace command
2015-11-16 09:48:55 -06:00
Josh Poimboeuf
8e8de4718d kpatch: deprecate the replace command
"kpatch replace" is complex, buggy, and probably unnecessary.  And
upstream livepatch has nothing like it.

Remove it from the kpatch utility, but leave the infrastructure in place
in the patch module and the core module for now.

Fixes: #456
2015-11-16 09:38:44 -06:00
Josh Poimboeuf
fffbb85b81 create-diff-object: handle reference to end of section
Deal with a special case where gcc needs a pointer to the address at the end of
a data section.

This is usually used with a compare instruction to determine when to end a
loop.  The code doesn't actually dereference the pointer so this is "normal"
and we just replace the section reference with a reference to the last symbol
in the section.

Note that this only catches the issue when it happens at the end of a section.
It can also happen in the middle of a section.  In that case, the wrong symbol
will be associated with the reference.  But that's ok because:

1) This situation only occurs when gcc is trying to get the address of the
   symbol, not the contents of its data; and

2) Because kpatch doesn't allow data sections to change, &(var1+sizeof(var1))
   will always be the same as &var2.

Fixes: #553
2015-11-13 16:42:40 -06:00
Josh Poimboeuf
ac9020af20 create-diff-object: more static local variable rework
Refine the static local variable handling again.  This builds on a
previous patch by Zhou Chengming.

This fixes the following bugs reported by Zhou:

1.          xxx.123 ---> xxx.123 (previous correlation by coincidence)
            xxx.256 ---> xxx.256 (previous correlation by coincidence)
   But real xxx.123 ---> xxx.256

   In this case, the code doesn't work. Because when find patched_sym for
   xxx.123, the xxx.256 in patched_object hasn't been de-correlated.

2. old-object | new-object
        func1 | func1
      xxx.123 | xxx.123 (inline)
        func2 | func2
      xxx.256 | xxx.256
      xxx.123 | xxx.123 (inline)

   When find patched_sym for xxx.123, first find xxx.123 in func1 of new-object,
   But then find xxx.256 in func2 of new-object.
   So I think should not iterate the base-sections, when find one, just go out to next symbol.

Both of these problems can be fixed by splitting the code up into
multiple passes:

  1. uncorrelate all static locals
  2. correlate all static locals
  3. ensure each static local is referenced by all the same sections in
     both objects
  4. print warning on any new static locals

Fixes: #545
2015-11-13 13:56:13 -06:00
Li Bin
273ea9a06c kpatch-build: reduce dependency on bash version >4.0
Before this patch, kpatch_build dependends on bash version >4.0
that support declare -A. This patch remove this dependency by
replacing dict(declare -A) with array.

Signed-off-by: Li Bin <huawei.libin@huawei.com>
2015-11-13 17:13:39 +08:00
Li Bin
9143e88f16 kpatch-build: fix find_parent_obj
When find kobj, it should use 'cat changed_objs' to get the changed
objects, in order to process the following object format:
a/b/c/../../object.o. If using patched dir to get changed object,
the object will be a/object.o, but it is a/b/c/../../object.o in
*.cmd file.
This patch also fix the find_parent_obj that change the format
'a/b/c/../../object.o' to 'a/object.o' in deep find, otherwise
it will fail with "two parent matches for *.o".

Signed-off-by: Li Bin <huawei.libin@huawei.com>
2015-11-13 14:24:37 +08:00
Josh Poimboeuf
d529091f3b kpatch-build: cleanup on SIGHUP
Fix an issue where kpatch-build fails to clean up after hitting CTRL-C
during a remote integration test (make remote).
2015-11-12 20:39:14 -06:00
Li Bin
9fedd0d283 kpatch-build: fix gcc_version_check
gcc version string format may be 'gcc (xxx xxx) x.x.x [xxx]'
fix gcc_version_check to adapt to it.

Signed-off-by: Li Bin <huawei.libin@huawei.com>
2015-11-13 08:19:50 +08:00
Seth Jennings
eb54876936 Merge pull request #544 from jpoimboe/ronx-crash
kmod/core: fix crash with !CONFIG_DEBUG_SET_MODULE_RONX
2015-11-04 13:51:12 -06:00