Skip to content

module: ELF validation enhancement and cleanups

Luis Chamberlain linux-modules lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest5 patches 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5module: add sanity check for ELF module sectionkernel/module/main.c+53 -90 replies
2/5module: add stop-grap sanity check on module memcpy()kernel/module/main.c+22 -40 replies
3/5module: move more elf validity checks to elf_validity_check()kernel/module/main.c+44 -350 replies
4/5module: merge remnants of setup_load_info() to elf validationkernel/module/main.c+27 -330 replies
5/5module: fold usermode helper kmod into modules directoryMAINTAINERS kernel/Makefile kernel/module/Makefile +1 more+6 -120 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/5] module: ELF validation enhancement and cleanups

While doing a cleanup of load_module() to do less work before we allocate [0], one of the undocumented tricks we pull off is memcpy'ing the struct module from the module.mod.c into the kernel, with the modifications we've made to it on load_module(). This puts a bit of love to make the clearer, and extends our ELF validity checker to ensure we verify this before allowing us to even process a module.

This effort has discovered a new possible build issue we have to fix:

It is in theory possible today to modify the module struct module size, let a kernel developer lazily just build the module (say make fs/xfs/) and then try to insert that module without ensuring the module size expected should have grown. You can verify the size with:

nm --print-size --size-sort fs/xfs/xfs.ko | grep __this_module 0000000000000000 0000000000000500 D __this_module

The struct module size will be different per each kernel configuration, and so this is system build dependent. The new ELF check put in place prevents this situation and also make the use case of memcpying the struct module very clear, along with ensuring we keep all modifications we've made to it.

[0] https://lkml.kernel.org/r/[email protected]

Luis Chamberlain (5):
module: add sanity check for ELF module section
module: add stop-grap sanity check on module memcpy()
module: move more elf validity checks to elf_validity_check()
module: merge remnants of setup_load_info() to elf validation
module: fold usermode helper kmod into modules directory

 MAINTAINERS                |  13 +--
 kernel/Makefile            |   1 -
 kernel/module/Makefile     |   4 +-
 kernel/{ => module}/kmod.c |   0
 kernel/module/main.c       | 219 ++++++++++++++++++++++++-------------
 5 files changed, 148 insertions(+), 89 deletions(-)
 rename kernel/{ => module}/kmod.c (100%)
Signature · 1 line
2.39.1