diff --git a/sbom/sbom/cmd_graph/savedcmd_parser/command_parser_registry.py b/sbom/sbom/cmd_graph/savedcmd_parser/command_parser_registry.py index 6e5f939..d1f8289 100644 --- a/sbom/sbom/cmd_graph/savedcmd_parser/command_parser_registry.py +++ b/sbom/sbom/cmd_graph/savedcmd_parser/command_parser_registry.py @@ -96,6 +96,12 @@ def _parse_link_vmlinux_command(command: str) -> list[PathStr]: return ["vmlinux.a"] +def _parse_cp_command(command: str) -> list[PathStr]: + positionals = tokenize_single_command_positionals_only(command) + # expect positionals to be ["cp", input1, ..., destination] + return positionals[1:-1] + + def _parse_noop(command: str) -> list[PathStr]: """ No-op parser for commands with no input files (e.g., 'rm', 'true'). @@ -197,6 +203,12 @@ def _parse_vdso2c_command(command: str) -> list[PathStr]: return [positionals[1], positionals[2]] +def _parse_vdsomunge_command(command: str) -> list[PathStr]: + positionals = tokenize_single_command_positionals_only(command) + # expect positionals to be ['vdsomunge', input, output] + return [positionals[1]] + + def _parse_ld_command(command: str) -> list[PathStr]: command_parts = tokenize_single_command( command=command.strip(), @@ -396,6 +408,8 @@ def env_or_default_pattern(env_value: str | None, default_pattern: str) -> str: (re.compile(r"^rm\b"), _parse_noop), (re.compile(r"^mkdir\b"), _parse_noop), (re.compile(r"^touch\b"), _parse_noop), + (re.compile(r"^cp\b"), _parse_cp_command), + (re.compile(r"^truncate\b"), _parse_noop), (re.compile(r"^cat\b.*?[\|>]"), lambda c: _parse_cat_command(c.split("|")[0].split(">")[0])), (re.compile(r"^echo[^|]*$"), _parse_noop), (re.compile(r"^sed.*?>"), lambda c: _parse_sed_command(c.split(">")[0])), @@ -453,6 +467,7 @@ def env_or_default_pattern(env_value: str | None, default_pattern: str) -> str: (re.compile(r"sh (.*/)?gen_initramfs\.sh\b"), _parse_gen_initramfs_command), (re.compile(r"sh (.*/)?checkundef\.sh\b"), _parse_noop), (re.compile(r"(.*/)?vdso2c\b"), _parse_vdso2c_command), + (re.compile(r"(.*/)?vdsomunge\b"), _parse_vdsomunge_command), (re.compile(r"^(.*/)?mkpiggy.*?>"), _parse_mkpiggy_command), (re.compile(r"^(.*/)?relocs\b"), _parse_relocs_command), (re.compile(r"^(.*/)?mk_elfconfig.*?<.*?>"), _parse_mk_elfconfig_command), diff --git a/sbom/sbom/spdx_graph/kernel_file.py b/sbom/sbom/spdx_graph/kernel_file.py index f6600d4..cc7f7d3 100644 --- a/sbom/sbom/spdx_graph/kernel_file.py +++ b/sbom/sbom/spdx_graph/kernel_file.py @@ -249,7 +249,7 @@ def includes_path_segments(path_segments: list[str]) -> bool: return "source" # Libraries - if ends_with([".a", ".so", ".rlib"]): + if ends_with([".a", ".so", ".so.raw", ".rlib"]): return "library" # Archives @@ -257,11 +257,11 @@ def includes_path_segments(path_segments: list[str]) -> bool: return "archive" # Applications - if ends_with(["bzImage", "Image"]): + if ends_with(["bzImage", "Image", ".efi"]): return "application" # Executables / machine code - if ends_with([".bin", ".elf", "vmlinux", "vmlinux.unstripped", "bpfilter_umh"]): + if ends_with([".bin", ".elf", "vmlinux", "vmlinux.unstripped", "vmlinuz", "bpfilter_umh"]): return "executable" # Kernel modules diff --git a/sbom/tests/cmd_graph/test_savedcmd_parser.py b/sbom/tests/cmd_graph/test_savedcmd_parser.py index 00bb68c..561ae01 100644 --- a/sbom/tests/cmd_graph/test_savedcmd_parser.py +++ b/sbom/tests/cmd_graph/test_savedcmd_parser.py @@ -215,6 +215,12 @@ def test_strip(self): expected = "drivers/firmware/efi/libstub/mem.o" self._assert_parsing(cmd, expected) + # cp command tests + def test_cp_truncate(self): + cmd = "cp arch/arm64/boot/Image arch/arm64/boot/vmlinux.bin; truncate -s $$(hexdump -s16 -n4 -e '\"%u\"' arch/arm64/boot/Image) arch/arm64/boot/vmlinux.bin" + expected = "arch/arm64/boot/Image" + self._assert_parsing(cmd, expected) + # rustc command tests def test_rustc(self): cmd = """OBJTREE=/workspace/linux/kernel_build rustc -Zbinary_dep_depinfo=y -Astable_features -Dnon_ascii_idents -Dunsafe_op_in_unsafe_fn -Wmissing_docs -Wrust_2018_idioms -Wclippy::all -Wclippy::as_ptr_cast_mut -Wclippy::as_underscore -Wclippy::cast_lossless -Wclippy::ignored_unit_patterns -Wclippy::mut_mut -Wclippy::needless_bitwise_bool -Aclippy::needless_lifetimes -Wclippy::no_mangle_with_rust_abi -Wclippy::ptr_as_ptr -Wclippy::ptr_cast_constness -Wclippy::ref_as_ptr -Wclippy::undocumented_unsafe_blocks -Wclippy::unnecessary_safety_comment -Wclippy::unnecessary_safety_doc -Wrustdoc::missing_crate_level_docs -Wrustdoc::unescaped_backticks -Cpanic=abort -Cembed-bitcode=n -Clto=n -Cforce-unwind-tables=n -Ccodegen-units=1 -Csymbol-mangling-version=v0 -Crelocation-model=static -Zfunction-sections=n -Wclippy::float_arithmetic --target=./scripts/target.json -Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-avx,-avx2 -Zcf-protection=branch -Zno-jump-tables -Ctarget-cpu=x86-64 -Ztune-cpu=generic -Cno-redzone=y -Ccode-model=kernel -Zfunction-return=thunk-extern -Zpatchable-function-entry=16,16 -Copt-level=2 -Cdebug-assertions=n -Coverflow-checks=y -Dwarnings @./include/generated/rustc_cfg --edition=2021 --cfg no_fp_fmt_parse --emit=dep-info=rust/.core.o.d --emit=obj=rust/core.o --emit=metadata=rust/libcore.rmeta --crate-type rlib -L./rust --crate-name core /usr/lib/rust-1.84/lib/rustlib/src/rust/library/core/src/lib.rs --sysroot=/dev/null ;llvm-objcopy --redefine-sym __addsf3=__rust__addsf3 --redefine-sym __eqsf2=__rust__eqsf2 --redefine-sym __extendsfdf2=__rust__extendsfdf2 --redefine-sym __gesf2=__rust__gesf2 --redefine-sym __lesf2=__rust__lesf2 --redefine-sym __ltsf2=__rust__ltsf2 --redefine-sym __mulsf3=__rust__mulsf3 --redefine-sym __nesf2=__rust__nesf2 --redefine-sym __truncdfsf2=__rust__truncdfsf2 --redefine-sym __unordsf2=__rust__unordsf2 --redefine-sym __adddf3=__rust__adddf3 --redefine-sym __eqdf2=__rust__eqdf2 --redefine-sym __ledf2=__rust__ledf2 --redefine-sym __ltdf2=__rust__ltdf2 --redefine-sym __muldf3=__rust__muldf3 --redefine-sym __unorddf2=__rust__unorddf2 --redefine-sym __muloti4=__rust__muloti4 --redefine-sym __multi3=__rust__multi3 --redefine-sym __udivmodti4=__rust__udivmodti4 --redefine-sym __udivti3=__rust__udivti3 --redefine-sym __umodti3=__rust__umodti3 rust/core.o""" @@ -317,6 +323,12 @@ def test_vdso2c(self): expected = "arch/x86/entry/vdso/vdso64.so.dbg arch/x86/entry/vdso/vdso64.so" self._assert_parsing(cmd, expected) + # vdsomunge command tests + def test_vdsomunge(self): + cmd = "arch/arm64/kernel/vdso32/../../../arm/vdso/vdsomunge arch/arm64/kernel/vdso32/vdso.so.raw arch/arm64/kernel/vdso32/vdso32.so.dbg" + expected = "arch/arm64/kernel/vdso32/vdso.so.raw" + self._assert_parsing(cmd, expected) + # mkpiggy command tests def test_mkpiggy(self): cmd = "arch/x86/boot/compressed/mkpiggy arch/x86/boot/compressed/vmlinux.bin.gz > arch/x86/boot/compressed/piggy.S"