Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of kernel vmlinuz extractor. #360

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

brnpl
Copy link
Contributor

@brnpl brnpl commented Dec 23, 2024

Pull request for the kernel vmlinuz extractor.

Implemented:

  • Extractor implementation;
  • Unit test implementation;
  • Integrated extractor in the main tool;

binary/proto/proto.go Outdated Show resolved Hide resolved
docs/supported_inventory_types.md Outdated Show resolved Hide resolved
extractor/filesystem/os/kernel/vmlinuz/vmlinuz.go Outdated Show resolved Hide resolved
extractor/filesystem/os/kernel/vmlinuz/vmlinuz.go Outdated Show resolved Hide resolved
// Architecture
case strings.HasPrefix(t, "x86 "):
architecture = "x86"
case strings.HasPrefix(t, "ARM64 "):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these values ever appear? In the magic library code I just see "x86 boot executable" as an option but nothing related to ARM:
https://github.com/deitch/magic/blob/c67ab88f10cb7323bd698f7fe7fb0c41f3af4da5/pkg/magic/internal/kernel.go#L15

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, here's an example of the metadata extracted from a vmlinuz archive on my Raspberry Pi:

/boot/vmlinuz-6.1.0-rpi7-rpi-v7: Linux kernel ARM boot executable zImage (little-endian)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried scanning this vmlinuz archive with Scalibr, and I encountered an error while extracting the magic type:

plugin_status: {
  name:  "os/kernel/vmlinuz"
  status: {
    status:  PARTIALLY_SUCCEEDED
    failure_reason:  "home/bruno/go/pkg/mod/golang.org/[email protected]/src/debug/pe/testdata/vmlinuz-4.15.0-47-generic: error determining magic type: EOF\nhome/bruno/vmlinuz: error determining magic type: EOF\nhome/bruno/Downloads/vmlinuz-6.1.0-rpi7-rpi-v7: no match with linux kernel found\nusr/share/go-1.18/src/debug/pe/testdata/vmlinuz-4.15.0-47-generic: error determining magic type: EOF\n
    ...

As you highlighted above the library (github.com/deitch/magic/pkg/magic) doesn’t currently handle ARM-based kernel files correctly. Let me know if you prefer to remove support for ARM64 and ARM architecture in the code

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we aware of any other libraries that might be able to parse the ARM values properly?
If this just checks for specific magic bytes at specific offsets how hard would it be for us to implement our own parsing for ARM?

extractor/filesystem/os/kernel/vmlinuz/vmlinuz_test.go Outdated Show resolved Hide resolved
extractor/filesystem/os/kernel/vmlinuz/vmlinuz_test.go Outdated Show resolved Hide resolved
extractor/filesystem/os/kernel/vmlinuz/vmlinuz_test.go Outdated Show resolved Hide resolved
@erikvarga
Copy link
Collaborator

Some merge conflicts will need to be resolved here too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants