| Message ID | 20261127115249.793478-1-christoph.steiger@siemens.com |
|---|---|
| State | New |
| Headers | show |
| Series | [1/1] kernel: add support for kernel SBOMs | expand |
On 27.11.26 12:52, 'Christoph Steiger' via isar-users wrote: > The kernel supports generating SPDX3 SBOMs [1]. These SBOMs are useful > for triaging vulnerabilities, among other things. > > If the kernel supports SBOMs provide a `linux-sboms` package. The > package is automatically built, but not installed automatically to the > rootfs. Actual SBOMs are always deployed to the image deploy directory > during a kernel build. How will this integrate with the image SBOMs one day? And don't we also want the file in the deploy folder, at least aside those images SBOMs? > > Kernels can be marked to support SBOMs with the newly introduced > `KERNEL_SBOM_SUPPORT` variable, which defaults to not supported. Can't we derive that from the existence of related files in the kerner sources or at least its version? Jan
On Fri, 2026-11-27 at 12:52 +0100, Christoph Steiger wrote: > The kernel supports generating SPDX3 SBOMs [1]. These SBOMs are useful > for triaging vulnerabilities, among other things. > > If the kernel supports SBOMs provide a `linux-sboms` package. The > package is automatically built, but not installed automatically to the > rootfs. Actual SBOMs are always deployed to the image deploy directory > during a kernel build. > > Kernels can be marked to support SBOMs with the newly introduced > `KERNEL_SBOM_SUPPORT` variable, which defaults to not supported. > > [1] https://docs.kernel.org/tools/sbom/sbom.html > > Signed-off-by: Christoph Steiger <christoph.steiger@siemens.com> > --- > doc/custom_kernel.md | 2 ++ > meta/classes-recipe/linux-kernel.bbclass | 29 +++++++++++++++++++ > .../linux/files/debian/control.tmpl | 6 ++++ > .../linux/files/debian/isar/build.tmpl | 6 +++- > .../linux/files/debian/isar/common.tmpl | 2 ++ > .../linux/files/debian/isar/install.tmpl | 14 +++++++++ > 6 files changed, 58 insertions(+), 1 deletion(-) > > diff --git a/doc/custom_kernel.md b/doc/custom_kernel.md > index ce5f1bf7..223113b6 100644 > --- a/doc/custom_kernel.md > +++ b/doc/custom_kernel.md > @@ -68,6 +68,8 @@ The linux-custom recipe provides support for: > > 14. Support `devshell` (kernel configuration shall be applied) > > + 15. Produce a `linux-sboms` package with kernel SBOMs Hi, isn't that linux-sboms-${KERNEL_NAME_PROVIDED} ? > + > ## Future > > In the future, the recipe may be extended to: > diff --git a/meta/classes-recipe/linux-kernel.bbclass b/meta/classes-recipe/linux-kernel.bbclass > index ac587b17..97a2ecf0 100644 > --- a/meta/classes-recipe/linux-kernel.bbclass > +++ b/meta/classes-recipe/linux-kernel.bbclass > @@ -45,6 +45,8 @@ KERNEL_LIBC_DEV_ARCH_ALL:ubuntu = "0" > > KERNEL_LIBC_DEV_DEPLOY ?= "0" > > +KERNEL_SBOM_SUPPORT ?= "0" > + > # Settings that may be changed on a per distro, machine or layer basis > # -------------------------------------------------------------------- > > @@ -197,6 +199,9 @@ RECIPE_PROVIDES = " \ > ${BPN}-pseudo-native \ > " > > +# Provide the sbom package if the kernel supports it > +RECIPE_PROVIDES:append = "${@ 'linux-sboms-${KERNEL_NAME_PROVIDED}' if bb.utils.to_boolean(d.getVar('KERNEL_SBOM_SUPPORT')) else ''}" > + > # Provide linux-libc-dev packages unless nolibcdev profile used > OVERRIDES:append = ":${@ bb.utils.contains('DEB_BUILD_PROFILES', 'pkg.{}.nolibcdev'.format(d.getVar('BPN')), '', 'libcdev', d)}" > > @@ -272,6 +277,9 @@ def get_additional_build_profiles(d): > profiles += ' pkg.{}.nolibcdev'.format(d.getVar('BPN')) > elif bb.utils.to_boolean(d.getVar('KERNEL_LIBC_DEV_ARCH_ALL')): > profiles += ' pkg.{}.libcdev-arch-all'.format(d.getVar('BPN')) > + > + if bb.utils.to_boolean(d.getVar('KERNEL_SBOM_SUPPORT')): > + profiles += ' pkg.{}.sbom'.format(d.getVar('BPN')) > return profiles > > KERNEL_LIBC_DEV_ARCH = "${@ bb.utils.contains('DEB_BUILD_PROFILES', 'pkg.{}.libcdev-arch-all'.format(d.getVar('BPN')), 'all\nMulti-Arch: foreign', 'any', d) }" > @@ -377,3 +385,24 @@ do_dpkg_source:prepend() { > dpkg_configure_kernel > get_localversion_auto > } > + > +SSTATETASKS += "do_deploy_sboms" > +DEPLOY_DIR_SBOMS = "${DEPLOYDIR}/sboms" > +do_deploy_sboms[cleandirs] += "${DEPLOY_DIR_SBOMS}" > +do_deploy_sboms[sstate-inputdirs] = "${DEPLOY_DIR_SBOMS}" > +do_deploy_sboms[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}" > +do_deploy_sboms() { > + dpkg --fsys-tarfile ${DEPLOYDIR}/linux-sboms-${KERNEL_NAME_PROVIDED}_*.deb | tar -xvf - -C ${DEPLOY_DIR_SBOMS} --strip-components=4 \ > + ./usr/share/linux-sboms-${KERNEL_NAME_PROVIDED}/sbom-build.spdx.json \ > + ./usr/share/linux-sboms-${KERNEL_NAME_PROVIDED}/sbom-output.spdx.json \ > + ./usr/share/linux-sboms-${KERNEL_NAME_PROVIDED}/sbom-source.spdx.json > + install -m 644 ${DEPLOY_DIR_SBOMS}/sbom-build.spdx.json ${DEPLOY_DIR_SBOMS}/linux-${KERNEL_NAME_PROVIDED}-${PV}-sbom-build.spdx.json > + install -m 644 ${DEPLOY_DIR_SBOMS}/sbom-output.spdx.json ${DEPLOY_DIR_SBOMS}/linux-${KERNEL_NAME_PROVIDED}-${PV}-sbom-output.spdx.json > + install -m 644 ${DEPLOY_DIR_SBOMS}/sbom-source.spdx.json ${DEPLOY_DIR_SBOMS}/linux-${KERNEL_NAME_PROVIDED}-${PV}-sbom-source.spdx.json > + rm ${DEPLOY_DIR_SBOMS}/sbom-build.spdx.json ${DEPLOY_DIR_SBOMS}/sbom-output.spdx.json ${DEPLOY_DIR_SBOMS}/sbom-source.spdx.json > +} > + > +python() { > + if bb.utils.to_boolean(d.getVar("KERNEL_SBOM_SUPPORT")): > + bb.build.addtask('do_deploy_sboms', 'do_deploy_deb', 'do_dpkg_build', d) > +} > diff --git a/meta/recipes-kernel/linux/files/debian/control.tmpl b/meta/recipes-kernel/linux/files/debian/control.tmpl > index 77c4048b..e2af1064 100644 > --- a/meta/recipes-kernel/linux/files/debian/control.tmpl > +++ b/meta/recipes-kernel/linux/files/debian/control.tmpl > @@ -69,3 +69,9 @@ Conflicts: linux-kbuild-${KERNEL_NAME_PROVIDED} > Description: ${KERNEL_NAME_PROVIDED} Linux kbuild scripts and tools for @KR@ > This package provides kernel kbuild scripts and tools for @KR@ > This is useful for people who need to build external modules > + > +Package: linux-sboms-${KERNEL_NAME_PROVIDED} > +Build-Profiles: <pkg.${BPN}.sbom> > +Architecture: any Isn't that an architecture all package, as the files are not architecture specific? I'm a bit unsure, though. > +Description: ${KERNEL_NAME_PROVIDED} Linux kernel SBOMs for @KR@ > + This package provides the kernel SBOMs for @KR@ on ${DISTRO_ARCH} We should not template with DISTRO_ARCH, as the package might be built and deployed for multiple architectures. The KR should already contain enough entropy to differentiate between kernel packages. For details, please also see 2e5de13a. > diff --git a/meta/recipes-kernel/linux/files/debian/isar/build.tmpl b/meta/recipes-kernel/linux/files/debian/isar/build.tmpl > index b4c105c1..79226d45 100644 > --- a/meta/recipes-kernel/linux/files/debian/isar/build.tmpl > +++ b/meta/recipes-kernel/linux/files/debian/isar/build.tmpl > @@ -17,12 +17,16 @@ do_build() { > # (use defaults for options that were not specified) > ${MAKE} O=${KERNEL_BUILD_DIR} olddefconfig prepare > > + if echo "${DEB_BUILD_PROFILES}" | grep -q "sbom"; then > + SBOM_TARGET="sbom" > + fi > + > # Transfer effective kernel version into control file and scripts > KR=$(${MAKE} O=${KERNEL_BUILD_DIR} -s --no-print-directory kernelrelease) > sed -i "s/@KR@/${KR}/g" ${S}/debian/control ${S}/debian/linux-image-${KERNEL_NAME_PROVIDED}.* > > if echo "${DEB_BUILD_PROFILES}" | grep -q "kernel"; then # Build kernel scripts and tools > - ${MAKE} O=${KERNEL_BUILD_DIR} ${PARALLEL_MAKE} ${KERNEL_EXTRA_BUILDARGS} KCFLAGS="${KCFLAGS}" KAFLAGS="${KAFLAGS}" > + ${MAKE} O=${KERNEL_BUILD_DIR} ${PARALLEL_MAKE} ${KERNEL_EXTRA_BUILDARGS} KCFLAGS="${KCFLAGS}" KAFLAGS="${KAFLAGS}" ${SBOM_TARGET} > elif echo "${DEB_BUILD_PROFILES}" | grep -q "kbuild"; then # Build kernel scripts and tools > ${MAKE} O=${KERNEL_BUILD_DIR} ${PARALLEL_MAKE} ${KERNEL_EXTRA_BUILDARGS} KCFLAGS="${KCFLAGS}" KAFLAGS="${KAFLAGS}" scripts > if grep -q -E "CONFIG_STACK_VALIDATION=y|CONFIG_HAVE_OBJTOOL=y" ${KERNEL_BUILD_DIR}/.config && [ -d "tools/objtool" ]; then > diff --git a/meta/recipes-kernel/linux/files/debian/isar/common.tmpl b/meta/recipes-kernel/linux/files/debian/isar/common.tmpl > index b7001ff5..0ca398b8 100644 > --- a/meta/recipes-kernel/linux/files/debian/isar/common.tmpl > +++ b/meta/recipes-kernel/linux/files/debian/isar/common.tmpl > @@ -12,6 +12,7 @@ KERNEL_PKG_LIBC_HEADERS=linux-libc-dev > KERNEL_PKG_LIBC_HEADERS_CROSS=linux-libc-dev-${DISTRO_ARCH}-cross > KERNEL_PKG_KERN_KBUILD=linux-kbuild-${KERNEL_NAME_PROVIDED} > KERNEL_PKG_KERN_KBUILD_CROSS=${KERNEL_PKG_KERN_KBUILD}-${DISTRO_ARCH}-cross > +KERNEL_PKG_SBOMS=linux-sboms-${KERNEL_NAME_PROVIDED} > > # Force creating debian package with valid host arch for -native build > # Use a cross build to comply with arch specific kernel defconfigs > @@ -42,6 +43,7 @@ deb_libc_hdr_dir=${deb_top_dir}/${KERNEL_PKG_LIBC_HEADERS} > deb_libc_hdr_cross_dir=${deb_top_dir}/${KERNEL_PKG_LIBC_HEADERS_CROSS} > deb_kern_kbuild_dir=${deb_top_dir}/${KERNEL_PKG_KERN_KBUILD} > deb_kern_kbuild_cross_dir=${deb_top_dir}/${KERNEL_PKG_KERN_KBUILD_CROSS} > +deb_kern_sboms_dir=${deb_top_dir}/${KERNEL_PKG_SBOMS} > > # Array of packages to be generated > declare -A kern_pkgs > diff --git a/meta/recipes-kernel/linux/files/debian/isar/install.tmpl b/meta/recipes-kernel/linux/files/debian/isar/install.tmpl > index 7975404b..2772b01c 100644 > --- a/meta/recipes-kernel/linux/files/debian/isar/install.tmpl > +++ b/meta/recipes-kernel/linux/files/debian/isar/install.tmpl > @@ -77,6 +77,7 @@ do_install() { > install_dtbs > install_kmods > install_headers > + install_sboms > fi > > # Stop tracing > @@ -253,6 +254,19 @@ install_headers() { > kernel_headers > } > > +sboms() { > + kernel_sboms_dir="usr/share/linux-sboms-${KERNEL_NAME_PROVIDED}" > + destdir=${deb_kern_sboms_dir}/${kernel_sboms_dir} > + > + mkdir -p ${destdir} > + install -m 644 ${O}/*.spdx.json ${destdir} > +} > + > +install_sboms() { > + [ -z "${kern_pkgs[${KERNEL_PKG_SBOMS}]}" ] && return 0 > + sboms > +} > + Felix > install_kbuild() { > kernel_kbuild_dir=usr/lib/linux-kbuild-${krel} > destdir=$1/${kernel_kbuild_dir} > -- > 2.47.3
On Fri, 2026-11-27 at 13:57 +0100, Jan Kiszka wrote: > On 27.11.26 12:52, 'Christoph Steiger' via isar-users wrote: > > The kernel supports generating SPDX3 SBOMs [1]. These SBOMs are useful > > for triaging vulnerabilities, among other things. > > > > If the kernel supports SBOMs provide a `linux-sboms` package. The > > package is automatically built, but not installed automatically to the > > rootfs. Actual SBOMs are always deployed to the image deploy directory > > during a kernel build. > > How will this integrate with the image SBOMs one day? And don't we also > want the file in the deploy folder, at least aside those images SBOMs? I briefly brainstormed this with Christoph. We will add the SBOM uuid as an external reference to the kernel package. The same approach can then also be used for container-in-image SBOMs. Flattening the SBOMs into the image one does not work, as they have different granularities (package vs. files). Another issue is that the kernel SBOMs are SPDX only. The corresponding debsbom feature will need to be developed. Regarding deployment: They are already deployed next to the image. > > > > > Kernels can be marked to support SBOMs with the newly introduced > > `KERNEL_SBOM_SUPPORT` variable, which defaults to not supported. > > Can't we derive that from the existence of related files in the kerner > sources or at least its version? We also considered this, but we need to create the bitbake tasks to do the deployment prior to having the kernel. Felix > > Jan > > -- > Siemens AG, Foundational Technologies > Linux Expert Center
On Fri, 2026-11-27 at 12:52 +0100, Christoph Steiger wrote: > The kernel supports generating SPDX3 SBOMs [1]. These SBOMs are useful > for triaging vulnerabilities, among other things. > > If the kernel supports SBOMs provide a `linux-sboms` package. The > package is automatically built, but not installed automatically to the > rootfs. Actual SBOMs are always deployed to the image deploy directory > during a kernel build. > > Kernels can be marked to support SBOMs with the newly introduced > `KERNEL_SBOM_SUPPORT` variable, which defaults to not supported. > > [1] https://docs.kernel.org/tools/sbom/sbom.html > > Signed-off-by: Christoph Steiger <christoph.steiger@siemens.com> > --- > doc/custom_kernel.md | 2 ++ > meta/classes-recipe/linux-kernel.bbclass | 29 +++++++++++++++++++ > .../linux/files/debian/control.tmpl | 6 ++++ > .../linux/files/debian/isar/build.tmpl | 6 +++- > .../linux/files/debian/isar/common.tmpl | 2 ++ > .../linux/files/debian/isar/install.tmpl | 14 +++++++++ PS: we need an in-tree kernel that supports this. We then also have to wire that into the testsuite. Felix
On 11/27/26 2:02 PM, Moessbauer, Felix (FT RPD CPC OES-DE) wrote: > On Fri, 2026-11-27 at 12:52 +0100, Christoph Steiger wrote: >> The kernel supports generating SPDX3 SBOMs [1]. These SBOMs are useful >> for triaging vulnerabilities, among other things. >> >> If the kernel supports SBOMs provide a `linux-sboms` package. The >> package is automatically built, but not installed automatically to the >> rootfs. Actual SBOMs are always deployed to the image deploy directory >> during a kernel build. >> >> Kernels can be marked to support SBOMs with the newly introduced >> `KERNEL_SBOM_SUPPORT` variable, which defaults to not supported. >> >> [1] https://docs.kernel.org/tools/sbom/sbom.html >> >> Signed-off-by: Christoph Steiger <christoph.steiger@siemens.com> >> --- >> doc/custom_kernel.md | 2 ++ >> meta/classes-recipe/linux-kernel.bbclass | 29 +++++++++++++++++++ >> .../linux/files/debian/control.tmpl | 6 ++++ >> .../linux/files/debian/isar/build.tmpl | 6 +++- >> .../linux/files/debian/isar/common.tmpl | 2 ++ >> .../linux/files/debian/isar/install.tmpl | 14 +++++++++ >> 6 files changed, 58 insertions(+), 1 deletion(-) >> >> diff --git a/doc/custom_kernel.md b/doc/custom_kernel.md >> index ce5f1bf7..223113b6 100644 >> --- a/doc/custom_kernel.md >> +++ b/doc/custom_kernel.md >> @@ -68,6 +68,8 @@ The linux-custom recipe provides support for: >> >> 14. Support `devshell` (kernel configuration shall be applied) >> >> + 15. Produce a `linux-sboms` package with kernel SBOMs > > Hi, > > isn't that linux-sboms-${KERNEL_NAME_PROVIDED} ? Yes, the actual name is with the kernel name included. The surrounding documentation does not mention the ${KERNEL_NAME_PROVIDED}, see e.g. `linux-headers` which should have the same suffix, but does not mention this in the docs. > >> + >> ## Future >> >> In the future, the recipe may be extended to: >> diff --git a/meta/classes-recipe/linux-kernel.bbclass b/meta/classes-recipe/linux-kernel.bbclass >> index ac587b17..97a2ecf0 100644 >> --- a/meta/classes-recipe/linux-kernel.bbclass >> +++ b/meta/classes-recipe/linux-kernel.bbclass >> @@ -45,6 +45,8 @@ KERNEL_LIBC_DEV_ARCH_ALL:ubuntu = "0" >> >> KERNEL_LIBC_DEV_DEPLOY ?= "0" >> >> +KERNEL_SBOM_SUPPORT ?= "0" >> + >> # Settings that may be changed on a per distro, machine or layer basis >> # -------------------------------------------------------------------- >> >> @@ -197,6 +199,9 @@ RECIPE_PROVIDES = " \ >> ${BPN}-pseudo-native \ >> " >> >> +# Provide the sbom package if the kernel supports it >> +RECIPE_PROVIDES:append = "${@ 'linux-sboms-${KERNEL_NAME_PROVIDED}' if bb.utils.to_boolean(d.getVar('KERNEL_SBOM_SUPPORT')) else ''}" >> + >> # Provide linux-libc-dev packages unless nolibcdev profile used >> OVERRIDES:append = ":${@ bb.utils.contains('DEB_BUILD_PROFILES', 'pkg.{}.nolibcdev'.format(d.getVar('BPN')), '', 'libcdev', d)}" >> >> @@ -272,6 +277,9 @@ def get_additional_build_profiles(d): >> profiles += ' pkg.{}.nolibcdev'.format(d.getVar('BPN')) >> elif bb.utils.to_boolean(d.getVar('KERNEL_LIBC_DEV_ARCH_ALL')): >> profiles += ' pkg.{}.libcdev-arch-all'.format(d.getVar('BPN')) >> + >> + if bb.utils.to_boolean(d.getVar('KERNEL_SBOM_SUPPORT')): >> + profiles += ' pkg.{}.sbom'.format(d.getVar('BPN')) >> return profiles >> >> KERNEL_LIBC_DEV_ARCH = "${@ bb.utils.contains('DEB_BUILD_PROFILES', 'pkg.{}.libcdev-arch-all'.format(d.getVar('BPN')), 'all\nMulti-Arch: foreign', 'any', d) }" >> @@ -377,3 +385,24 @@ do_dpkg_source:prepend() { >> dpkg_configure_kernel >> get_localversion_auto >> } >> + >> +SSTATETASKS += "do_deploy_sboms" >> +DEPLOY_DIR_SBOMS = "${DEPLOYDIR}/sboms" >> +do_deploy_sboms[cleandirs] += "${DEPLOY_DIR_SBOMS}" >> +do_deploy_sboms[sstate-inputdirs] = "${DEPLOY_DIR_SBOMS}" >> +do_deploy_sboms[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}" >> +do_deploy_sboms() { >> + dpkg --fsys-tarfile ${DEPLOYDIR}/linux-sboms-${KERNEL_NAME_PROVIDED}_*.deb | tar -xvf - -C ${DEPLOY_DIR_SBOMS} --strip-components=4 \ >> + ./usr/share/linux-sboms-${KERNEL_NAME_PROVIDED}/sbom-build.spdx.json \ >> + ./usr/share/linux-sboms-${KERNEL_NAME_PROVIDED}/sbom-output.spdx.json \ >> + ./usr/share/linux-sboms-${KERNEL_NAME_PROVIDED}/sbom-source.spdx.json >> + install -m 644 ${DEPLOY_DIR_SBOMS}/sbom-build.spdx.json ${DEPLOY_DIR_SBOMS}/linux-${KERNEL_NAME_PROVIDED}-${PV}-sbom-build.spdx.json >> + install -m 644 ${DEPLOY_DIR_SBOMS}/sbom-output.spdx.json ${DEPLOY_DIR_SBOMS}/linux-${KERNEL_NAME_PROVIDED}-${PV}-sbom-output.spdx.json >> + install -m 644 ${DEPLOY_DIR_SBOMS}/sbom-source.spdx.json ${DEPLOY_DIR_SBOMS}/linux-${KERNEL_NAME_PROVIDED}-${PV}-sbom-source.spdx.json >> + rm ${DEPLOY_DIR_SBOMS}/sbom-build.spdx.json ${DEPLOY_DIR_SBOMS}/sbom-output.spdx.json ${DEPLOY_DIR_SBOMS}/sbom-source.spdx.json >> +} >> + >> +python() { >> + if bb.utils.to_boolean(d.getVar("KERNEL_SBOM_SUPPORT")): >> + bb.build.addtask('do_deploy_sboms', 'do_deploy_deb', 'do_dpkg_build', d) >> +} >> diff --git a/meta/recipes-kernel/linux/files/debian/control.tmpl b/meta/recipes-kernel/linux/files/debian/control.tmpl >> index 77c4048b..e2af1064 100644 >> --- a/meta/recipes-kernel/linux/files/debian/control.tmpl >> +++ b/meta/recipes-kernel/linux/files/debian/control.tmpl >> @@ -69,3 +69,9 @@ Conflicts: linux-kbuild-${KERNEL_NAME_PROVIDED} >> Description: ${KERNEL_NAME_PROVIDED} Linux kbuild scripts and tools for @KR@ >> This package provides kernel kbuild scripts and tools for @KR@ >> This is useful for people who need to build external modules >> + >> +Package: linux-sboms-${KERNEL_NAME_PROVIDED} >> +Build-Profiles: <pkg.${BPN}.sbom> >> +Architecture: any > > Isn't that an architecture all package, as the files are not > architecture specific? I'm a bit unsure, though. > Me too :-) I am always a bit confused about the exact meaning and exact differences between `all` and `any`. Let me know if you have a preference and will adjust it accordingly. >> +Description: ${KERNEL_NAME_PROVIDED} Linux kernel SBOMs for @KR@ >> + This package provides the kernel SBOMs for @KR@ on ${DISTRO_ARCH} > > We should not template with DISTRO_ARCH, as the package might be built > and deployed for multiple architectures. The KR should already contain > enough entropy to differentiate between kernel packages. For details, > please also see 2e5de13a. > ACK, will change this in v2. >> diff --git a/meta/recipes-kernel/linux/files/debian/isar/build.tmpl b/meta/recipes-kernel/linux/files/debian/isar/build.tmpl >> index b4c105c1..79226d45 100644 >> --- a/meta/recipes-kernel/linux/files/debian/isar/build.tmpl >> +++ b/meta/recipes-kernel/linux/files/debian/isar/build.tmpl >> @@ -17,12 +17,16 @@ do_build() { >> # (use defaults for options that were not specified) >> ${MAKE} O=${KERNEL_BUILD_DIR} olddefconfig prepare >> >> + if echo "${DEB_BUILD_PROFILES}" | grep -q "sbom"; then >> + SBOM_TARGET="sbom" >> + fi >> + >> # Transfer effective kernel version into control file and scripts >> KR=$(${MAKE} O=${KERNEL_BUILD_DIR} -s --no-print-directory kernelrelease) >> sed -i "s/@KR@/${KR}/g" ${S}/debian/control ${S}/debian/linux-image-${KERNEL_NAME_PROVIDED}.* >> >> if echo "${DEB_BUILD_PROFILES}" | grep -q "kernel"; then # Build kernel scripts and tools >> - ${MAKE} O=${KERNEL_BUILD_DIR} ${PARALLEL_MAKE} ${KERNEL_EXTRA_BUILDARGS} KCFLAGS="${KCFLAGS}" KAFLAGS="${KAFLAGS}" >> + ${MAKE} O=${KERNEL_BUILD_DIR} ${PARALLEL_MAKE} ${KERNEL_EXTRA_BUILDARGS} KCFLAGS="${KCFLAGS}" KAFLAGS="${KAFLAGS}" ${SBOM_TARGET} >> elif echo "${DEB_BUILD_PROFILES}" | grep -q "kbuild"; then # Build kernel scripts and tools >> ${MAKE} O=${KERNEL_BUILD_DIR} ${PARALLEL_MAKE} ${KERNEL_EXTRA_BUILDARGS} KCFLAGS="${KCFLAGS}" KAFLAGS="${KAFLAGS}" scripts >> if grep -q -E "CONFIG_STACK_VALIDATION=y|CONFIG_HAVE_OBJTOOL=y" ${KERNEL_BUILD_DIR}/.config && [ -d "tools/objtool" ]; then >> diff --git a/meta/recipes-kernel/linux/files/debian/isar/common.tmpl b/meta/recipes-kernel/linux/files/debian/isar/common.tmpl >> index b7001ff5..0ca398b8 100644 >> --- a/meta/recipes-kernel/linux/files/debian/isar/common.tmpl >> +++ b/meta/recipes-kernel/linux/files/debian/isar/common.tmpl >> @@ -12,6 +12,7 @@ KERNEL_PKG_LIBC_HEADERS=linux-libc-dev >> KERNEL_PKG_LIBC_HEADERS_CROSS=linux-libc-dev-${DISTRO_ARCH}-cross >> KERNEL_PKG_KERN_KBUILD=linux-kbuild-${KERNEL_NAME_PROVIDED} >> KERNEL_PKG_KERN_KBUILD_CROSS=${KERNEL_PKG_KERN_KBUILD}-${DISTRO_ARCH}-cross >> +KERNEL_PKG_SBOMS=linux-sboms-${KERNEL_NAME_PROVIDED} >> >> # Force creating debian package with valid host arch for -native build >> # Use a cross build to comply with arch specific kernel defconfigs >> @@ -42,6 +43,7 @@ deb_libc_hdr_dir=${deb_top_dir}/${KERNEL_PKG_LIBC_HEADERS} >> deb_libc_hdr_cross_dir=${deb_top_dir}/${KERNEL_PKG_LIBC_HEADERS_CROSS} >> deb_kern_kbuild_dir=${deb_top_dir}/${KERNEL_PKG_KERN_KBUILD} >> deb_kern_kbuild_cross_dir=${deb_top_dir}/${KERNEL_PKG_KERN_KBUILD_CROSS} >> +deb_kern_sboms_dir=${deb_top_dir}/${KERNEL_PKG_SBOMS} >> >> # Array of packages to be generated >> declare -A kern_pkgs >> diff --git a/meta/recipes-kernel/linux/files/debian/isar/install.tmpl b/meta/recipes-kernel/linux/files/debian/isar/install.tmpl >> index 7975404b..2772b01c 100644 >> --- a/meta/recipes-kernel/linux/files/debian/isar/install.tmpl >> +++ b/meta/recipes-kernel/linux/files/debian/isar/install.tmpl >> @@ -77,6 +77,7 @@ do_install() { >> install_dtbs >> install_kmods >> install_headers >> + install_sboms >> fi >> >> # Stop tracing >> @@ -253,6 +254,19 @@ install_headers() { >> kernel_headers >> } >> >> +sboms() { >> + kernel_sboms_dir="usr/share/linux-sboms-${KERNEL_NAME_PROVIDED}" >> + destdir=${deb_kern_sboms_dir}/${kernel_sboms_dir} >> + >> + mkdir -p ${destdir} >> + install -m 644 ${O}/*.spdx.json ${destdir} >> +} >> + >> +install_sboms() { >> + [ -z "${kern_pkgs[${KERNEL_PKG_SBOMS}]}" ] && return 0 >> + sboms >> +} >> + > > Felix > >> install_kbuild() { >> kernel_kbuild_dir=usr/lib/linux-kbuild-${krel} >> destdir=$1/${kernel_kbuild_dir} >> -- >> 2.47.3 >
On 11/27/26 2:11 PM, Moessbauer, Felix (FT RPD CPC OES-DE) wrote: > On Fri, 2026-11-27 at 12:52 +0100, Christoph Steiger wrote: >> The kernel supports generating SPDX3 SBOMs [1]. These SBOMs are useful >> for triaging vulnerabilities, among other things. >> >> If the kernel supports SBOMs provide a `linux-sboms` package. The >> package is automatically built, but not installed automatically to the >> rootfs. Actual SBOMs are always deployed to the image deploy directory >> during a kernel build. >> >> Kernels can be marked to support SBOMs with the newly introduced >> `KERNEL_SBOM_SUPPORT` variable, which defaults to not supported. >> >> [1] https://docs.kernel.org/tools/sbom/sbom.html >> >> Signed-off-by: Christoph Steiger <christoph.steiger@siemens.com> >> --- >> doc/custom_kernel.md | 2 ++ >> meta/classes-recipe/linux-kernel.bbclass | 29 +++++++++++++++++++ >> .../linux/files/debian/control.tmpl | 6 ++++ >> .../linux/files/debian/isar/build.tmpl | 6 +++- >> .../linux/files/debian/isar/common.tmpl | 2 ++ >> .../linux/files/debian/isar/install.tmpl | 14 +++++++++ > > PS: we need an in-tree kernel that supports this. We then also have to > wire that into the testsuite. > True, I tested this in isar-cip-core with CIP kernels and the kernel SBOM series applied. I was not quite sure how I could setup an easy test here, but if you want to play around with my test setup I can provide you the patches for it. > Felix > >
On Fri, 2026-11-27 at 14:19 +0100, Christoph Steiger wrote: > On 11/27/26 2:11 PM, Moessbauer, Felix (FT RPD CPC OES-DE) wrote: > > On Fri, 2026-11-27 at 12:52 +0100, Christoph Steiger wrote: > > > The kernel supports generating SPDX3 SBOMs [1]. These SBOMs are useful > > > for triaging vulnerabilities, among other things. > > > > > > If the kernel supports SBOMs provide a `linux-sboms` package. The > > > package is automatically built, but not installed automatically to the > > > rootfs. Actual SBOMs are always deployed to the image deploy directory > > > during a kernel build. > > > > > > Kernels can be marked to support SBOMs with the newly introduced > > > `KERNEL_SBOM_SUPPORT` variable, which defaults to not supported. > > > > > > [1] https://docs.kernel.org/tools/sbom/sbom.html > > > > > > Signed-off-by: Christoph Steiger <christoph.steiger@siemens.com> > > > --- > > > doc/custom_kernel.md | 2 ++ > > > meta/classes-recipe/linux-kernel.bbclass | 29 +++++++++++++++++++ > > > .../linux/files/debian/control.tmpl | 6 ++++ > > > .../linux/files/debian/isar/build.tmpl | 6 +++- > > > .../linux/files/debian/isar/common.tmpl | 2 ++ > > > .../linux/files/debian/isar/install.tmpl | 14 +++++++++ > > > > PS: we need an in-tree kernel that supports this. We then also have to > > wire that into the testsuite. > > > True, I tested this in isar-cip-core with CIP kernels and the kernel SBOM > series applied. I was not quite sure how I could setup an easy test here, > but if you want to play around with my test setup I can provide you the > patches for it. Can't we just add a rather recent mainline kernel in isar (maybe in meta-test to denote nobody updates this) and build that in citest.py:KernelTests ? Felix > > > Felix > > > >
diff --git a/doc/custom_kernel.md b/doc/custom_kernel.md index ce5f1bf7..223113b6 100644 --- a/doc/custom_kernel.md +++ b/doc/custom_kernel.md @@ -68,6 +68,8 @@ The linux-custom recipe provides support for: 14. Support `devshell` (kernel configuration shall be applied) + 15. Produce a `linux-sboms` package with kernel SBOMs + ## Future In the future, the recipe may be extended to: diff --git a/meta/classes-recipe/linux-kernel.bbclass b/meta/classes-recipe/linux-kernel.bbclass index ac587b17..97a2ecf0 100644 --- a/meta/classes-recipe/linux-kernel.bbclass +++ b/meta/classes-recipe/linux-kernel.bbclass @@ -45,6 +45,8 @@ KERNEL_LIBC_DEV_ARCH_ALL:ubuntu = "0" KERNEL_LIBC_DEV_DEPLOY ?= "0" +KERNEL_SBOM_SUPPORT ?= "0" + # Settings that may be changed on a per distro, machine or layer basis # -------------------------------------------------------------------- @@ -197,6 +199,9 @@ RECIPE_PROVIDES = " \ ${BPN}-pseudo-native \ " +# Provide the sbom package if the kernel supports it +RECIPE_PROVIDES:append = "${@ 'linux-sboms-${KERNEL_NAME_PROVIDED}' if bb.utils.to_boolean(d.getVar('KERNEL_SBOM_SUPPORT')) else ''}" + # Provide linux-libc-dev packages unless nolibcdev profile used OVERRIDES:append = ":${@ bb.utils.contains('DEB_BUILD_PROFILES', 'pkg.{}.nolibcdev'.format(d.getVar('BPN')), '', 'libcdev', d)}" @@ -272,6 +277,9 @@ def get_additional_build_profiles(d): profiles += ' pkg.{}.nolibcdev'.format(d.getVar('BPN')) elif bb.utils.to_boolean(d.getVar('KERNEL_LIBC_DEV_ARCH_ALL')): profiles += ' pkg.{}.libcdev-arch-all'.format(d.getVar('BPN')) + + if bb.utils.to_boolean(d.getVar('KERNEL_SBOM_SUPPORT')): + profiles += ' pkg.{}.sbom'.format(d.getVar('BPN')) return profiles KERNEL_LIBC_DEV_ARCH = "${@ bb.utils.contains('DEB_BUILD_PROFILES', 'pkg.{}.libcdev-arch-all'.format(d.getVar('BPN')), 'all\nMulti-Arch: foreign', 'any', d) }" @@ -377,3 +385,24 @@ do_dpkg_source:prepend() { dpkg_configure_kernel get_localversion_auto } + +SSTATETASKS += "do_deploy_sboms" +DEPLOY_DIR_SBOMS = "${DEPLOYDIR}/sboms" +do_deploy_sboms[cleandirs] += "${DEPLOY_DIR_SBOMS}" +do_deploy_sboms[sstate-inputdirs] = "${DEPLOY_DIR_SBOMS}" +do_deploy_sboms[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}" +do_deploy_sboms() { + dpkg --fsys-tarfile ${DEPLOYDIR}/linux-sboms-${KERNEL_NAME_PROVIDED}_*.deb | tar -xvf - -C ${DEPLOY_DIR_SBOMS} --strip-components=4 \ + ./usr/share/linux-sboms-${KERNEL_NAME_PROVIDED}/sbom-build.spdx.json \ + ./usr/share/linux-sboms-${KERNEL_NAME_PROVIDED}/sbom-output.spdx.json \ + ./usr/share/linux-sboms-${KERNEL_NAME_PROVIDED}/sbom-source.spdx.json + install -m 644 ${DEPLOY_DIR_SBOMS}/sbom-build.spdx.json ${DEPLOY_DIR_SBOMS}/linux-${KERNEL_NAME_PROVIDED}-${PV}-sbom-build.spdx.json + install -m 644 ${DEPLOY_DIR_SBOMS}/sbom-output.spdx.json ${DEPLOY_DIR_SBOMS}/linux-${KERNEL_NAME_PROVIDED}-${PV}-sbom-output.spdx.json + install -m 644 ${DEPLOY_DIR_SBOMS}/sbom-source.spdx.json ${DEPLOY_DIR_SBOMS}/linux-${KERNEL_NAME_PROVIDED}-${PV}-sbom-source.spdx.json + rm ${DEPLOY_DIR_SBOMS}/sbom-build.spdx.json ${DEPLOY_DIR_SBOMS}/sbom-output.spdx.json ${DEPLOY_DIR_SBOMS}/sbom-source.spdx.json +} + +python() { + if bb.utils.to_boolean(d.getVar("KERNEL_SBOM_SUPPORT")): + bb.build.addtask('do_deploy_sboms', 'do_deploy_deb', 'do_dpkg_build', d) +} diff --git a/meta/recipes-kernel/linux/files/debian/control.tmpl b/meta/recipes-kernel/linux/files/debian/control.tmpl index 77c4048b..e2af1064 100644 --- a/meta/recipes-kernel/linux/files/debian/control.tmpl +++ b/meta/recipes-kernel/linux/files/debian/control.tmpl @@ -69,3 +69,9 @@ Conflicts: linux-kbuild-${KERNEL_NAME_PROVIDED} Description: ${KERNEL_NAME_PROVIDED} Linux kbuild scripts and tools for @KR@ This package provides kernel kbuild scripts and tools for @KR@ This is useful for people who need to build external modules + +Package: linux-sboms-${KERNEL_NAME_PROVIDED} +Build-Profiles: <pkg.${BPN}.sbom> +Architecture: any +Description: ${KERNEL_NAME_PROVIDED} Linux kernel SBOMs for @KR@ + This package provides the kernel SBOMs for @KR@ on ${DISTRO_ARCH} diff --git a/meta/recipes-kernel/linux/files/debian/isar/build.tmpl b/meta/recipes-kernel/linux/files/debian/isar/build.tmpl index b4c105c1..79226d45 100644 --- a/meta/recipes-kernel/linux/files/debian/isar/build.tmpl +++ b/meta/recipes-kernel/linux/files/debian/isar/build.tmpl @@ -17,12 +17,16 @@ do_build() { # (use defaults for options that were not specified) ${MAKE} O=${KERNEL_BUILD_DIR} olddefconfig prepare + if echo "${DEB_BUILD_PROFILES}" | grep -q "sbom"; then + SBOM_TARGET="sbom" + fi + # Transfer effective kernel version into control file and scripts KR=$(${MAKE} O=${KERNEL_BUILD_DIR} -s --no-print-directory kernelrelease) sed -i "s/@KR@/${KR}/g" ${S}/debian/control ${S}/debian/linux-image-${KERNEL_NAME_PROVIDED}.* if echo "${DEB_BUILD_PROFILES}" | grep -q "kernel"; then # Build kernel scripts and tools - ${MAKE} O=${KERNEL_BUILD_DIR} ${PARALLEL_MAKE} ${KERNEL_EXTRA_BUILDARGS} KCFLAGS="${KCFLAGS}" KAFLAGS="${KAFLAGS}" + ${MAKE} O=${KERNEL_BUILD_DIR} ${PARALLEL_MAKE} ${KERNEL_EXTRA_BUILDARGS} KCFLAGS="${KCFLAGS}" KAFLAGS="${KAFLAGS}" ${SBOM_TARGET} elif echo "${DEB_BUILD_PROFILES}" | grep -q "kbuild"; then # Build kernel scripts and tools ${MAKE} O=${KERNEL_BUILD_DIR} ${PARALLEL_MAKE} ${KERNEL_EXTRA_BUILDARGS} KCFLAGS="${KCFLAGS}" KAFLAGS="${KAFLAGS}" scripts if grep -q -E "CONFIG_STACK_VALIDATION=y|CONFIG_HAVE_OBJTOOL=y" ${KERNEL_BUILD_DIR}/.config && [ -d "tools/objtool" ]; then diff --git a/meta/recipes-kernel/linux/files/debian/isar/common.tmpl b/meta/recipes-kernel/linux/files/debian/isar/common.tmpl index b7001ff5..0ca398b8 100644 --- a/meta/recipes-kernel/linux/files/debian/isar/common.tmpl +++ b/meta/recipes-kernel/linux/files/debian/isar/common.tmpl @@ -12,6 +12,7 @@ KERNEL_PKG_LIBC_HEADERS=linux-libc-dev KERNEL_PKG_LIBC_HEADERS_CROSS=linux-libc-dev-${DISTRO_ARCH}-cross KERNEL_PKG_KERN_KBUILD=linux-kbuild-${KERNEL_NAME_PROVIDED} KERNEL_PKG_KERN_KBUILD_CROSS=${KERNEL_PKG_KERN_KBUILD}-${DISTRO_ARCH}-cross +KERNEL_PKG_SBOMS=linux-sboms-${KERNEL_NAME_PROVIDED} # Force creating debian package with valid host arch for -native build # Use a cross build to comply with arch specific kernel defconfigs @@ -42,6 +43,7 @@ deb_libc_hdr_dir=${deb_top_dir}/${KERNEL_PKG_LIBC_HEADERS} deb_libc_hdr_cross_dir=${deb_top_dir}/${KERNEL_PKG_LIBC_HEADERS_CROSS} deb_kern_kbuild_dir=${deb_top_dir}/${KERNEL_PKG_KERN_KBUILD} deb_kern_kbuild_cross_dir=${deb_top_dir}/${KERNEL_PKG_KERN_KBUILD_CROSS} +deb_kern_sboms_dir=${deb_top_dir}/${KERNEL_PKG_SBOMS} # Array of packages to be generated declare -A kern_pkgs diff --git a/meta/recipes-kernel/linux/files/debian/isar/install.tmpl b/meta/recipes-kernel/linux/files/debian/isar/install.tmpl index 7975404b..2772b01c 100644 --- a/meta/recipes-kernel/linux/files/debian/isar/install.tmpl +++ b/meta/recipes-kernel/linux/files/debian/isar/install.tmpl @@ -77,6 +77,7 @@ do_install() { install_dtbs install_kmods install_headers + install_sboms fi # Stop tracing @@ -253,6 +254,19 @@ install_headers() { kernel_headers } +sboms() { + kernel_sboms_dir="usr/share/linux-sboms-${KERNEL_NAME_PROVIDED}" + destdir=${deb_kern_sboms_dir}/${kernel_sboms_dir} + + mkdir -p ${destdir} + install -m 644 ${O}/*.spdx.json ${destdir} +} + +install_sboms() { + [ -z "${kern_pkgs[${KERNEL_PKG_SBOMS}]}" ] && return 0 + sboms +} + install_kbuild() { kernel_kbuild_dir=usr/lib/linux-kbuild-${krel} destdir=$1/${kernel_kbuild_dir}
The kernel supports generating SPDX3 SBOMs [1]. These SBOMs are useful for triaging vulnerabilities, among other things. If the kernel supports SBOMs provide a `linux-sboms` package. The package is automatically built, but not installed automatically to the rootfs. Actual SBOMs are always deployed to the image deploy directory during a kernel build. Kernels can be marked to support SBOMs with the newly introduced `KERNEL_SBOM_SUPPORT` variable, which defaults to not supported. [1] https://docs.kernel.org/tools/sbom/sbom.html Signed-off-by: Christoph Steiger <christoph.steiger@siemens.com> --- doc/custom_kernel.md | 2 ++ meta/classes-recipe/linux-kernel.bbclass | 29 +++++++++++++++++++ .../linux/files/debian/control.tmpl | 6 ++++ .../linux/files/debian/isar/build.tmpl | 6 +++- .../linux/files/debian/isar/common.tmpl | 2 ++ .../linux/files/debian/isar/install.tmpl | 14 +++++++++ 6 files changed, 58 insertions(+), 1 deletion(-)