All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] libbpf: fix off-by-one error in ELF sanity check
@ 2019-10-28 23:37 Andrii Nakryiko
  2019-10-29  3:29 ` Alexei Starovoitov
  0 siblings, 1 reply; 2+ messages in thread
From: Andrii Nakryiko @ 2019-10-28 23:37 UTC (permalink / raw)
  To: bpf, netdev, ast, daniel; +Cc: andrii.nakryiko, kernel-team, Andrii Nakryiko

libbpf's bpf_object__elf_collect() does simple sanity check after iterating
over all ELF sections, if checks that .strtab index is correct. Unfortunately,
due to section indices being 1-based, the check breaks for cases when .strtab
ends up being the very last section in ELF.

Fixes: 77ba9a5b48a7 ("tools lib bpf: Fetch map names from correct strtab")
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index d71631a01926..5d15cc4dfcd6 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1664,7 +1664,7 @@ static int bpf_object__elf_collect(struct bpf_object *obj, bool relaxed_maps)
 		}
 	}
 
-	if (!obj->efile.strtabidx || obj->efile.strtabidx >= idx) {
+	if (!obj->efile.strtabidx || obj->efile.strtabidx > idx) {
 		pr_warn("Corrupted ELF file: index of strtab invalid\n");
 		return -LIBBPF_ERRNO__FORMAT;
 	}
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH bpf-next] libbpf: fix off-by-one error in ELF sanity check
  2019-10-28 23:37 [PATCH bpf-next] libbpf: fix off-by-one error in ELF sanity check Andrii Nakryiko
@ 2019-10-29  3:29 ` Alexei Starovoitov
  0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2019-10-29  3:29 UTC (permalink / raw)
  To: Andrii Nakryiko, bpf, netdev, daniel; +Cc: andrii.nakryiko, Kernel Team

On 10/28/19 4:37 PM, Andrii Nakryiko wrote:
> libbpf's bpf_object__elf_collect() does simple sanity check after iterating
> over all ELF sections, if checks that .strtab index is correct. Unfortunately,
> due to section indices being 1-based, the check breaks for cases when .strtab
> ends up being the very last section in ELF.
> 
> Fixes: 77ba9a5b48a7 ("tools lib bpf: Fetch map names from correct strtab")
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>

4 year old bug. Nice!
Applied. Thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-29  3:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-28 23:37 [PATCH bpf-next] libbpf: fix off-by-one error in ELF sanity check Andrii Nakryiko
2019-10-29  3:29 ` Alexei Starovoitov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.