Skip to contentSkip to conversation

kernel.bbclass: add strip process for signed kernel modules

PATCH Superseded Anis Bougrine 3 participants 6 messages Aug 12 – Aug 13

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel.bbclass: add strip process for signed kernel modules

Currently, signed kernel modules skip the stripping process in order to preserve the file contents after signing. See commit:
4c47e5f171fa2603355e2f9183065ce8137a18c7

However, the kernel install Makefile supports stripping modules before signing them. This allows signed modules to be stripped while preserving a valid signature.

Make non-signed kernel modules follow the standard Yocto stripping flow, while signed kernel modules use the kernel Makefile stripping flow.

Fixes [YOCTO #12927]

---
 meta/classes-recipe/kernel.bbclass | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
meta/classes-recipe/kernel.bbclass +15 -1
index a82bdf7ecb..0d8d370e9d 100644
@@ -453,7 +453,21 @@ kernel_do_install() {
 	#
 	unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
 	if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
-		oe_runmake DEPMOD=echo MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} INSTALL_FW_PATH=${D}${firmwaredir} modules_install
+		# If the module will be auto-signed, perform stripping before signing.
+		if grep -q '^CONFIG_MODULE_SIG=y$' .config && grep -q '^CONFIG_MODULE_SIG_ALL=y$' .config; then
+			oe_runmake \
+				INSTALL_MOD_STRIP="--strip-debug --remove-section=.comment --remove-section=.note --preserve-dates" \
+				DEPMOD=echo \
+				MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} \
+				INSTALL_FW_PATH=${D}${nonarch_base_libdir}/firmware \
+				modules_install
+		else
+			oe_runmake \
+				DEPMOD=echo \
+				MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} \
+				INSTALL_FW_PATH=${D}${nonarch_base_libdir}/firmware \
+				modules_install
+		fi
 		rm -f "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build"
 		rm -f "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/source"
 		# Remove empty module directories to prevent QA issues
Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw
Quoted 33 lines · Anis Bougrine via lists.openembedded.org

Currently, signed kernel modules skip the stripping process in order to preserve the file contents after signing. See commit:
4c47e5f171fa2603355e2f9183065ce8137a18c7

However, the kernel install Makefile supports stripping modules before signing them. This allows signed modules to be stripped while preserving a valid signature.

Make non-signed kernel modules follow the standard Yocto stripping flow, while signed kernel modules use the kernel Makefile stripping flow.

Fixes [YOCTO #12927]

---
 meta/classes-recipe/kernel.bbclass | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
meta/classes-recipe/kernel.bbclass +4 -1
index a82bdf7ecb..0d8d370e9d 100644
@@ -453,7 +453,21 @@ kernel_do_install() {
        #
        unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
        if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
-               oe_runmake DEPMOD=echo MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} INSTALL_FW_PATH=${D}${firmwaredir} modules_install
+               # If the module will be auto-signed, perform stripping before signing.
+               if grep -q '^CONFIG_MODULE_SIG=y$' .config && grep -q '^CONFIG_MODULE_SIG_ALL=y$' .config; then
+                       oe_runmake \
+                               INSTALL_MOD_STRIP="--strip-debug --remove-section=.comment --remove-section=.note --preserve-dates" \

meta/classes-recipe/kernel.bbclass kernel_do_install() { · line 469

Quoted 10 lines
meta/classes-recipe/kernel.bbclass +10 -0
+                               DEPMOD=echo \
+                               MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} \
+                               INSTALL_FW_PATH=${D}${nonarch_base_libdir}/firmware \
+                               modules_install
+               else
+                       oe_runmake \
+                               DEPMOD=echo \
+                               MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} \
+                               INSTALL_FW_PATH=${D}${nonarch_base_libdir}/firmware \
+                               modules_install

Am I misreading the patch (it has been known to happen :)) ? is the only differnece
between the two conditions the INSTALL_MOD_STRIP ? if so, why not just use a variable and put $INSTALL_MOD_STRIP (or whatever) in the oe_runmake line ?

Better to have the variable be conditional, than duplicating the actual call to strip
the modules.

Bruce

Quoted 16 lines
meta/classes-recipe/kernel.bbclass +1 -1
+               fi
                rm -f "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build"
                rm -f "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/source"
                # Remove empty module directories to prevent QA issues
--

2.50.1 (Apple Git-155)

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#243287): https://lists.openembedded.org/g/openembedded-core/message/243287
Mute This Topic: https://lists.openembedded.org/mt/120717114/1050810
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Signature · 3 lines
- Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end
- "Use the force Harry" - Gandalf, Star Trek II
#2 lore raw

Hi Bruce,

You are correct, INSTALL_MOD_STRIP is the only difference between the two branches.

I initially tried using a variable as you suggested, but had issues with the variable expansion when passing the strip options to the kernel Makefile.

Using an environment variable keeps a single oe_runmake call:

if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
# If the module will be auto-signed, perform stripping before
signing.

        if [ "$(./source/scripts/config --file ./.config --state
MODULE_SIG)" = y ] &&
           [ "$(./source/scripts/config --file ./.config --state

MODULE_SIG_ALL)" = y ]; then
export INSTALL_MOD_STRIP="--strip-debug
--remove-section=.comment --remove-section=.note --preserve-dates"
fi
oe_runmake DEPMOD=echo
MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} INSTALL_FW_PATH=${D}${nonarch_base_libdir}/firmware modules_install
fi

If you are okay with this approach, I can send v2.

BR,
Anis

Quoted 96 lines · Bruce Ashfield
Quoted 14 lines · Anis Bougrine via lists.openembedded.org

Currently, signed kernel modules skip the stripping process in order to preserve the file contents after signing. See commit:
4c47e5f171fa2603355e2f9183065ce8137a18c7

However, the kernel install Makefile supports stripping modules before signing them. This allows signed modules to be stripped while preserving a valid signature.

Make non-signed kernel modules follow the standard Yocto stripping flow, while signed kernel modules use the kernel Makefile stripping flow.

Fixes [YOCTO #12927]

Review

Quoted 7 lines
---
 meta/classes-recipe/kernel.bbclass | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/meta/classes-recipe/kernel.bbclass

meta/classes-recipe/kernel.bbclass kernel_do_install() { · line 456

Quoted 8 lines

index a82bdf7ecb..0d8d370e9d 100644

meta/classes-recipe/kernel.bbclass +0 -1
@@ -453,7 +453,21 @@ kernel_do_install() {
        #
        unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
        if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
-               oe_runmake DEPMOD=echo

MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} INSTALL_FW_PATH=${D}${firmwaredir} modules_install

meta/classes-recipe/kernel.bbclass kernel_do_install() { · line 456

Quoted 1 line
meta/classes-recipe/kernel.bbclass +1 -0
+               # If the module will be auto-signed, perform stripping

before signing.

meta/classes-recipe/kernel.bbclass kernel_do_install() { · line 457

Quoted 1 line
meta/classes-recipe/kernel.bbclass +1 -0
+               if grep -q '^CONFIG_MODULE_SIG=y$' .config && grep -q

'^CONFIG_MODULE_SIG_ALL=y$' .config; then

meta/classes-recipe/kernel.bbclass kernel_do_install() { · line 459

Quoted 2 lines
meta/classes-recipe/kernel.bbclass +2 -0
+                       oe_runmake \
+                               INSTALL_MOD_STRIP="--strip-debug

--remove-section=.comment --remove-section=.note --preserve-dates" \

meta/classes-recipe/kernel.bbclass kernel_do_install() { · line 461

Quoted 2 lines
meta/classes-recipe/kernel.bbclass +2 -0
+                               DEPMOD=echo \
+

MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} \

meta/classes-recipe/kernel.bbclass kernel_do_install() { · line 462

Quoted 1 line
meta/classes-recipe/kernel.bbclass +1 -0
+

INSTALL_FW_PATH=${D}${nonarch_base_libdir}/firmware \

meta/classes-recipe/kernel.bbclass kernel_do_install() {

Quoted 5 lines
meta/classes-recipe/kernel.bbclass +5 -0
+                               modules_install
+               else
+                       oe_runmake \
+                               DEPMOD=echo \
+

MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} \

meta/classes-recipe/kernel.bbclass kernel_do_install() { · line 468

Quoted 1 line
meta/classes-recipe/kernel.bbclass +1 -0
+

INSTALL_FW_PATH=${D}${nonarch_base_libdir}/firmware \

meta/classes-recipe/kernel.bbclass kernel_do_install() { · line 469

Quoted 1 line
meta/classes-recipe/kernel.bbclass +1 -0
+                               modules_install

Am I misreading the patch (it has been known to happen :)) ? is the only differnece
between the two conditions the INSTALL_MOD_STRIP ? if so, why not just use a
variable and put $INSTALL_MOD_STRIP (or whatever) in the oe_runmake line ?

Better to have the variable be conditional, than duplicating the actual call to strip
the modules.

Bruce

meta/classes-recipe/kernel.bbclass kernel_do_install() { · line 471

Quoted 2 lines
meta/classes-recipe/kernel.bbclass +1 -0
+               fi
                rm -f

"${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build"

meta/classes-recipe/kernel.bbclass kernel_do_install() { · line 472

Quoted 1 line
meta/classes-recipe/kernel.bbclass +0 -0
                rm -f

"${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/source"

Quoted 8 lines
meta/classes-recipe/kernel.bbclass +0 -1
                # Remove empty module directories to prevent QA issues
--

2.50.1 (Apple Git-155)

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#243287):

https://lists.openembedded.org/g/openembedded-core/message/243287

Quoted 3 lines

Mute This Topic: https://lists.openembedded.org/mt/120717114/1050810
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [

[email protected]]

Quoted 2 lines

-=-=-=-=-=-=-=-=-=-=-=-

--
- Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end
- "Use the force Harry" - Gandalf, Star Trek II

#3 lore raw
In reply to Anis Bougrine

Hi,

Quoted 24 lines · Anis Bougrine via lists.openembedded.org

Currently, signed kernel modules skip the stripping process in order to preserve the file contents after signing. See commit:
4c47e5f171fa2603355e2f9183065ce8137a18c7

However, the kernel install Makefile supports stripping modules before signing them. This allows signed modules to be stripped while preserving a valid signature.

Make non-signed kernel modules follow the standard Yocto stripping flow, while signed kernel modules use the kernel Makefile stripping flow.

Fixes [YOCTO #12927]

---
 meta/classes-recipe/kernel.bbclass | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
meta/classes-recipe/kernel.bbclass +0 -0
index a82bdf7ecb..0d8d370e9d 100644

meta/classes-recipe/kernel.bbclass kernel_do_install() { · line 457

Quoted 6 lines
meta/classes-recipe/kernel.bbclass +2 -1
@@ -453,7 +453,21 @@ kernel_do_install() {
 	#
 	unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
 	if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
-		oe_runmake DEPMOD=echo MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} INSTALL_FW_PATH=${D}${firmwaredir} modules_install
+		# If the module will be auto-signed, perform stripping before signing.
+		if grep -q '^CONFIG_MODULE_SIG=y$' .config && grep -q '^CONFIG_MODULE_SIG_ALL=y$' .config; then

Suggestion: you can use the kernel's scripts/config utility to get the option values:

$ ./scripts/config --file ./.config --state MODULE_SIG
y

So that you really see the option value as the kernel sees it.

Antonin

#4 lore raw

Hi Antonin,

I took your suggestion into account. A v2 patch may look like this:

if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
# If the module will be auto-signed, perform stripping before
signing.

        if [ "$(./source/scripts/config --file ./.config --state
MODULE_SIG)" = y ] &&
           [ "$(./source/scripts/config --file ./.config --state

MODULE_SIG_ALL)" = y ]; then
export INSTALL_MOD_STRIP="--strip-debug
--remove-section=.comment --remove-section=.note --preserve-dates"
fi
oe_runmake DEPMOD=echo
MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} INSTALL_FW_PATH=${D}${nonarch_base_libdir}/firmware modules_install
fi

However, I think grepping the .config file is more reliable, since its location inside ${WORKDIR} is more stable than the location of the config script.

I stay open to any further suggestions.

BR,

Anis

Quoted 51 lines · Antonin Godard

Hi,

Quoted 13 lines · Anis Bougrine via lists.openembedded.org

Currently, signed kernel modules skip the stripping process in order to preserve the file contents after signing. See commit:
4c47e5f171fa2603355e2f9183065ce8137a18c7

However, the kernel install Makefile supports stripping modules before signing them. This allows signed modules to be stripped while preserving a valid signature.

Make non-signed kernel modules follow the standard Yocto stripping flow, while signed kernel modules use the kernel Makefile stripping flow.

Fixes [YOCTO #12927]

Review

Quoted 7 lines
---
 meta/classes-recipe/kernel.bbclass | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/meta/classes-recipe/kernel.bbclass

meta/classes-recipe/kernel.bbclass kernel_do_install() { · line 456

Quoted 8 lines

index a82bdf7ecb..0d8d370e9d 100644

meta/classes-recipe/kernel.bbclass +0 -1
@@ -453,7 +453,21 @@ kernel_do_install() {
      #
      unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
      if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
-             oe_runmake DEPMOD=echo

MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} INSTALL_FW_PATH=${D}${firmwaredir} modules_install

meta/classes-recipe/kernel.bbclass kernel_do_install() { · line 456

Quoted 1 line
meta/classes-recipe/kernel.bbclass +1 -0
+             # If the module will be auto-signed, perform stripping

before signing.

meta/classes-recipe/kernel.bbclass kernel_do_install() { · line 457

Quoted 1 line
meta/classes-recipe/kernel.bbclass +1 -0
+             if grep -q '^CONFIG_MODULE_SIG=y$' .config && grep -q

'^CONFIG_MODULE_SIG_ALL=y$' .config; then

Suggestion: you can use the kernel's scripts/config utility to get the option
values:

$ ./scripts/config --file ./.config --state MODULE_SIG
y

So that you really see the option value as the kernel sees it.

Antonin

#5 lore raw

Hi,

Quoted 19 lines · Bougrine Anis

Hi Antonin,

I took your suggestion into account. A v2 patch may look like this:

if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
# If the module will be auto-signed, perform stripping before
signing.

        if [ "$(./source/scripts/config --file ./.config --state
MODULE_SIG)" = y ] &&
           [ "$(./source/scripts/config --file ./.config --state

MODULE_SIG_ALL)" = y ]; then
export INSTALL_MOD_STRIP="--strip-debug
--remove-section=.comment --remove-section=.note --preserve-dates"
fi
oe_runmake DEPMOD=echo
MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} INSTALL_FW_PATH=${D}${nonarch_base_libdir}/firmware modules_install
fi

Quoted 3 lines

However, I think grepping the .config file is more reliable, since its location inside ${WORKDIR} is more stable than the location of the config script.

Can you use the script directly from the source using S?

${S}/scripts/config --file ./.config --state ...

Also, if you know the config file is always going to be in your current working directory, then you can do:

${S}/scripts/config --state ...

Since the default value for --file is "./.config".

So your conditions would look like:

if [ "$(${S}/scripts/config --state MODULE_SIG)" = "y" ] && [ "$(${S}/scripts/config --state MODULE_SIG_ALL)" = "y" ]; then

(not tested)

Antonin