Patch "libbpf: Fix segfault in static linker for objects without BTF" has been added to the 5.14-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    libbpf: Fix segfault in static linker for objects without BTF

to the 5.14-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     libbpf-fix-segfault-in-static-linker-for-objects-wit.patch
and it can be found in the queue-5.14 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit cbb6ee365aa0dc45d15ef22b752453d98bf325d8
Author: Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx>
Date:   Fri Sep 24 08:07:25 2021 +0530

    libbpf: Fix segfault in static linker for objects without BTF
    
    [ Upstream commit bcfd367c2839f2126c048fe59700ec1b538e2b06 ]
    
    When a BPF object is compiled without BTF info (without -g),
    trying to link such objects using bpftool causes a SIGSEGV due to
    btf__get_nr_types accessing obj->btf which is NULL. Fix this by
    checking for the NULL pointer, and return error.
    
    Reproducer:
    $ cat a.bpf.c
    extern int foo(void);
    int bar(void) { return foo(); }
    $ cat b.bpf.c
    int foo(void) { return 0; }
    $ clang -O2 -target bpf -c a.bpf.c
    $ clang -O2 -target bpf -c b.bpf.c
    $ bpftool gen obj out a.bpf.o b.bpf.o
    Segmentation fault (core dumped)
    
    After fix:
    $ bpftool gen obj out a.bpf.o b.bpf.o
    libbpf: failed to find BTF info for object 'a.bpf.o'
    Error: failed to link 'a.bpf.o': Unknown error -22 (-22)
    
    Fixes: a46349227cd8 (libbpf: Add linker extern resolution support for functions and global variables)
    Signed-off-by: Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx>
    Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx>
    Signed-off-by: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
    Link: https://lore.kernel.org/bpf/20210924023725.70228-1-memxor@xxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c
index 10911a8cad0f..2df880cefdae 100644
--- a/tools/lib/bpf/linker.c
+++ b/tools/lib/bpf/linker.c
@@ -1649,11 +1649,17 @@ static bool btf_is_non_static(const struct btf_type *t)
 static int find_glob_sym_btf(struct src_obj *obj, Elf64_Sym *sym, const char *sym_name,
 			     int *out_btf_sec_id, int *out_btf_id)
 {
-	int i, j, n = btf__get_nr_types(obj->btf), m, btf_id = 0;
+	int i, j, n, m, btf_id = 0;
 	const struct btf_type *t;
 	const struct btf_var_secinfo *vi;
 	const char *name;
 
+	if (!obj->btf) {
+		pr_warn("failed to find BTF info for object '%s'\n", obj->filename);
+		return -EINVAL;
+	}
+
+	n = btf__get_nr_types(obj->btf);
 	for (i = 1; i <= n; i++) {
 		t = btf__type_by_id(obj->btf, i);
 



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux