Skip to content

Commit

Permalink
elf_reader: check if ELF machine type is for BPF data
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Lehner <dev@der-flo.net>
  • Loading branch information
florianl authored and ti-mo committed Nov 2, 2022
1 parent b4f36f0 commit c92998d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions elf_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ func LoadCollectionSpecFromReader(rd io.ReaderAt) (*CollectionSpec, error) {
return nil, err
}

// Checks if the ELF file is for BPF data.
// Old LLVM versions set e_machine to EM_NONE.
if f.File.Machine != unix.EM_NONE && f.File.Machine != elf.EM_BPF {
return nil, fmt.Errorf("unexpected machine type for BPF ELF: %s", f.File.Machine)
}

var (
licenseSection *elf.Section
versionSection *elf.Section
Expand Down
2 changes: 2 additions & 0 deletions internal/unix/types_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ const (
SIGPROF = linux.SIGPROF
SIG_BLOCK = linux.SIG_BLOCK
SIG_UNBLOCK = linux.SIG_UNBLOCK
EM_NONE = linux.EM_NONE
EM_BPF = linux.EM_BPF
)

type Statfs_t = linux.Statfs_t
Expand Down
2 changes: 2 additions & 0 deletions internal/unix/types_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ const (
SIGPROF
SIG_BLOCK
SIG_UNBLOCK
EM_NONE
EM_BPF
)

type Statfs_t struct {
Expand Down

0 comments on commit c92998d

Please sign in to comment.