Commit Graph

229 Commits

Author SHA1 Message Date
Artem Savkov
80f78c78bb test/integration: skip -SLOW load tests in combined run
We are not including -SLOW patches into combined module, so there is no
reason to expect their -LOADED tests to succeed with combined module.
Skip them in run_combined_test().

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-08-23 09:23:50 +02:00
Artem Savkov
1a91e256ff test/integration: run -FAIL tests when invoked with --quick
Include -FAIL tests as well as combined in 'quick' target.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-08-23 09:23:30 +02:00
Artem Savkov
6cbf55d77b test/integration: include build log on failures
If a patch build fails copy the build log to <prefix>.log file.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-08-23 09:23:03 +02:00
Artem Savkov
41f025d392 Include mrecord-mcount unit tests
Update objs-repo pointer to include new unit tests.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-07-26 16:51:28 +02:00
Artem Savkov
7cb5baccde Include gcc8 unit-tests
Update submodule pointer to include new gcc8 unit tests.

This update also includes unit-test for https://github.com/dynup/kpatch/pull/892

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-07-13 09:39:26 +02:00
Joe Lawrence
37e4ae0c88
Merge pull request #875 from sm00th/unit-clean
unittests: skip clean if objdir is not present
2018-06-04 13:59:59 -04:00
Joe Lawrence
9bc7776b0f
Merge pull request #868 from joe-lawrence/kpatch-test-names
testing: kpatch-build should set all module names
2018-06-04 13:58:32 -04:00
Artem Savkov
b10e0b7d82 unittests: skip clean if objdir is not present
Don't try to call unittest clean if objfile dir is non-existant (e.g.
when objfile submodule wasn't cloned). Another solution would be to make
clean target dependant on objdir but that would mean downloading a lot
of unneeded data for users who don't run unit-tests.

Fixes: #872

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-06-04 13:14:28 +02:00
Joe Lawrence
7646c68b59 testing: kpatch-build should set all module names
Since c0105ea467 ("kpatch-build: set default module prefix
accordingly") kpatch-build has automatically named resulting patch
modules with a "kpatch-" or "livepatch-" prefix (depending on its type).

To avoid naming confusion, have kpatch-test name all of its patch
modules with a "test-" prefix.

Fixes #867.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2018-06-01 16:59:08 -04:00
Josh Poimboeuf
a7c413d4e9
Merge pull request #856 from sm00th/unlikely-cold
create-diff-object: ignore .cold.* suffixes in is_bundleable()
2018-05-31 09:25:28 -05:00
Artem Savkov
6c58f09cc7 test/unit: update objects to include cold testcase
Update unit test objects subrepo to include x86_64 gcc-constprop-cold
testcase.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-05-31 15:29:06 +02:00
Joe Lawrence
ace1e2cbf6
Merge pull request #849 from sm00th/cdo-symtab
create-diff-object symtab
2018-05-30 14:15:43 -04:00
Josh Poimboeuf
5736f18d83 test/unit: run submodule command from base git directory
This fixes the following error with an older version of git
(1.8.3.1):

  make -C test/unit
  make[1]: Entering directory `/root/kpatch/test/unit'
  git submodule update --init --rebase
  You need to run this command from the toplevel of the working tree.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-05-30 10:54:24 -05:00
Artem Savkov
3aa5abb807 kpatch-build: use symbol table instead of kobject
create-diff-object doesn't really need the full kernel object file as
input. All it requires is a symbol table. Switch to using "eu-readelf -s"'s
output instead of object files. This will enable us to cover more cases
in unit tests.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-05-18 09:24:40 +02:00
Artem Savkov
5f610fdda2 ppc64le: add WARN detection
ppc64le lacked kpatch_line_macro_change_only() implementation. Add one
based on x86_64 version and available unit tests.

Fixes: #843

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-05-04 16:32:48 +02:00
Artem Savkov
e0acd5f835 unittests: object submodule update
Update submodule to 6774fbc "ppc64le: initial object files"
Remove CDO_ENV since it is moved to per-arch makefiles.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-27 20:10:43 +02:00
Artem Savkov
ffc4122efb Add kpatch-unit-objs submodule
Add a submodule containing object files for unittests.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-26 18:49:29 +02:00
Artem Savkov
89a8ac740c Disable git-lfs
While convenient git-lfs has too many restrictions for kpatch's needs.
Remove links to the objectfiles and related configs.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-26 15:08:24 +02:00
Joe Lawrence
70959ce6ec
Merge pull request #838 from jpoimboe/test-cleanups
Test cleanups
2018-04-23 17:31:35 -04:00
Josh Poimboeuf
3feb694c91 test/unit: further silence non-verbose mode
Just show a summary of each test command in non-verbose mode.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-20 08:16:26 -05:00
Josh Poimboeuf
4c1184dcf7 test/unit: add a library for common functions
I placed the library in the top-level test directory, as the same
assertions could also be used by the integration tests once we rework
them a bit.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-20 08:16:20 -05:00
Josh Poimboeuf
d6dfa4a992 test/unit: test the number of patched functions
As an extra sanity check, ensure the number of patched functions never
changes.

Also added a test for convert-global-local to ensure the global symbol
is converted to a local.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:09 -05:00
Josh Poimboeuf
e16b4187a1 test/integration: remove obsolete tests
Cleaning house a bit.  Now that we have unit tests, a lot of these tests
aren't very useful anymore.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:09 -05:00
Josh Poimboeuf
5629d91bfe test/unit: add WARN test
Add a WARN detection test, based on the integration test of the same
name.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:09 -05:00
Josh Poimboeuf
8e315b42e0 test/integration: update WARN detection patch
Update the WARN detection patch to be based on net/core/dev.c, which is
a much better stress test.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:09 -05:00
Josh Poimboeuf
635754fc46 test/unit: add meminfo-string test
Copy the meminfo-string test from the integration tests.  It's a good
stress test for dynrelas.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:08 -05:00
Josh Poimboeuf
ff5bcc2fdc test/unit: broaden the 'clean' target
Broaden the impact of the 'clean' target so that output objects will
still get cleaned when when old tests get removed or renamed.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:08 -05:00
Josh Poimboeuf
af9f9f491c test: remove obsolete tests
After doing some research, I've discovered that most of these tests no
longer test what they were originally intended to test.

An exception here is the 'macro-hooks' test, which is probably better
suited as an integration test, so I removed its unit test and kept its
integration test.

Really, most of these tests weren't all that useful to begin with, so
it's not a big loss.  The one exception is 'gcc-static-local-var-2',
which was originally meant to test multiple static local variables with
the same name in the name function.  That's a good thing, so I'll try to
come up with another test for that which works with Linux 4.16.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:08 -05:00
Josh Poimboeuf
805b1f5d3f test/unit: fix 'new-fuction' test name typo
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:08 -05:00
Josh Poimboeuf
87939db272 create-diff-object: skip dynrelas for function pointers to new functions
With #755, we started using dynrelas for function pointers.  However,
this behavior only makes sense for function pointers to existing
functions.  For function pointers to *new* functions, just use a normal
rela.

The 'function-ptr-new' unit test is from the following patch:

  https://github.com/dynup/kpatch/files/1927198/new-static-callback.patch.txt

Fixes #834.

Fixes: 495e619750 ("kpatch-build, x86: do not use the patched functions as callbacks directly")
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 07:56:12 -05:00
Josh Poimboeuf
69ba464462 unit: don't suppress stderr in non-fail tests
Don't suppress stderr in the non-fail unit tests so that
create-diff-object error messages will be printed.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-18 08:03:25 -05:00
Artem Savkov
a0edfc1ded unittests: check that obj files are fetched
Check that tested .o is not an lfs meta-file before testing.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-13 18:11:50 +02:00
Artem Savkov
b9c56c475a uinttests: add strip check
Check that files are stripped of debuginfo as it is useless for
unittesting at this moment.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-13 18:11:17 +02:00
Artem Savkov
3ee81ec4ee x86_64: integration test objs
Populate x86_64 dir with objectfiles from integration test builds.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-13 18:10:34 +02:00
Artem Savkov
a05c644c7b Add create-diff-object unittest framework
Add a simple unittest framework for create-diff-object implemented in
GNU Make.
It will automatically scan the kpatch-unit-objs/$(uname -m) directory
for specifically named files running one of 3 tests:
  - creating diff object with expected success
  - creating diff object with expected failure
  - creating diff object and running a shell script on it with expected
  success

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-13 18:09:37 +02:00
Kamalesh Babulal
4d3363a975 Testcase: Clean up gcc-static-local-var-2
The test case gcc-static-local-var-2 doesn't uses any macros
from kpatch-macros.h, so remove the hunk including it.

Cc: Joe Lawrence <jdl1291@gmail.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2018-04-06 12:11:05 +05:30
Kamalesh Babulal
bfacf5d15c Testing: Add testcase for correlating static local variable
This patch adds a reproducer testcase for correlating static local
variables added in .rodata* section, ahead of .toc section. This
testcase is for issue seen on PowerPC. For more details on the issue
refer pull request: 793.

It add's the testcase for:
- Fedora-27 Kernel version 4.15.10-300
- Centos-7 Kernel version 3.10.0-693 and
- Ubuntu-16.04 Kernel version 4.13.0-25.29

Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2018-04-05 09:44:45 -05:00
Joe Lawrence
926e4e0c7d kmod: add support for in-kernel livepatch hooks
Upstream 4.15 kernels provide support for pre and post (un)patch
callbacks, inspired by the kpatch load hooks.  Add support for them
in the livepatch-patch-hook.

At the same time, convert the kpatch hooks to use the same API.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2018-03-23 10:32:14 -04:00
Joe Lawrence
1d942ebb41 testing: rebase patches for Fedora 27 4.13.9-300.fc27.x86_64
Rename the old Fedora 25 integration patch directory and rebase to
Fedora 27 sources.

Fixes #761.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2018-03-22 14:36:34 -04:00
Doug Goldstein
ff5c554a40
drop unused rpmdevtools dependency
It appears that since 0dec5136ee nothing
has been used from the rpmdevtools package by kpatch-build.

Signed-off-by: Doug Goldstein <cardoe@cardoe.com>
2018-03-21 15:15:08 -05:00
Artem Savkov
cedcd2314b Prepare for built-in.o -> built-in.a rename
for-next branch of kbuild repo contains a "kbuild: rename built-in.o to
built-in.a" which renames all built-in.o instances. Filter on both .o
and .a in kpatch-gcc/kpatch-build to be prepared for this change.

Fixes #800.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-03-20 10:46:50 +01:00
Joe Lawrence
eda8357743 testing: simplify combined integration test
Now that kpatch-build can accept multiple patches on the command line,
ditch the combinediff and associated logic in the integration test
script.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2017-09-25 09:17:07 -04:00
Joe Lawrence
2f8170e962 testing: rebase patches for CentOS 7.4 kernel-3.10.0-693.el7
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2017-09-22 17:02:33 -04:00
Jessica Yu
0bb5c106ef kmod: restructure kpatch sysfs tree
Restructure kpatch's sysfs interface and mirror the sysfs tree after
livepatch's sysfs layout. With the current sysfs layout, we cannot
distinguish which object a function belongs to, and we cannot tell which
modules/objects are patched. Therefore, restructure the kpatch sysfs tree
such that module/object information is available. With the new layout, each
patched object has its own directory, with each function being a
subdirectory of its object.

Implement this by embedding a kobject struct within the kpatch_module,
kpatch_func, and kpatch_object structs and supplying their ktypes and
kobject release methods.

Before:
/sys/kernel/kpatch
└── patches
    └── <patch_module>
        ├── checksum
        ├── enabled
        └── functions
            ├── <function>    # from <object1>
            │    ├── new_addr
            │    └── old_addr
            ├── <function>    # from <object2>
            │    ├── new_addr
            │    └── old_addr
            └─── <function>   # from <object3>
                 ├── new_addr
                 └── old_addr

After:
/sys/kernel/kpatch
└── <patch_module>
    ├── <object1>
    │   └── <function,sympos>
    │       ├── new_addr
    │       └── old_addr
    ├── <object2>
    │   └── <function,sympos>
    │       ├── new_addr
    │       └── old_addr
    ├── checksum
    ├── enabled
    └── <object3>
        └── <function,sympos>
            ├── new_addr
            └── old_addr
2017-02-27 20:07:16 -08:00
Joe Lawrence
9a786313e0 testing - rebase for integration tests for Fedora 25
Kernel version 4.9.7-201.fc25.x86_64
2017-02-09 15:41:41 -05:00
Joe Lawrence
3215c4ff2f testing: remove extra '}' from run_custom_test's prefix variable
Fixes: #664.
2017-01-26 11:06:02 -05:00
Josh Poimboeuf
ac899455ab create-diff-object: convert global symbols to local
As reported in PR #658, when patching an exported function which is used
by the patch module init code, the init code will incorrectly link to
the patched version of the function and will call the patched function
before its relocations have been applied.

For example, when patching __kmalloc(), I see:

  # insmod kpatch-kmalloc.ko
  kpatch_kmalloc: module is marked as livepatch module, but livepatch support is disabled
  kernel tried to execute NX-protected page - exploit attempt? (uid: 0)
  BUG: unable to handle kernel paging request at ffffc90001d03c58
  IP: 0xffffc90001d03c58
  PGD 7c8b4067
  PUD 7c8b5067
  PMD 755f7067
  PTE 800000007ad03163
  Oops: 0011 [#1] PREEMPT SMP
  Modules linked in: kpatch_kmalloc(OE+) kpatch(OE) ip6t_rpfilter ip6t_REJECT nf_reject_ipv6 xt_conntrack cfg80211 rfkill ebtable_nat ebtable_broute bridge stp llc ebtable_filter ebtables ip6table_nat nf_conntrack_ipv6 nf_defrag_ipv6 nf_nat_ipv6 ip6table_mangle ip6table_security ip6table_raw ip6table_filter ip6_tables iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack iptable_mangle iptable_security iptable_raw snd_hda_codec_generic ppdev crct10dif_pclmul crc32_pclmul crc32c_intel ghash_clmulni_intel snd_hda_intel virtio_balloon snd_hda_codec snd_hwdep serio_raw virtio_console snd_hda_core parport_pc parport snd_pcm virtio_net snd_timer snd i2c_piix4 soundcore virtio_blk qxl drm_kms_helper ttm drm virtio_pci virtio_ring virtio ata_generic pata_acpi
  CPU: 1 PID: 1042 Comm: insmod Tainted: G           OE   4.10.0-rc5 #1
  Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.9.1-1.fc24 04/01/2014
  task: ffff88007560d480 task.stack: ffffc90001d00000
  RIP: 0010:0xffffc90001d03c58
  RSP: 0018:ffffc90001d03c50 EFLAGS: 00010286
  RAX: 0000000000000004 RBX: 0000000000000008 RCX: 0000000000000000
  RDX: 0000000000000000 RSI: 00000000014080c0 RDI: 0000000000000008
  RBP: ffff88007ad00058 R08: 0000000000000001 R09: 0000000000000001
  R10: 0000000000000000 R11: 0000000000000001 R12: 00000000fffffff4
  R13: ffffffffa0394ef0 R14: 0000000000000000 R15: ffffc90001d03ea8
  FS:  00007f9689d74700(0000) GS:ffff88007d000000(0000) knlGS:0000000000000000
  CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
  CR2: ffffc90001d03c58 CR3: 000000007af1d000 CR4: 00000000001406e0
  Call Trace:
   ? kzalloc.constprop.6+0xe/0x10 [kpatch_kmalloc]
   ? patch_init+0xa6/0x1000 [kpatch_kmalloc]
   ? 0xffffffffa0399000
   ? do_one_initcall+0x52/0x1b0
   ? do_init_module+0x27/0x1fa
   ? rcu_read_lock_sched_held+0x4a/0x80
   ? kmem_cache_alloc_trace+0x28a/0x2f0
   ? do_init_module+0x5f/0x1fa
   ? load_module+0x2446/0x2b90
   ? __symbol_put+0x90/0x90
   ? vfs_read+0x137/0x180
   ? SYSC_finit_module+0xdf/0x110
   ? SyS_finit_module+0xe/0x10
   ? entry_SYSCALL_64_fastpath+0x1f/0xc2
  Code: c9 ff ff 10 00 00 00 00 00 00 00 86 02 01 00 00 00 00 00 50 3c d0 01 00 c9 ff ff 18 00 00 00 00 00 00 00 b4 33 39 a0 ff ff ff ff <a0> 3c d0 01 00 c9 ff ff a6 90 39 a0 ff ff ff ff 00 00 00 00 00
  RIP: 0xffffc90001d03c58 RSP: ffffc90001d03c50
  CR2: ffffc90001d03c58
2017-01-23 15:50:13 -06:00
Joe Lawrence
97be7f57fb testing: add full path for /sbin executables
"/sbin" might not be in the user's path, so prefix callouts to such
utilities with their full path.
2017-01-13 13:54:35 -05:00
Joe Lawrence
f7b59ca809 testing: skip combined test for a single patch
If kpatch-test processes a single .patch file, it will skip creating a
COMBINED.patch.

Do the same on the testing side (instead of complaining that it "can't
find kpatch-COMBINED.ko, skipping.")
2017-01-13 13:54:35 -05:00
Joe Lawrence
1096da7155 testing: handle empty glob cases
If kpatch-test looks for *.patch or *.test globs in a directory that
contains no such files, it will try to handle a single file named
"*.patch" or "*.test".

Set the global nullglob option to avoid this problem.  At the same time,
stop and whine to the user if no .patch files were found.
2017-01-13 13:54:04 -05:00
Joe Lawrence
6ee3c0f8fa testing: add a PATCHES_LIST to kpatch-test
Instead of building *.patch, allow the user to specify patch files on
the command line.  For example:

  kpatch-test --quick centos-7/cmdline-string.patch centos-7/data-new.patch

Update the top-level Makefile as well, so it can be similarly invoked:

  PATCHES="centos-7/cmdline-string.patch centos-7/data-new.patch" make quick

If no patches are specified on the kpatch-test command line, then fall
back to the previous behavior of *.patch.

NOTE: If patches *are* specified, then only the .test files
corresponding to those patches will be executed.  Provided patch paths
will also override any --directory value.
2016-12-16 16:18:19 -05:00
Joe Lawrence
5db4e232ee testing: use common Makefile
Move the integration tests Makefile up a directory level so that it can
be shared.  Update the kpatch-test script to accept a patch-directory
argument and the multiple.test cases to handle this new arrangement.
2016-12-16 16:16:30 -05:00
Joe Lawrence
b6692c14d7 testing: add and rebase integration tests for Ubuntu 16
Kernel version: 4.4.0-53-generic
2016-12-16 16:06:49 -05:00
Joe Lawrence
11ce8102c2 testing: add and rebase integration tests for CentOS 7
Kernel version: 3.10.0-327.36.3.el7.x86_64
2016-12-16 16:06:28 -05:00
Joe Lawrence
d7bcd38787 testing: rebase integration tests for Fedora 25
Kernel version 4.8.6-300.fc25.x86_64
2016-12-16 16:06:15 -05:00
Joe Lawrence
1592c5a711 testing: move integration test patches directory
Prepare for updating the integration tests and move into a standard path
(this should be easier for future automation).

The patch directory name(s) should be in the form ${ID}-${VERSION_ID}/
as defined by the target's /etc/os-release.
2016-12-16 16:05:59 -05:00
Joe Lawrence
33ac7db028 testing: add rebase_patches tool 2016-12-16 16:05:06 -05:00
Josh Poimboeuf
353f976312 test: integration test cleanup
- fix kpatch tool path in multiple.test
- remove "kpatch replace" tests (replace is deprecated)
2015-10-30 16:47:34 -05:00
Josh Poimboeuf
aa9f7fb1f6 test: add ability to run tests remotely
Create a "make remote" target and a poor man's ansible to allow setting
up a remote F22 system and running integration tests on it.

To run tests remotely:

  make remote SSH_HOST=my.remote.f22.box
2015-10-26 22:35:40 -05:00
Josh Poimboeuf
69b241ab38 test: fix ccache
For some reason CCACHE_HASHDIR needs to be unset for ccache to work when
building the integration tests from the kpatch-test script.
2015-10-26 22:35:40 -05:00
Josh Poimboeuf
3d46973c40 test: fix patches
Update the integration test patches so that they apply against the F22
kernel.
2015-10-26 21:09:19 -05:00
Josh Poimboeuf
8dc6a4dd3c test: move tests to f22 directory
The integration tests are targeted for Fedora kernels, so move them to a
new f22 directory.  The README file specifies the exact kernel version
they're targeted for.
2015-10-26 21:09:19 -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
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
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
Seth Jennings
8e9aa2b559 Merge pull request #448 from jpoimboe/static-local-fixes
improve static local variable correlation
2014-10-06 23:56:24 -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
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
7876ce4aae test: make sure TMP.patch is cleaned up 2014-10-06 14:42:34 -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
36150a8beb fix integration test patch conflict 2014-10-06 12:42:45 -05:00
Seth Jennings
6175658196 Merge pull request #441 from jpoimboe/module-shadow
allow shadow functions to be called from modules
2014-10-02 23:22:26 -05:00
Josh Poimboeuf
ea445c0333 allow shadow functions to be called from modules
Fixes an issue where attempting to call the shadow functions from a
module results in modpost failures:

    ERROR: "kpatch_shadow_get" [net/mac80211/mac80211.ko] undefined!
    ERROR: "kpatch_shadow_alloc" [net/mac80211/mac80211.ko] undefined!

LDFLAGS_MODULE is apparently not really needed.
2014-10-02 13:31:48 -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
Josh Poimboeuf
b295c8686e test: improve macro-hooks patch
Restore aio_max_nr to its original value when unloading.

Also move the location of the patch hunk to be not at the end of the
file.  Otherwise we hit a weird combinediff bug which results in the
diff's context being removed.
2014-10-01 11:11:54 -05:00
Josh Poimboeuf
1ee3ae669f test: add slow test for rebuilding entire tree
Only gets run with the slow integration tests, not "make quick".
2014-09-15 14:54:59 -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
dacdfcfd22 fix test conflict
I accidentally added two tests which both create a non-static
kpatch_foo() function, which breaks the combined integration test kernel
build.
2014-09-12 13:12:36 -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
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
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
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
Seth Jennings
c21cc1292f Merge pull request #398 from flaming-toast/patch-reenable
re-enable forced patch modules
2014-09-09 12:05:30 -05:00
Jessica Yu
8f06a11962 testmod/doit.sh: add .kpatch.checksum to test module 2014-09-09 07:52:41 -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
Seth Jennings
4506a9575e add test case for new globals inclusion
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-09-03 17:06:50 -05:00
Josh Poimboeuf
aca9b52567 add test case for issue #394. 2014-09-03 10:10:07 -05:00
Josh Poimboeuf
543ad11ccd create-diff-object: allow new data to be included
Allow the inclusion of new global variables.
2014-08-14 01:12:27 -05:00
Josh Poimboeuf
eb62038e92 test: add hook macro test
From issue #357.
2014-08-13 14:24:18 -05:00
Seth Jennings
a59607742e add difftest.sh test
The purpose of this test script is to determine if create-diff-object
can properly recognize object file equivalence when passed the same file
for both the original and patched objects.  This verifies that
create-diff-object is correctly parsing, correlating, and comparing the
different elements of the object file.  In practice, a situation similar
to the test case occurs when a commonly included header file changes,
causing Make to rebuild many objects that have no functional change.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-08-12 10:50:46 -05:00
Jessica Yu
6933181c12 test/testmod/doit.sh: set KBUILD_EXTRA_SYMBOLS to include core module
symbols
2014-08-05 18:51:47 -07:00
Josh Poimboeuf
e2f706877d test: add KPATCH_PRINTK test 2014-08-04 17:03:23 -05:00
Josh Poimboeuf
9c3c9b0c0a support for gcc static local variable renaming
gcc renames static local variables by appending a period and a number.
For example, __key could be renamed to __key.31452.  Unfortunately this
number can arbitrarily change.  Try to rename the patched version of the
symbol to match the base version and then correlate them.

Fixes #313.
2014-07-24 15:08:15 -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
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
Josh Poimboeuf
2362d44783 create-diff-object: include new functions 2014-06-25 16:46:08 -05:00
Seth Jennings
88cac305be Merge pull request #230 from jpoimboe/isra
create-diff-object: support gcc function name mangling
2014-06-03 12:22:39 -05:00
Josh Poimboeuf
72e260f50c create-diff-object: support gcc function name mangling
Fixes #189.
Fixes #228.
2014-06-03 11:26:03 -05:00
Seth Jennings
5b62d5f169 add module for testing module patching
A simple kernel module for testing basic kernel module patching.

Just run doit.sh from test/testmod.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-06-02 20:34:38 -05:00
Josh Poimboeuf
401680a7c9 create-diff-object: tracepoint & jump label fixes
The current approach of trying to include the tracepoint-related
sections doesn't work at all.  The new tracepoints don't show up in
"perf list".

And also, with one patch (issue #219) I've seen a panic in
jump_label_del_module().  I suspect it's because the kernel is confused
by dynamic relocations' changing of the jump table after it was
registered with the jump table code.

I think the best approach for now is to just always exclude these
sections.  It should be harmless, with the only consequence being that
tracepoints and jump labels can't be enabled in patched functions (which
is already the case with the current code anyway).

Fixes #221.
2014-05-30 15:20:08 -05:00
Josh Poimboeuf
92a4ca2621 create-diff-object: support tracepoints and related sections
Add support for the following special sections:

- __jump_table
- __tracepoints
- __tracepoints_ptrs
- __tracepoints_strings

Fixes #157.
2014-05-27 12:47:45 -05:00
Josh Poimboeuf
698cc1c137 create-diff-object: support fixup and related sections
Add support for the following sections:

- .fixup
- __ex_table
- .altinstructions
- .altinstr_replacement

Fixes #187.
2014-05-27 12:47:45 -05:00
Josh Poimboeuf
6aee215b04 Merge pull request #213 from jpoimboe/test-combined
test: add much quicker combined test option
2014-05-27 09:51:57 -05:00
Josh Poimboeuf
d7f209f838 test: add much quicker combined test option
Combine all the patch modules into a single kpatch-COMBINED.ko for a
much quicker test which still gives 95% or so of the coverage compared
to the full test suite.  Use "make quick" for use this new option.
2014-05-27 09:40:24 -05:00
Seth Jennings
be4ee611c1 remove inventory based testing
The inventory based testing for create-diff-object was introduced at a
time when create-diff-object only needed the two object files to operate.
Now, it requires vmlinux as well.  This makes the inventory testing (a
unit testing framework for create-diff-object) obsolete and difficult to
update in it's current form.

This commit removes the inventory test framework.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-05-26 16:51:53 -05:00
Josh Poimboeuf
b143442916 test: tell user to check test.log on error 2014-05-20 14:34:11 -05:00
Josh Poimboeuf
ecfed91904 test: add basic tests for special sections
One of the tests is now failing:

    ERROR: smp-locks-section: kpatch replace failed

I suspect the issue is the vmlinux mismatch problem.  Fix for that
coming soon.
2014-05-15 17:14:25 -05:00
Josh Poimboeuf
707afe238c test: add make targets 2014-05-15 16:24:33 -05:00
Josh Poimboeuf
c7d3c5d86c test: do load/unload testing for modules that don't have tests
Do some basic load/unload tests for all the test modules, even if they
don't have a corresponding -LOADED.test file.
2014-05-15 16:22:45 -05:00
Seth Jennings
08dbc37c75 add null symbol to inventory files
Add the null symbol to in inventory files.  Before the linked-link
change, the null symbol wasn't included in the inventory.  However,
it is required to be a valid ELF file and should be inventoried and
check for in the test.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-05-07 10:16:39 -05:00
Josh Poimboeuf
b541692061 test: add test for loading multiple modules 2014-05-05 20:03:57 -05:00
Josh Poimboeuf
1fced0bc3d test: fix unload_all 2014-05-05 20:03:57 -05:00
Josh Poimboeuf
df2e2daa92 test: send status messages to log file 2014-05-05 20:03:54 -05:00
Josh Poimboeuf
100f358b1d test: fix custom test error condition check 2014-05-05 17:05:49 -05:00
Josh Poimboeuf
bcbc9d3109 test: make .init sections can't be changed 2014-05-05 17:05:49 -05:00
Josh Poimboeuf
7c60dcf2a3 test: make output messages easier to read 2014-05-05 17:05:49 -05:00
Josh Poimboeuf
46786dad93 test: add custom test for kpatch replace 2014-05-05 17:05:44 -05:00
Josh Poimboeuf
757120d8a0 test: add meminfo-cmdline test 2014-05-05 16:05:00 -05:00
Josh Poimboeuf
a0c9aff4cc test: fix uninitialized skip variable 2014-05-05 16:05:00 -05:00
Josh Poimboeuf
3ae6bc46ff test: add cmdline-string test 2014-05-05 16:05:00 -05:00
Josh Poimboeuf
d3aee7c734 test: test 'kpatch reload' and cleanup between tests 2014-05-05 16:04:58 -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
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
Seth Jennings
0cbb7cf5ee add automated testing system
This commit introduces a simple automated testing system
with 3 simple testcase.

For each test case there is a .c, a .patch, and a .inventory
file.  The .c is compiled, using the flags from the kflags file,
to create the original object.  The .c file is then patched
with the .patch file and rebuilt to create the patched object.
The files are then analyzed by the differencing tool and an
output object is generated with a .inventory file that lists
the sections and symbol included in the output object.  That
inventory file is then compared to the .inventory file for
that testcase.  If they are the same, the test passes. If
not, the differences in the inventory files are displayed,
and the test fails.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-10 14:36:11 -05:00