Comments (20)
have debugged kpatch, found that the entsize of .return_sites section changed from 4 to 0, thus kpatch reported this error.
from kpatch.
after adding V=1 to module Makefile, log output shows:
make -f ./scripts/Makefile.build obj=/root/testmod_ext \
single-build= \
need-builtin=1 need-modorder=1
gcc -Wp,-MMD,/root/testmod_ext/.testmod_drv.o.d -nostdinc -isystem /usr/lib/gcc/x86_64-linux-gnu/10.3.1/include -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -fmacro-prefix-map=./= -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -std=gnu89 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fcf-protection=none -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -mfunction-return=thunk-extern -fno-jump-tables -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-address-of-packed-member -O2 -fno-allow-store-data-races -Wframe-larger-than=2048 -fstack-protector-strong -Wimplicit-fallthrough -Wno-unused-but-set-variable -Wno-unused-const-variable -g -gdwarf-4 -pg -mrecord-mcount -mfentry -DCC_USING_FENTRY -fno-inline-functions-called-once -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wno-stringop-truncation -Wno-zero-length-bounds -Wno-array-bounds -Wno-stringop-overflow -Wno-restrict -Wno-maybe-uninitialized -fno-strict-overflow -fno-stack-check -fconserve-stack -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wno-packed-not-aligned -DMODULE -DKBUILD_BASENAME='"testmod_drv"' -DKBUILD_MODNAME='"testmod_ext"' -c -o /root/testmod_ext/testmod_drv.o /root/testmod_ext/testmod_drv.c
./tools/objtool/objtool orc generate --module --no-fp --retpoline --rethunk --uaccess /root/testmod_ext/testmod_drv.o
if objdump -h /root/testmod_ext/testmod_drv.o | grep -q __ksymtab; then
gcc -E -D__GENKSYMS__ -Wp,-MMD,/root/testmod_ext/.testmod_drv.o.d -nostdinc -isystem /usr/lib/gcc/x86_64-linux-gnu/10.3.1/include -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -fmacro-prefix-map=./= -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -std=gnu89 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fcf-protection=none -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -mfunction-return=thunk-extern -fno-jump-tables -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-address-of-packed-member -O2 -fno-allow-store-data-races -Wframe-larger-than=2048 -fstack-protector-strong -Wimplicit-fallthrough -Wno-unused-but-set-variable -Wno-unused-const-variable -g -gdwarf-4 -pg -mrecord-mcount -mfentry -DCC_USING_FENTRY -fno-inline-functions-called-once -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wno-stringop-truncation -Wno-zero-length-bounds -Wno-array-bounds -Wno-stringop-overflow -Wno-restrict -Wno-maybe-uninitialized -fno-strict-overflow -fno-stack-check -fconserve-stack -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wno-packed-not-aligned -DMODULE -DKBUILD_BASENAME='"testmod_drv"' -DKBUILD_MODNAME='"testmod_ext"' /root/testmod_ext/testmod_drv.c | scripts/genksyms/genksyms -r /dev/null > /root/testmod_ext/.tmp_testmod_drv.ver;
### this ld changed the entsize
ld -m elf_x86_64 -r -o /root/testmod_ext/.tmp_testmod_drv.o /root/testmod_ext/testmod_drv.o -T /root/testmod_ext/.tmp_testmod_drv.ver;
mv -f /root/testmod_ext/.tmp_testmod_drv.o /root/testmod_ext/testmod_drv.o;
rm -f /root/testmod_ext/.tmp_testmod_drv.ver;
fi
ld -m elf_x86_64 -r -o /root/testmod_ext/testmod_ext.o /root/testmod_ext/testmod_drv.o
{ echo /root/testmod_ext/testmod_drv.o; echo; } > /root/testmod_ext/testmod_ext.mod
{ echo /root/testmod_ext/testmod_ext.ko; :; } | awk '!x[$0]++' - > /root/testmod_ext/modules.order
make -f ./scripts/Makefile.modpost
sed 's/ko$/o/' /root/testmod_ext/modules.order | scripts/mod/modpost -m -a -o /root/testmod_ext/Module.symvers -e -i Module.symvers -T -
make -f ./scripts/Makefile.modfinal
gcc -Wp,-MMD,/root/testmod_ext/.testmod_ext.mod.o.d -nostdinc -isystem /usr/lib/gcc/x86_64-linux-gnu/10.3.1/include -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -fmacro-prefix-map=./= -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -std=gnu89 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fcf-protection=none -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -mfunction-return=thunk-extern -fno-jump-tables -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-address-of-packed-member -O2 -fno-allow-store-data-races -Wframe-larger-than=2048 -fstack-protector-strong -Wimplicit-fallthrough -Wno-unused-but-set-variable -Wno-unused-const-variable -g -gdwarf-4 -pg -mrecord-mcount -mfentry -DCC_USING_FENTRY -fno-inline-functions-called-once -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wno-stringop-truncation -Wno-zero-length-bounds -Wno-array-bounds -Wno-stringop-overflow -Wno-restrict -Wno-maybe-uninitialized -fno-strict-overflow -fno-stack-check -fconserve-stack -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wno-packed-not-aligned -DMODULE -DKBUILD_BASENAME='"testmod_ext.mod"' -DKBUILD_MODNAME='"testmod_ext"' -c -o /root/testmod_ext/testmod_ext.mod.o /root/testmod_ext/testmod_ext.mod.c
ld -r -m elf_x86_64 --build-id=sha1 -T scripts/module.lds -o /root/testmod_ext/testmod_ext.ko /root/testmod_ext/testmod_ext.o /root/testmod_ext/testmod_ext.mod.o; true
make[1]: Leaving directory '/usr/src/kernels/5.10.0-60.18.0.50.h485.x86_64'
there is one 'ld' step after objtool generates .return_sites section, and it changed entsize of .return_sites section of testmod_drv.o from 4 to 0.
the reason why 'ld' step happens seems to be that patched module contains __ksymtab section due to exporting a function.
from kpatch.
localhost:~/testmod_ext # readelf -SW /root/.kpatch/tmp/orig/testmod_drv.o | grep return_sites
[46] .return_sites PROGBITS 0000000000000000 0147aa 000010 04 A 0 0 1
[47] .rela.return_sites RELA 0000000000000000 0147c0 000060 18 I 43 46 8
localhost:~/testmod_ext # readelf -SW /root/.kpatch/tmp/patched/testmod_drv.o | grep return_sites
[28] .return_sites PROGBITS 0000000000000000 000239 000014 00 A 0 0 1
[29] .rela.return_sites RELA 0000000000000000 00b848 000078 18 I 58 28 8
localhost:~/testmod_ext # readelf -SW /root/.kpatch/tmp/orig/testmod_drv.o | grep symtab
[43] .symtab SYMTAB 0000000000000000 013f00 0004f8 18 44 38 8
localhost:~/testmod_ext # readelf -SW /root/.kpatch/tmp/patched/testmod_drv.o | grep symtab
[16] __ksymtab_strings PROGBITS 0000000000000000 00018a 000014 01 AMS 0 0 1
[17] ___ksymtab+new_export_testfun PROGBITS 0000000000000000 0001a0 00000c 00 A 0 0 4
[18] .rela___ksymtab+new_export_testfun RELA 0000000000000000 00b770 000048 18 I 58 17 8
[58] .symtab SYMTAB 0000000000000000 00ab20 000660 18 59 51 8
from kpatch.
Not sure should kpatch deal with this situation, or it is kernel's problem.
Or ld should keep testmod_drv.o's entsize not changed?
from kpatch.
Hi @he7850,
I am not getting the error you mention while trying to reproduce your issue. Could you please attach a tarball including the original test module C file
+ the patch file
you applied?
Could you also provide the "kpatch-build" line
you used to build and get that error?
Thanks
from kpatch.
Hi @he7850,
I am not getting the error you mention while trying to reproduce your issue. Could you please attach a tarball including the original
test module C file
+ thepatch file
you applied?Could you also provide the
"kpatch-build" line
you used to build and get that error? Thanks
I cannot upload files to github due to the firewall of my company, I will copy the code to my PC and upload it, but it may take some time.
from kpatch.
@he7850 Maybe just the kpatch-build ...
command line that failed used to build the kpatch-patch and if available, the link to the kernel source tree you use should be a good start.
from kpatch.
sorry for the late reply. here is the command:
localhost:~/testmod_ext # kpatch-build -e testmod_ext.ko -s /root/testmod_ext -t all -c /opt/patch_workspace/.config -v /opt/patch_workspace/vmlinux -n klp_testexport003 /root/testmod_ext/testexport003.patch -R
Using source directory at /root/testmod_ext
Testing patch file(s)
Reading special section data
Building original source
Building patched source
Extracting new and modified ELF sections
ERROR: testmod_drv.o: .return_sites section header details differ from .return_sites
/usr/libexec/kpatch/create-diff-object: unreconcilable difference
ERROR: 1 error(s) encountered. Check /root/.kpatch/build.log for more details.
from kpatch.
- kernel source tree
https://gitee.com/openeuler/kernel/tree/openEuler-22.03-LTS/ - testmod_ext module C file
it has been pasted in the fisrt comment, its file name istestmod_drv.c
: - testmod_ext module patch file
it has been pasted in the fisrt comment, its file name istestexport003.patch
: - testmod_ext module Makefile
######## modify the name to the module name ########
name := testmod_ext
######## do not modify the following content ###########
CURDIR := ${shell pwd}
BINDIR=$(shell echo $(CURDIR) | sed 's/testcases\//bin\//g')
ifeq ("$(ARCH)", "arm64")
EXTRA_CFLAGS += -DCONFIG_ARM64=1
endif
SOURCES_FILE := $(wildcard *.c)
ifneq ($(KERNELRELEASE),)
obj-m:=$(name).o
$(name)-objs := testmod_drv.o
else
KVER := $(shell uname -r)
KDIR := /lib/modules/$(KVER)/build
PWD := $(shell pwd)
all:
[ -e $(BINDIR) ] || mkdir -p $(BINDIR)
$(MAKE) V=1 -C $(KDIR) M=$(PWD) modules
.PHONY: install
install:
cp *.ko $(BINDIR)
.PHONY: clean
clean:
make -C $(KDIR) M=$(PWD) clean
rm -rf $(BINDIR)/*.ko
endif
from kpatch.
Can the problem be reproduced without adding a new symbol export? This is something that kpatch-build does not support (for example, see #1178)
from kpatch.
Also, not sure what the -e
command line option does, as the upstream kpatch-build only processes:
options="$(getopt -o ha:r:s:c:v:j:t:n:o:dR ...
from kpatch.
@jpoimboe: (symbol exports aside) I think this is another variant of [0] objtool creating elf sections with entry size while the rest of the toolchain (ie, ld) not bothering? If we're otherwise ignoring this section, should we relax the section header check to allow for N to 0 entry size changes?
[0] https://lore.kernel.org/lkml/[email protected]/T/#mea3ba10046d6a72b4ed07556f63cc537da767e15
from kpatch.
Also, not sure what the
-e
command line option does, as the upstream kpatch-build only processes:options="$(getopt -o ha:r:s:c:v:j:t:n:o:dR ...
-e means oot module.
I'm using Kpatch 0.9.5, kpatch-build option has not been refactored:
localhost:~/testmod_ext # kpatch-build -h
usage: kpatch-build [options] <patch1 ... patchN>
patchN Input patchfile(s)
-h, --help Show this help message
-a, --archversion Specify the kernel arch version
-r, --sourcerpm Specify kernel source RPM
-s, --sourcedir Specify kernel source directory
-c, --config Specify kernel config file
-v, --vmlinux Specify original vmlinux
-j, --jobs Specify the number of make jobs
-t, --target Specify custom kernel build targets
-n, --name Specify the name of the kpatch module
-o, --output Specify output folder
-d, --debug Enable 'xtrace' and keep scratch files
in <CACHEDIR>/tmp
(can be specified multiple times)
-e, --oot-module Enable patching out-of-tree module,
specify current version of module
-R, --non-replace Disable replace patch (replace is on by default)
--skip-cleanup Skip post-build cleanup
--skip-compiler-check Skip compiler version matching check
(not recommended)
from kpatch.
lol, just found my version of kpatch does support exporting symbol in patch module. (there is a patch allowing this)
and header difference problem only happens when the patched module contains __symtab section and original module does not.
bcz ld to textmod_drv.o only gets executed when there is __symtab section and ld changes the entsize of .return_sites section.
from kpatch.
I cannot figure why ld will change the entsize of .return_sites section, but I have tried one possible solution:
add SHF_MERGE to .return_sites section when creating it in objtool, then ld will keep the entsize not changed in the ouput testmod_drv.o
localhost:/opt/patch_workspace/kernel-source # git diff tools/objtool/check.c*
diff --git a/tools/objtool/check.c b/tools/objtool/check.c.new
index c7b6e6b..1162bf7 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c.new
@@ -672,7 +672,7 @@ static int create_return_sites_sections(struct objtool_file *file)
if (!idx)
return 0;
- sec = elf_create_section(file->elf, ".return_sites", 0,
+ sec = elf_create_section(file->elf, ".return_sites", 0x10, // SHF_MERGE
sizeof(int), idx);
if (!sec) {
WARN("elf_create_section: .return_sites");
but I am not sure if this flag can be added to the section.
currently I temporarily solve this problem by kpatch ignoring the section header change. maybe setting the entsize to 0 in objtool is better, if the entsize attrubute of .return_sites section is not actually used.
from kpatch.
just found my version of kpatch does support exporting symbol in patch module. (there is a patch allowing this)
Is this a local patch, or from a forked kpatch project?
As for the entry size changing, I'll leave it up to Josh to whether objtool should mimic the rest of the toolchain or not.
from kpatch.
just found my version of kpatch does support exporting symbol in patch module. (there is a patch allowing this)
Is this a local patch, or from a forked kpatch project?
the patch is from openEuler's forked kpatch repository: https://gitee.com/src-openeuler/kpatch
from kpatch.
This issue has been open for 30 days with no activity and no assignee. It will be closed in 7 days unless a comment is added.
from kpatch.
This issue has been open for 30 days with no activity and no assignee. It will be closed in 7 days unless a comment is added.
from kpatch.
This issue was closed because it was inactive for 7 days after being marked stale.
from kpatch.
Related Issues (20)
- create-diff-object static local variable correlation and inlining HOT 5
- 1.0 release HOT 2
- Do we need more robust archeticture protection HOT 4
- kpatch-build: verify_patch_files might miss a parameter HOT 2
- ERROR in find_local_syms, couldn't find matching XXX local symbols in vmlinux symbol table HOT 14
- Can you add support for Rocky and Alma? HOT 1
- relocation with type R_X86_64_GOTPCREL is not supported HOT 5
- Arch Compile kpatch-git test failed HOT 4
- Regarding "statically allocated data" again HOT 2
- kpatch-build error when modifying an object file's only syscall
- nowhere to find the definition of klp_register_patch HOT 5
- x86 paravirt code uses alternatives v6.8+ HOT 1
- special-static.patch can fail to build on s390x / upstream v6.8 HOT 6
- CONFIG_FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY not supported on ppc64le HOT 6
- function __pfx_new_sync_read has no fentry/mcount call, unable to patch HOT 6
- Unchanged and unpatchable function moves from .text to .text.unlikely HOT 5
- Why did the kpatch-build script export the KPATCH-BUILD environment variable from the BUILD directory to the SOURCE directory? HOT 3
- CONFIG_WERROR=y and CONFIG_LD_ORPHAN_WARN_LEVEL="error" break kpatch-build HOT 2
- linux 6.9.0-rc6 can't find special struct paravirt_patch_site size HOT 6
- fair.o: changed section .data..read_mostly not selected for inclusion HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kpatch.