diff mbox series

[v2] kernel-module-split: fix re-signing of modules built in a subdirectory

Message ID 20261127084231.1188128-1-mark.yang@lge.com
State New
Headers show
Series [v2] kernel-module-split: fix re-signing of modules built in a subdirectory | expand

Commit Message

mark.yang Nov. 27, 2026, 8:42 a.m. UTC
From: "mark.yang" <mark.yang@lge.com>

Out-of-tree modules built in a subdirectory of ${S}, such as
lttng-modules, are not signed again after package stripping and end up
in the packages without a signature.

A kernel with CONFIG_MODULE_SIG_FORCE=y then refuses to load them.
modprobe fails with "Key was rejected by service" and the kernel logs:

  Loading of unsigned module is rejected

To reproduce, set CONFIG_MODULE_SIG=y and CONFIG_MODULE_SIG_ALL=y in
linux-yocto and build lttng-modules. In log.do_package, modules_sign
enters ${S}, signs nothing and succeeds:

  NOTE: make ... M=.../lttng-modules-2.16.0 modules_sign
  make[1]: Entering directory '.../lttng-modules-2.16.0'
  make[1]: Leaving directory '.../lttng-modules-2.16.0'

Since 02890c1eff10 ("kernel-module-split: Remove get_ext_mod")
modules_sign always gets M=${S}, but lttng-modules runs Kbuild in
${S}/src and modules.order is only there.

Use MODULES_MODULE_SYMVERS_LOCATION, which module.bbclass already uses
to find Module.symvers in the same directory. modules_sign then signs
the modules:

  NOTE: make ... M=.../lttng-modules-2.16.0/src modules_sign
    SIGN    .../lttng-modules/lttng-ring-buffer-client-discard.ko

Give the variable a default in kernel-module-split.bbclass instead of
module.bbclass, so that it is also set for the kernel recipe and the
call can expand it directly.

M is now based on ${B} instead of ${S}. They are the same for most
module recipes, so nothing changes for them. For a recipe that sets B
to a subdirectory of ${S}, M follows ${B}, which is where
module_do_compile runs make. This is a behaviour change.

Suggested-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Signed-off-by: mark.yang <mark.yang@lge.com>
---
v2:
- Give MODULES_MODULE_SYMVERS_LOCATION a default in
  kernel-module-split.bbclass and expand it directly at the call site,
  as Bruce suggested.
- Drop the now redundant default from module.bbclass.
- Mention the ${S} -> ${B} change in the commit message.

v1: https://patchwork.yoctoproject.org/project/oe-core/patch/20261125005619.45574-1-mark.yang@lge.com/

 meta/classes-recipe/kernel-module-split.bbclass | 4 +++-
 meta/classes-recipe/module.bbclass              | 1 -
 2 files changed, 3 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/meta/classes-recipe/kernel-module-split.bbclass b/meta/classes-recipe/kernel-module-split.bbclass
index 9a7f04f37b..b10e9315ba 100644
--- a/meta/classes-recipe/kernel-module-split.bbclass
+++ b/meta/classes-recipe/kernel-module-split.bbclass
@@ -47,6 +47,8 @@  KERNEL_MODULE_PACKAGE_PREFIX ?= ""
 KERNEL_MODULE_PACKAGE_SUFFIX ?= "-${KERNEL_VERSION}"
 KERNEL_MODULE_PROVIDE_VIRTUAL ?= "1"
 
+MODULES_MODULE_SYMVERS_LOCATION ?= ""
+
 # This function supports both in-tree and out-of-tree modules.
 post_strip_kernel_modules_signing(){
     # Read .config values to determine if module auto-signing is enabled
@@ -69,7 +71,7 @@  post_strip_kernel_modules_signing(){
         oe_runmake \
             -C ${KBUILD_OUTPUT}  \
             MODLIB=${PKGD}${KERNEL_MODULE_INSTALL_PREFIX} \
-            ${@'M=%s' % '${S}' if not "virtual/kernel" in d.getVar('PROVIDES') else ''} \
+            ${@'M=${B}/${MODULES_MODULE_SYMVERS_LOCATION}' if not "virtual/kernel" in d.getVar('PROVIDES') else ''} \
             modules_sign
     fi
 }
diff --git a/meta/classes-recipe/module.bbclass b/meta/classes-recipe/module.bbclass
index 985c24bed5..ec6ff91612 100644
--- a/meta/classes-recipe/module.bbclass
+++ b/meta/classes-recipe/module.bbclass
@@ -12,7 +12,6 @@  DEPENDS += "virtual/cross-cc virtual/cross-binutils"
 EXTRA_OEMAKE += "KERNEL_SRC=${STAGING_KERNEL_DIR}"
 
 MODULES_INSTALL_TARGET ?= "modules_install"
-MODULES_MODULE_SYMVERS_LOCATION ?= ""
 
 python __anonymous () {
     depends = d.getVar('DEPENDS')