Patch "libbpf: Add NULL checks to bpf_object__{prev_map,next_map}" 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: Add NULL checks to bpf_object__{prev_map,next_map}

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-add-null-checks-to-bpf_object__-prev_map-next.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 1562484e3a48be236bf88343618e0aad9ec04c40
Author: Andreas Ziegler <ziegler.andreas@xxxxxxxxxxx>
Date:   Wed Jul 3 10:34:36 2024 +0200

    libbpf: Add NULL checks to bpf_object__{prev_map,next_map}
    
    [ Upstream commit cedc12c5b57f7efa6dbebfb2b140e8675f5a2616 ]
    
    In the current state, an erroneous call to
    bpf_object__find_map_by_name(NULL, ...) leads to a segmentation
    fault through the following call chain:
    
      bpf_object__find_map_by_name(obj = NULL, ...)
      -> bpf_object__for_each_map(pos, obj = NULL)
      -> bpf_object__next_map((obj = NULL), NULL)
      -> return (obj = NULL)->maps
    
    While calling bpf_object__find_map_by_name with obj = NULL is
    obviously incorrect, this should not lead to a segmentation
    fault but rather be handled gracefully.
    
    As __bpf_map__iter already handles this situation correctly, we
    can delegate the check for the regular case there and only add
    a check in case the prev or next parameter is NULL.
    
    Signed-off-by: Andreas Ziegler <ziegler.andreas@xxxxxxxxxxx>
    Signed-off-by: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
    Link: https://lore.kernel.org/bpf/20240703083436.505124-1-ziegler.andreas@xxxxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 015ed8253f73..33cdcfe10634 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -9005,7 +9005,7 @@ __bpf_map__iter(const struct bpf_map *m, const struct bpf_object *obj, int i)
 struct bpf_map *
 bpf_map__next(const struct bpf_map *prev, const struct bpf_object *obj)
 {
-	if (prev == NULL)
+	if (prev == NULL && obj != NULL)
 		return obj->maps;
 
 	return __bpf_map__iter(prev, obj, 1);
@@ -9014,7 +9014,7 @@ bpf_map__next(const struct bpf_map *prev, const struct bpf_object *obj)
 struct bpf_map *
 bpf_map__prev(const struct bpf_map *next, const struct bpf_object *obj)
 {
-	if (next == NULL) {
+	if (next == NULL && obj != NULL) {
 		if (!obj->nr_maps)
 			return NULL;
 		return obj->maps + obj->nr_maps - 1;




[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