[PATCH] tap: check that file is BPF arch before extracting

Stephen Hemminger stephen at networkplumber.org
Sun Jan 7 18:40:10 CET 2024


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")
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
 drivers/net/tap/bpf/bpf_extract.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/tap/bpf/bpf_extract.py b/drivers/net/tap/bpf/bpf_extract.py
index b630c42b809f..72c15cf7ad12 100644
--- a/drivers/net/tap/bpf/bpf_extract.py
+++ b/drivers/net/tap/bpf/bpf_extract.py
@@ -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)
-- 
2.43.0



More information about the dev mailing list