libbpf: Improve relocation ambiguity detection
authorAndrii Nakryiko <andriin@fb.com>
Tue, 18 Aug 2020 22:39:15 +0000 (15:39 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 19 Aug 2020 01:12:45 +0000 (18:12 -0700)
commit353c788c2054257359114f12827d86f8e3332e10
tree76da039698fb3c846183f722e82f3d03c854200d
parent28b93c64499ae09d9dc8c04123b15f8654a93c4c
libbpf: Improve relocation ambiguity detection

Split the instruction patching logic into relocation value calculation and
application of relocation to instruction. Using this, evaluate relocation
against each matching candidate and validate that all candidates agree on
relocated value. If not, report ambiguity and fail load.

This logic is necessary to avoid dangerous (however unlikely) accidental match
against two incompatible candidate types. Without this change, libbpf will
pick a random type as *the* candidate and apply potentially invalid
relocation.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200818223921.2911963-4-andriin@fb.com
tools/lib/bpf/libbpf.c