Patch "libbpf: Fix null-pointer dereference in find_prog_by_sec_insn()" has been added to the 5.10-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 null-pointer dereference in find_prog_by_sec_insn()

to the 5.10-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-null-pointer-dereference-in-find_prog_by_.patch
and it can be found in the queue-5.10 subdirectory.

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



commit 3908cc082bb8ebd156900f60e90b27b1e7aae96f
Author: Shung-Hsi Yu <shung-hsi.yu@xxxxxxxx>
Date:   Wed Oct 12 10:23:53 2022 +0800

    libbpf: Fix null-pointer dereference in find_prog_by_sec_insn()
    
    [ Upstream commit d0d382f95a9270dcf803539d6781d6bd67e3f5b2 ]
    
    When there are no program sections, obj->programs is left unallocated,
    and find_prog_by_sec_insn()'s search lands on &obj->programs[0] == NULL,
    and will cause null-pointer dereference in the following access to
    prog->sec_idx.
    
    Guard the search with obj->nr_programs similar to what's being done in
    __bpf_program__iter() to prevent null-pointer access from happening.
    
    Fixes: db2b8b06423c ("libbpf: Support CO-RE relocations for multi-prog sections")
    Signed-off-by: Shung-Hsi Yu <shung-hsi.yu@xxxxxxxx>
    Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx>
    Link: https://lore.kernel.org/bpf/20221012022353.7350-4-shung-hsi.yu@xxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 66d7f8d494de..015ed8253f73 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -3479,6 +3479,9 @@ static struct bpf_program *find_prog_by_sec_insn(const struct bpf_object *obj,
 	int l = 0, r = obj->nr_programs - 1, m;
 	struct bpf_program *prog;
 
+	if (!obj->nr_programs)
+		return NULL;
+
 	while (l < r) {
 		m = l + (r - l + 1) / 2;
 		prog = &obj->programs[m];



[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