kpatch-build: Add support for module symbol namespaces#1467
Merged
joe-lawrence merged 3 commits intodynup:masterfrom Jul 8, 2025
Merged
kpatch-build: Add support for module symbol namespaces#1467joe-lawrence merged 3 commits intodynup:masterfrom
joe-lawrence merged 3 commits intodynup:masterfrom
Conversation
All previous callers needed a corresponding .rela section, but the following patch just needs to create a .modinfo section. Split create_section_pair() into two parts: create the base section seperately, then add the relocation section for those who request it. Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
Contributor
Author
|
(I pushed up an example obj test case here: dynup/kpatch-unit-test-objs#53 It's x86-only, but that's fine as this feature isn't architecture specific. This MR can be updated to move forward the submodule reference when that MR is approved.) |
jpoimboe
reviewed
Jul 1, 2025
| { | ||
| struct section *sec; | ||
|
|
||
| sec = create_section(kelf_out, ".modinfo", |
Member
There was a problem hiding this comment.
Should this be skipped if .modinfo doesn't exist in the patched object?
Contributor
Author
There was a problem hiding this comment.
Yup, no need to create an empty section.
Member
There was a problem hiding this comment.
Actually I suppose it should only create .modinfo if kelf_patched->modinfo_data is non-NULL?
Contributor
Author
There was a problem hiding this comment.
True, that's a better test, as it would skip instances with .modinfo but no imports.
3347579 to
f8b7b05
Compare
Contributor
Author
|
v2:
|
Kernel module namespace imports are saved in the .modinfo section in key-value strings. In order for a livepatch to access those symbols in those namespaces, it needs to provide the same imports else modpost refuses to process it. For example: ERROR: modpost: module livepatch-test uses symbol dma_buf_export from namespace DMA_BUF, but does not import it. We don't need the entire .modinfo section, as it carries other key-value pairs that we are not interested in. Selectively extract all of the "import_ns=<value" strings and then restore them in the ELF output for inclusion in the livepatch .ko. Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
f8b7b05 to
c03786f
Compare
Contributor
Author
|
v3:
|
jpoimboe
approved these changes
Jul 7, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Roberto Bergantinos Corpas rbergant@redhat.com reported a problem when building a kpatch for:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/patch/?id=021ba7f1babd029e714d13a6bf2571b08af96d0f
The problem is that the livepatch needs to access symbols exported via the "DMA_BUF" symbol namespace. A workaround is to add
MODULE_IMPORT_NS("DMA_BUF")to the kpatch, but then kpatch-build complains about unhandled .modinfo changes.Update kpatch-build to allow .modinfo changes and extract the
import_ns=<value>strings from .modinfo for inclusion in the output ELF object file. Coupled withMODULE_IMPORT_NS("DMA_BUF"), this allows kpatch to build a livepatch that accesses a module symbol namespace.