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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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.txtFixes#834.
Fixes: 495e619750 ("kpatch-build, x86: do not use the patched functions as callbacks directly")
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
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>
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>
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>
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>
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>
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>
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>
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
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.")
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.
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.
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.
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.
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
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.
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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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.
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>
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.
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.
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>
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.
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.
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>
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.
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>
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.
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.
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>