Skip to content

Integrating KernelSbom into linux kernel repo #85

@augelu-tng

Description

@augelu-tng
  • Should the sbom.py be placed into linux/tools or linux/scripts ?

    linux/
    └── tools/
        └── sbom/
            ├── lib/
            ├── tests/
            ├── Makefile
            └── sbom.py 
    
    linux/
      └── scripts/
          └── lib/
              ├── sbom/
              │   ├── cmd_graph/
              │   ├── spdx/
              │   └── spdx_graph/
              └── sbom.py 
    

    A: I am leaning towards tools because tools seem to be more commonly invoked within the make build process. We could for example do things similar to how objtool does it.

  • How to call the tool via make?
    A: If we put the sbom.py script into tools we can call it manually via make -C tools sbom. For that, a make rule needs to be added to the top level tools/Makefile:

    sbom: FORCE
      $(call descend,sbom)

    This descends into the custom tools/sbom/Makefile which then invokes the python script. However, this would create an entirely new process separate to the kernel build itself. In this process we would not have access to make variables such as ARCH or HOSTCC. Therefore, we need to call the sbom script directly from within the main make process.
    We could do things similar to how objtool does it, i.e., definining a CONFIG_SBOM option (similar to CONFIG_OBJTOOL in linux/lib/Kconfig.debug). Then we can conditionally check if this option is set similar to here:

    ifdef CONFIG_OBJTOOL
    prepare: tools/objtool
    endif

    In our case we would do:

    ifdef CONFIG_SBOM
    all: tools/sbom
    endif

    In theory via a pattern rule the make command would already be delegated to tools/Makefile. However, the tool should only run after the build has finished. This requires an explicit rule that depends on some targets. Probably something like this:

    ifdef CONFIG_SBOM
    all: tools/sbom
    tools/sbom: vmlinux modules 
    	$(Q)$(MAKE) O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ sbom
    endif

Note: There is a comment that states that for new tools no new tools/* entry should be added but instead the "hostprogs" syntax should be used, see documentation/kbuild/makefiles. This seems to only be relevant for compiled tools.

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions