Bug 2065638

Summary: libbpf SEGFAULT with fully stripped BPF object
Product: Red Hat Enterprise Linux 9 Reporter: Felix Maurer <fmaurer>
Component: libbpfAssignee: Viktor Malik <vmalik>
Status: CLOSED ERRATA QA Contact: Zhiqian Guan <zhguan>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 9.0CC: vmalik, zhguan
Target Milestone: rcKeywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libbpf-0.6.0-1.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-11-15 11:21:16 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 2069045    
Bug Blocks:    

Description Felix Maurer 2022-03-18 11:43:07 UTC
Description of problem:
Trying to load an BPF object, which was fully stripped, using ip/libbpf fails with a SEGFAULT.


Version-Release number of selected component (if applicable):
iproute-5.15.0-2.el9.x86_64
libbpf-0.5.0-4.el9.x86_64
kernel-5.14.0-72.el9.x86_64


How reproducible:
Always


Steps to Reproduce:
This example is based on a BPF selftest failure. The behavior is very likely to occur in other places as well.
1. # cd /usr/libexec/kselftests/bpf
2. # ip link add dev veth0 type veth peer name veth1
3. # strip sample_map_ret0.o
4. # ip link set dev veth0 xdp obj sample_map_ret0.o sec .text verbose


Actual results:
libbpf: loading sample_map_ret0.o
libbpf: elf: section(1) .text, size 176, link 0, flags 6, type=1
Segmentation fault (core dumped)


Expected results:
Loading a fully stripped BPF file can not work but it should fail with a friendly error message.

Comment 1 Viktor Malik 2022-04-08 06:47:39 UTC
Requires upstream commit:

    03e601f48b2 libbpf: Don't crash on object files with no symbol tables

which should be pulled in as a part of BPF 5.16 rebase.

Comment 2 Viktor Malik 2022-07-18 08:34:23 UTC
libbpf 0.6.0 should contain the commit mentioned above

Comment 3 Zhiqian Guan 2022-07-20 03:43:29 UTC
Tested on kernel 5.14.0-130.el9.x86_64
[root@netqe12 ~]# cd /usr/libexec/kselftests/bpf
[root@netqe12 bpf]# ip link add dev veth0 type veth peer name veth1
[root@netqe12 bpf]# strip sample_map_ret0.o
[root@netqe12 bpf]# ip link set dev veth0 xdp obj sample_map_ret0.o sec .text verbose
libbpf: loading sample_map_ret0.o
libbpf: elf: couldn't find symbol table in sample_map_ret0.o, stripped object file?
ERROR: opening BPF object file failed

The error msg looks more friendly. 

Since the patch has already been merged by bpf update, so mark this as testOnly.

Comment 10 Zhiqian Guan 2022-07-20 14:16:22 UTC
Based on comment3, move this to VERIFIED

Comment 12 errata-xmlrpc 2022-11-15 11:21:16 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (libbpf bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:8364