From patchwork Tue Apr 28 08:10:44 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Kent X-Patchwork-Id: 87054 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68C0BFF885D for ; Tue, 28 Apr 2026 08:59:39 +0000 (UTC) Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by mx.groups.io with SMTP id smtpd.msgproc02-g2.8115.1777363918412374435 for ; Tue, 28 Apr 2026 01:11:58 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20251104 header.b=KKysZllf; spf=pass (domain: gmail.com, ip: 209.85.128.54, mailfrom: sam.john.kent@gmail.com) Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-488ff90d6c7so94723075e9.2 for ; Tue, 28 Apr 2026 01:11:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777363916; x=1777968716; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=knv8OHkTYFq3in7JMjaEX9aHm+yJPBR7EOCvHu+XnTo=; b=KKysZllfNs+bfl+2Eu8Qkq3vcNQRfLCzxoWZ1Ltqi53KSDp0KAp/KVdxzOeb+mpEE1 ee/4MkBBFsyPilSEVv0/Iy88L/YZtipR/OMc8GA+zGf69rtLINfNTyJ3MPIZ0S0odGtX Wvz1TGROhqHsV79wJCmvQ5ZFe/18W6T2Hm16lmEhElzHbZMCG5yfsGdq4HaD3EfIBjsA TuGNN7z7IdHPr8UyEX0dKtUzgptOxh8izKqZlxifhy0JCmVKCU4W52TrYaQL0bKUKvoX X9ajaktnJng7ThpKrQakJcHz+u+dDZ5mARgKF20IrCopWfHDTRK8G/E84aglfLzWUoW2 YpbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777363916; x=1777968716; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=knv8OHkTYFq3in7JMjaEX9aHm+yJPBR7EOCvHu+XnTo=; b=Ognbk3wczovuXAFsqT/VUxP4k6VKj7AXdka7aLF7S3GncBJn+UrXmQX/SV12DhrfGo wwwB/R1uFcHIkGq4v/aIBcyNGEsLTJaun808POXnnC5FZX8U4v2UfVg6zf8kaUeMAf0N vEzHwq9/UkcFRiNC4Y4Ow+j+rAf6NxofXMpY15a1UwU0l69oCwLO+PJ5Uh+7kHZtRsxG JFy/0CH3uHdGTL8Sr5tvtFAVBPv/8aRj6B6LT3SyPwKg7h4uK/kbHwp027UEDeZAaOOi yOnKkOVyhqsYosS/M/Tnk/MaoQb+m0ipTnIWRv8PA9hbrOOcts06aueQBYdxg5LmuCrB L0aw== X-Gm-Message-State: AOJu0YzqmCaeB5nklkMW0bNrnBSzjZ9iZvNlrkTPmHg1WinkNJvoLjmk a9t/fpX23DH2U2Fuij6pvNj6WbSFscftEN8sfJ4ToaBhFhJZzwwCB0DwW6MKaW/asAI= X-Gm-Gg: AeBDietRbvVEdyBYGJ6Ei/BG7Kp0tmMrwc55/tPZBl40lXzD6A3vMHhJJdqkvFtfBBd /ddVdt0vqZayHbLp7CI5MCT9aA6Cg7CJNIhUG3saKaPJqvCSnCepY0DAcZZfMuIR3QxBmv9+snt jpGy2kPWG1avO382UGOgwPLouGpd1YB3gL5URiEJXQfefmFqSJTs8mvBHkEmL9lM022y8t1amk3 5sbdTgCd92tJ+86IOMFbmKVQzbciMubKhhpfr33nRrjgh5PshTfr1l8WHK5/MFLN/j2sMQhu9RB 3S1eL7fmA7Uz7TfYCnFfpSkKry5uYgx7fF77D6S9ItmiPidT7Ju37h4t+S0SqapH37OUaPA3X72 kfRO0p3q2O2rbnghCuDRlPS+34C+uho+g2zC2sx9P0y5mpIsUDntBqkh/XWE2hH4ljMhS20Tdng 4LfHqE2WIPt9O6Dmx79c7aHi2IJEyBiV/3TUPOBr1foxfesOr3pQkHV4dRlHH2b7cpbydpKxZbS FuRYq8= X-Received: by 2002:a05:600c:3b96:b0:485:35d3:ce59 with SMTP id 5b1f17b1804b1-48a77aefe5amr32050325e9.10.1777363916229; Tue, 28 Apr 2026 01:11:56 -0700 (PDT) Received: from sam-ThinkPad-X1-Carbon-Gen-11.netbird.cloud ([79.123.125.82]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4463f4c07a2sm4588351f8f.20.2026.04.28.01.11.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2026 01:11:55 -0700 (PDT) From: "Sam Kent" To: openembedded-core@lists.openembedded.org Cc: Sam Kent Subject: [PATCH v2 1/3] package.py: fix kernel module file pre-filter and document strip asymmetry Date: Tue, 28 Apr 2026 09:10:44 +0100 Message-Id: <20260428081046.1660101-2-sam.john.kent@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260428081046.1660101-1-sam.john.kent@gmail.com> References: <20260428081046.1660101-1-sam.john.kent@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Tue, 28 Apr 2026 08:59:39 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/236047 Change the check to f.endswith(".ko"), consistent with strip_execs() and with the /lib/modules/ guard already present in is_elf() and splitdebuginfo(). Fixes [YOCTO #2348] Signed-off-by: Sam Kent --- meta/lib/oe/package.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/meta/lib/oe/package.py b/meta/lib/oe/package.py index 279cd56..c375acc 100644 --- a/meta/lib/oe/package.py +++ b/meta/lib/oe/package.py @@ -37,7 +37,8 @@ def runstrip(file, elftype, strip, extra_strip_sections=''): stripcmd = [strip] skip_strip = False - # kernel module + # kernel module: use --strip-debug and --preserve-dates (required for + # module signing to remain valid after stripping) if elftype & 16: if is_kernel_module_signed(file): bb.debug(1, "Skip strip on signed module %s" % file) @@ -1167,7 +1168,7 @@ def process_split_and_strip_files(d): or (s[stat.ST_MODE] & stat.S_IXOTH) \ or ((file.startswith(libdir) or file.startswith(baselibdir)) \ and (".so" in f or ".node" in f)) \ - or (f.startswith('vmlinux') or ".ko" in f): + or (f.startswith('vmlinux') or f.endswith(".ko")): if cpath.islink(file): checkelflinks[file] = ltarget From patchwork Tue Apr 28 08:10:45 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sam Kent X-Patchwork-Id: 87055 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68013FF885D for ; Tue, 28 Apr 2026 09:00:09 +0000 (UTC) Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.8388.1777363919081073274 for ; Tue, 28 Apr 2026 01:11:59 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20251104 header.b=phxNbNFI; spf=pass (domain: gmail.com, ip: 209.85.221.51, mailfrom: sam.john.kent@gmail.com) Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-43cfbd17589so8689984f8f.0 for ; Tue, 28 Apr 2026 01:11:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777363917; x=1777968717; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=K/RfwrppZ5/uZ1q0klgEETnYxMNySn8ycfMmKElIDHM=; b=phxNbNFIATpKx6BVNtw2PhK1gvVIXGXfZErcJu/HGiClRbSkrHPWjMAewo3zAoEaoM 4FaGu/qAGnJahSMn7Ju9KQ+DVnIw1jvwlxTwRPmEup1l1F4EmzCDYXTdLEt/LFUklLdl o1pA3dl66FfQbM1dkJMyIXRctsn0gjJ1AcCE//t93ntG3wgSoApZBLnlLPe2DvAR7zmD +sJkjVc9lM4q57pRA5rzJjX2WHUDjfosFZn1BQosViUBuy9cPm+NTbS7tqBncp4WiSzp rp7pC7oKw/9MaJ8Q2szkd+QssPMXeW8Pj5U5AKCdWcsu4pxZDPKIgcTcgeIudOiObvVl Rcug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777363917; x=1777968717; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=K/RfwrppZ5/uZ1q0klgEETnYxMNySn8ycfMmKElIDHM=; b=Uips8cIaU/Pmr6e6b+9/UjUKVkLdKP7nv1L8zzNByvIzmeNXZUSpoO6Hss6k/Oanhw uvQfS7ewY6lupWBiw99aKKCZrLeL9EIHKV4TnaSKk1TKM9qUqLoTbY12KkRl0vXEYzTR l/dNl1OXNbMlX/JNz7oYoddrQbtY29vPG5utdvgTMNoQCjOHxxabkpi/LCJOzt/sgNZj NYnpeR2NOt41r0CPE2rZ0Cvh2VPIdfOwB8eTReVd57vf7TRC7BaZskLx7khLeXnNu0U6 5BXQHmTilxjJSYVoz6AC57egfbVCQRoyQcjfzXsixY7cMqLTHPiv7EhSyeQ7LPWUJVcC g4nA== X-Gm-Message-State: AOJu0YxZ0QALHaK+U0Xq9StFHdiPqa+E98XtR52ojqxwrfqJeC9PAraL MoboGd3krRbYVcU2st2s4fJBnwzmsG0zKVdBMdQr+tHMR2XkdqLb6+vkGCqBznpEE6c= X-Gm-Gg: AeBDievd+s8ycxu2Gt4Iz8trherxJBH5xXwGjvT/iaOeB6XxtEd/BneADL/3aDpJR1F +9xo7GIQDaMoCfrg3IabmnM4+uzl1BN9NElPeHT6KupBYrtdCLe0SX1ON5/zH00ZYne40L/mzjj Z5oY1/mutrkn642nxVyrNhFXfsSnZhLGO7NaIugPnsaKRA2xgaDK5XZmnWmk44vCwm7TkAlvJ5R SLWCZoDqLb1WoT2A1D6sLfpZhDnwZd2Nh7kjSRRxrImKHc0JDoMUzr3pIigoM3eLCTvzX27YDIe q/v1gxW9g8AO5WRBccBIRDgqnIJifFVbUqQq1tAPBoCaX6QiYvYB7ON9D/si7pgiVMNmvxWNAlU NQbm9sv1Heosgd0tPmU56CZBeruv4bkzw4cT7xgk6UtqIMSk38ZUGxM0m/sW2qSgIeehbhaaG/0 mJGyt3m2dQOD8CrqTmlUcUHUDONnRHW/hp7IHUV/cdisKkH1j5CPLYfwO2CccHR6ON6OESJaN1H ci0sqg= X-Received: by 2002:a5d:5c84:0:b0:43f:e990:2f5d with SMTP id ffacd0b85a97d-44649ba18ffmr3663638f8f.35.1777363916998; Tue, 28 Apr 2026 01:11:56 -0700 (PDT) Received: from sam-ThinkPad-X1-Carbon-Gen-11.netbird.cloud ([79.123.125.82]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4463f4c07a2sm4588351f8f.20.2026.04.28.01.11.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2026 01:11:56 -0700 (PDT) From: "Sam Kent" To: openembedded-core@lists.openembedded.org Cc: Sam Kent Subject: [PATCH v2 2/3] oe/package: add unit tests for kernel module detection helpers Date: Tue, 28 Apr 2026 09:10:45 +0100 Message-Id: <20260428081046.1660101-3-sam.john.kent@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260428081046.1660101-1-sam.john.kent@gmail.com> References: <20260428081046.1660101-1-sam.john.kent@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Tue, 28 Apr 2026 09:00:09 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/236049 Add unit tests for the filename pre-filter logic, is_kernel_module(), and the is_kernel_module_signed() detection. Signed-off-by: Sam Kent --- meta/lib/oe/tests/__init__.py | 0 meta/lib/oe/tests/test_package.py | 121 ++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 meta/lib/oe/tests/__init__.py create mode 100644 meta/lib/oe/tests/test_package.py diff --git a/meta/lib/oe/tests/__init__.py b/meta/lib/oe/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/meta/lib/oe/tests/test_package.py b/meta/lib/oe/tests/test_package.py new file mode 100644 index 0000000..29e393c --- /dev/null +++ b/meta/lib/oe/tests/test_package.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python3 +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: GPL-2.0-only +# + +import mmap +import os +import tempfile +import unittest + + +# Copied from oe/package.py to allow standalone execution without bitbake. +def is_kernel_module(path): + with open(path) as f: + return mmap.mmap(f.fileno(), 0, prot=mmap.PROT_READ).find(b"vermagic=") >= 0 + +def is_kernel_module_signed(path): + with open(path, "rb") as f: + f.seek(-28, 2) + module_tail = f.read() + return "Module signature appended" in "".join(chr(c) for c in bytearray(module_tail)) + + +class TestKernelModuleFilenameFilter(unittest.TestCase): + """ + The pre-filter in process_split_and_strip_files() selects candidates to + pass to is_elf(). It must use f.endswith(".ko"), not ".ko" in f, to avoid + false-positives on compressed modules (.ko.xz, .ko.gz). + """ + + ko_files = [ + "driver.ko", + "net/foo.ko", + ] + + not_ko_files = [ + "driver.ko.xz", + "driver.ko.gz", + "driver.ko2", + "myko.c", + "vmlinux", + ] + + def test_endswith_matches_ko(self): + for f in self.ko_files: + with self.subTest(f=f): + self.assertTrue(f.endswith(".ko")) + + def test_endswith_rejects_non_ko(self): + for f in self.not_ko_files: + with self.subTest(f=f): + self.assertFalse(f.endswith(".ko")) + + def test_old_predicate_had_false_positives(self): + # Demonstrate that the previous check (".ko" in f) matched compressed + # modules — this is the regression the fix addresses. + false_positives = [f for f in self.not_ko_files if ".ko" in f] + self.assertEqual(false_positives, ["driver.ko.xz", "driver.ko.gz", "driver.ko2"]) + + +class TestIsKernelModule(unittest.TestCase): + """ + is_kernel_module() detects kernel modules by searching for the + "vermagic=" string, which is always present in genuine .ko files. + """ + + def _make_tmp(self, content: bytes) -> str: + f = tempfile.NamedTemporaryFile(delete=False, suffix=".ko") + f.write(content) + f.close() + return f.name + + def tearDown(self): + # Clean up any temp files created during the test. + for attr in ("_tmpfile",): + path = getattr(self, attr, None) + if path and os.path.exists(path): + os.unlink(path) + + def test_detects_vermagic(self): + self._tmpfile = self._make_tmp(b"\x7fELF\x00" * 10 + b"vermagic=5.15.0" + b"\x00" * 10) + self.assertTrue(is_kernel_module(self._tmpfile)) + + def test_rejects_plain_elf(self): + self._tmpfile = self._make_tmp(b"\x7fELF\x00" * 50) + self.assertFalse(is_kernel_module(self._tmpfile)) + + +class TestIsKernelModuleSigned(unittest.TestCase): + """ + is_kernel_module_signed() detects the "Module signature appended" tail + that the kernel's modsign infrastructure writes. + """ + + def _make_tmp(self, content: bytes) -> str: + f = tempfile.NamedTemporaryFile(delete=False, suffix=".ko") + f.write(content) + f.close() + return f.name + + def tearDown(self): + for attr in ("_tmpfile",): + path = getattr(self, attr, None) + if path and os.path.exists(path): + os.unlink(path) + + def test_detects_signed(self): + # Pad to >28 bytes so the seek(-28, 2) works; place the magic at the end. + tail = b"Module signature appended\n\x00\x00" + self._tmpfile = self._make_tmp(b"\x00" * 64 + tail) + self.assertTrue(is_kernel_module_signed(self._tmpfile)) + + def test_rejects_unsigned(self): + self._tmpfile = self._make_tmp(b"\x7fELF\x00" * 20) + self.assertFalse(is_kernel_module_signed(self._tmpfile)) + + +if __name__ == "__main__": + unittest.main() From patchwork Tue Apr 28 08:10:46 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sam Kent X-Patchwork-Id: 87056 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69413FF886C for ; Tue, 28 Apr 2026 09:00:19 +0000 (UTC) Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.8389.1777363920090557000 for ; Tue, 28 Apr 2026 01:12:00 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20251104 header.b=ZUsjKiF2; spf=pass (domain: gmail.com, ip: 209.85.221.42, mailfrom: sam.john.kent@gmail.com) Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-43cfde3c3f3so11204578f8f.3 for ; Tue, 28 Apr 2026 01:11:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777363918; x=1777968718; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iSPpAGe0QhXEcve7pLZOgeAXtZhG4hz4K0PrXKXCCsU=; b=ZUsjKiF2VutWCL0hznjTFID2rb/qQ6cNjN+2/hYuRf1s2WDLvgjz+cpTzhV1yT3MxW 1oQAxOVgy9Tlwb53Jez2J9u0joTNfx+0Rq7Gaw9S5NYQSQdAtnMiCNzyNg4+mF4SY/q5 U+Rsh+qQxKvMEvIyCHq8bzbC3FZvDo/GBOy86k5ZR/AxCU7tidhokieoH++7xH1DTaul f5BAbJDmcMGuM7k4jYcDgLPH2M3Iha4UsxtUF1Qc45jJZWmU7eW17wr1sTWAyauGrEWf nIZaX/tFfb2qRn4HROrbQ2a9RnYYiB49Bgm/OiSFZddeMCqEldSSrIZ/nUquOEPBHFHq wd+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777363918; x=1777968718; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=iSPpAGe0QhXEcve7pLZOgeAXtZhG4hz4K0PrXKXCCsU=; b=mQ2fEAxv/TqAn/zMCwBBJ1zJ7TzMrpWi7sH4Nzzj7uaPAAktT2VV1nEAiknoJjKCZ0 DM9OaMW10mNGiOSCZSH1zlDCmQFGediw/c3DeppmEOLvf2IdVSgKe1xnEcXauuFdoXrx f+zstLCFj7Uc/uNVmrjllbOO2/j2+NU/jocBKBmc5lErjZjla10d0v3Z1n+o2p/waZ1A tw8zZqVEVyCr/5JfDXDp3ticqp5vCDwFVXhFn8PJTb3KtVI58FFdTjeEpdo+ffZRm2CY p1kXF+5Fh2khuXWPOxv/FQ04X5wza8Ve5yvLcn65clH/ymFP/1cPEhq3InxugvChlqgU /eUg== X-Gm-Message-State: AOJu0YwsP7DLkjYLP2vu3lLUePGSP6446hc87jqb2bCwEzHSKlPJ1di7 pwwUMwCe6kx6My2fdBMXrkYFFty9tPuLxHX4eEfx25eK8zDWRkNHR5T/31qD5RP9PLc= X-Gm-Gg: AeBDievH3vkPtDtj7H1wDVXTjx2aeau0cKJ+t/ygM+dxPR/wkMxBWoQzf2xAxJ8TRSy 0JzXXJCIchLdl5V9W37hXLUKXLF1W0+Xmdm6ppW0yxfGuFlbYPWHDYo4c0iefccS+OdU1PaGulZ iOUjEcIFrnFdYP+MjALwNbN+i82WdKTnYk84KRY+J+WCpjW4qN9FIJzK1uIAiy/uCW2J+4PBhWE WrFWKmnweY95Vd5AOn5xaQngaD9HHUoXsbw0mbsHyyhJ/cFKrmbmDS0B7P00MSe/pU7qymJrLec 2soOhurkNwz+8dPmyKTY4E5+590ja2tyrqhcAg/6UOgdMr4pkt6R5US4j8zJZIrUFpNyS+4QiJP Z7awNzWAOGeBn8B3Q/VdZLMPNUXlKMp8N0UtJtfgfXqOw4k5f5QT9eiBwcNRdEx+XdJwzkEJpFP y+ClEdC3EtR5f5nTqlsHKvML0s7f1vgtMprz9CooR0zrPmhKTe1UewRK76G5GGPJjWyVODiej2z clW8hY= X-Received: by 2002:a5d:5f85:0:b0:43d:303f:f358 with SMTP id ffacd0b85a97d-4464761c249mr3514533f8f.2.1777363918081; Tue, 28 Apr 2026 01:11:58 -0700 (PDT) Received: from sam-ThinkPad-X1-Carbon-Gen-11.netbird.cloud ([79.123.125.82]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4463f4c07a2sm4588351f8f.20.2026.04.28.01.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2026 01:11:57 -0700 (PDT) From: "Sam Kent" To: openembedded-core@lists.openembedded.org Cc: Sam Kent Subject: [PATCH v2 3/3] oeqa/selftest: add oe-selftest for kernel module pre-filter Date: Tue, 28 Apr 2026 09:10:46 +0100 Message-Id: <20260428081046.1660101-4-sam.john.kent@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260428081046.1660101-1-sam.john.kent@gmail.com> References: <20260428081046.1660101-1-sam.john.kent@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Tue, 28 Apr 2026 09:00:19 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/236050 Add selftest-ko-filter recipe and a PackageTests.test_kmodule_prefilter oe-selftest that builds it to verify process_split_and_strip_files() handles .ko.xz/.ko.gz alongside a real .ko without corrupting them. Regression test for YOCTO #2348. AI-Generated: Uses Claude Sonnet 4.6 Signed-off-by: Sam Kent --- .../selftest-ko-filter/files/module.c | 3 ++ .../selftest-ko-filter/selftest-ko-filter.bb | 29 +++++++++++++++++++ meta/lib/oeqa/selftest/cases/package.py | 22 ++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 meta-selftest/recipes-test/selftest-ko-filter/files/module.c create mode 100644 meta-selftest/recipes-test/selftest-ko-filter/selftest-ko-filter.bb diff --git a/meta-selftest/recipes-test/selftest-ko-filter/files/module.c b/meta-selftest/recipes-test/selftest-ko-filter/files/module.c new file mode 100644 index 0000000..f6d50ba --- /dev/null +++ b/meta-selftest/recipes-test/selftest-ko-filter/files/module.c @@ -0,0 +1,3 @@ +/* SPDX-License-Identifier: MIT */ +/* Minimal relocatable object used as a .ko stand-in for pre-filter testing. */ +int selftest_ko_filter_marker = 42; diff --git a/meta-selftest/recipes-test/selftest-ko-filter/selftest-ko-filter.bb b/meta-selftest/recipes-test/selftest-ko-filter/selftest-ko-filter.bb new file mode 100644 index 0000000..1b8cc73 --- /dev/null +++ b/meta-selftest/recipes-test/selftest-ko-filter/selftest-ko-filter.bb @@ -0,0 +1,29 @@ +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# +SUMMARY = "Test fixture for the kernel-module file pre-filter in package.py" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" + +SRC_URI = "file://module.c" +S = "${UNPACKDIR}" + +MODDIR = "${libdir}/selftest-ko-filter" + +do_compile () { + ${CC} ${CFLAGS} -c module.c -o module.ko +} + +do_install () { + install -d ${D}${MODDIR} + install -m 0644 module.ko ${D}${MODDIR}/ + + # Fake compressed modules — the pre-filter must not pass these to strip. + # Use octal escapes: dash (the OE recipe shell) does not support \xHH in printf. + printf '\375\067\172\130\132\000' > ${D}${MODDIR}/module.ko.xz + printf '\037\213' > ${D}${MODDIR}/module.ko.gz +} + +FILES:${PN} = "${MODDIR}/*" diff --git a/meta/lib/oeqa/selftest/cases/package.py b/meta/lib/oeqa/selftest/cases/package.py index 38ed717..d33424b 100644 --- a/meta/lib/oeqa/selftest/cases/package.py +++ b/meta/lib/oeqa/selftest/cases/package.py @@ -185,6 +185,28 @@ class PackageTests(OESelftestTestCase): if not gdbtest(qemu, binary): self.fail('GDB %s failed' % binary) + def test_kmodule_prefilter(self): + # Regression test for YOCTO #2348: process_split_and_strip_files() must + # use f.endswith(".ko") so that compressed modules (.ko.xz, .ko.gz) are + # not fed to is_elf() / strip. + bitbake("selftest-ko-filter -c package") + + pkgdest = get_bb_var('PKGDEST', 'selftest-ko-filter') + libdir = get_bb_var('libdir', 'selftest-ko-filter') + moddir = pkgdest + "/selftest-ko-filter" + libdir + "/selftest-ko-filter" + + self.assertTrue(os.path.exists(moddir + "/module.ko"), + "module.ko missing from PKGDEST") + + for fname, magic in [("module.ko.xz", b"\xfd\x37\x7a\x58\x5a\x00"), + ("module.ko.gz", b"\x1f\x8b")]: + path = moddir + "/" + fname + self.assertTrue(os.path.exists(path), + "%s missing from PKGDEST" % fname) + with open(path, "rb") as f: + self.assertEqual(f.read(len(magic)), magic, + "%s header corrupted in PKGDEST" % fname) + def test_preserve_ownership(self): features = 'IMAGE_INSTALL:append = " selftest-chown"\n' self.write_config(features)