Skip to contentSkip to conversation

tap: check that file is BPF arch before extracting

PATCH New Stephen Hemminger 1 participant 1 message Jan 7, 2024 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tap: check that file is BPF arch before extracting

The script to extract BPF instructions from compiled ELF file would break if the ELF file was incorrectly built. Add simple check to give better message.

Fixes 4e679a5f1212 ("net/tap: add infrastructure to build BPF filter")
---
 drivers/net/tap/bpf/bpf_extract.py | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/tap/bpf/bpf_extract.py +2 -0
index b630c42b809f..72c15cf7ad12 100644
@@ -77,6 +77,8 @@ def main():
         write_header(out, args.source)
         for path in args.file:
             elffile = ELFFile(open_input(path))
+            if elffile['e_machine'] != 'EM_BPF':
+                sys.exit(f'{path} is not BPF')
             sections = load_sections(elffile)
             for name, insns in sections:
                 dump_section(name, insns, out)
Signature · 1 line
2.43.0