Skip to content

Commit 70422e7

Browse files
committed
x86: add module symbol import test
Symbol namespace imports end up as "import_ns=<value>" strings inside the ELF .modinfo section. If a kpatch needs to import a namespace, it may result in a modified .modinfo section that kpatch-build needs to carefully handle: the string is extracted from the patched ELF object and saved in the output ELF object .modinfo section. Add a test that verifies that four namespaces are successfully re-imported by create-diff-object. The following patch produced the import-ns.{ORIG,PATCHED}.o files: diff -Nupr src.orig/fs/proc/cmdline.c src/fs/proc/cmdline.c --- src.orig/fs/proc/cmdline.c 2022-10-24 15:41:08.858760066 -0400 +++ src/fs/proc/cmdline.c 2022-10-24 15:41:11.698715352 -0400 @@ -4,10 +4,23 @@ #include <linux/proc_fs.h> #include <linux/seq_file.h> +#include <linux/module.h> + +MODULE_IMPORT_NS(DMA_BUF); +MODULE_IMPORT_NS(DEVMEM); +MODULE_IMPORT_NS(KPATCH_TEST); /* dummy import to inflate .modinfo */ +MODULE_IMPORT_NS(KPATCH_TEST2); /* dummy import to inflate .modinfo */ +extern void dma_buf_export(void *); +extern int cpu_cache_invalidate_memregion(int); + static int cmdline_proc_show(struct seq_file *m, void *v) { - seq_puts(m, saved_command_line); - seq_putc(m, '\n'); + seq_printf(m, "%s kpatch=1\n", saved_command_line); + + /* test namespace import */ + pr_info("dma_buf_export=%pK", dma_buf_export); + pr_info("cpu_cache_invalidate_memregion=%pK", cpu_cache_invalidate_memregion); + return 0; } Signed-off-by: Joe Lawrence <[email protected]>
1 parent a51c80a commit 70422e7

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

x86_64/import-ns.ORIG.o

4.05 KB
Binary file not shown.

x86_64/import-ns.PATCHED.o

6.13 KB
Binary file not shown.

x86_64/import-ns.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
source $KPATCH_TEST_LIBRARY
3+
4+
TESTFILE=$(basename "$0")
5+
OUTFILE=${TESTFILE%.test}.OUTPUT.o
6+
7+
# Verify there are four namespace imports in the resulting .modinfo section, e.g.
8+
#
9+
# String dump of section '.modinfo':
10+
# [ 0] import_ns=KPATCH_TEST2
11+
# [ 17] import_ns=KPATCH_TEST
12+
# [ 2d] import_ns=DEVMEM
13+
# [ 3e] import_ns=DMA_BUF
14+
15+
[[ $(readelf --wide --string-dump=.modinfo "$OUTFILE" | grep --count -e 'import_ns=') == 4 ]]

0 commit comments

Comments
 (0)