Patch "bpf: Check validity of link->type in bpf_link_show_fdinfo()" has been added to the 5.15-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

    bpf: Check validity of link->type in bpf_link_show_fdinfo()

to the 5.15-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:
     bpf-check-validity-of-link-type-in-bpf_link_show_fdi.patch
and it can be found in the queue-5.15 subdirectory.

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



commit ee9f0443b129c3f50d6b792e5160fe4e2647da2a
Author: Hou Tao <houtao1@xxxxxxxxxx>
Date:   Fri Dec 27 14:04:35 2024 +0800

    bpf: Check validity of link->type in bpf_link_show_fdinfo()
    
    commit 8421d4c8762bd022cb491f2f0f7019ef51b4f0a7 upstream.
    
    If a newly-added link type doesn't invoke BPF_LINK_TYPE(), accessing
    bpf_link_type_strs[link->type] may result in an out-of-bounds access.
    
    To spot such missed invocations early in the future, checking the
    validity of link->type in bpf_link_show_fdinfo() and emitting a warning
    when such invocations are missed.
    
    Signed-off-by: Hou Tao <houtao1@xxxxxxxxxx>
    Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx>
    Link: https://lore.kernel.org/bpf/20241024013558.1135167-3-houtao@xxxxxxxxxxxxxxx
    [ shung-hsi.yu: break up existing seq_printf() call since commit 68b04864ca42
      ("bpf: Create links for BPF struct_ops maps.") is not present ]
    Signed-off-by: Shung-Hsi Yu <shung-hsi.yu@xxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index d4b4a47081b5..37aa1e319165 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -2522,16 +2522,21 @@ static void bpf_link_show_fdinfo(struct seq_file *m, struct file *filp)
 {
 	const struct bpf_link *link = filp->private_data;
 	const struct bpf_prog *prog = link->prog;
+	enum bpf_link_type type = link->type;
 	char prog_tag[sizeof(prog->tag) * 2 + 1] = { };
 
+	if (type < ARRAY_SIZE(bpf_link_type_strs) && bpf_link_type_strs[type]) {
+		seq_printf(m, "link_type:\t%s\n", bpf_link_type_strs[type]);
+	} else {
+		WARN_ONCE(1, "missing BPF_LINK_TYPE(...) for link type %u\n", type);
+		seq_printf(m, "link_type:\t<%u>\n", type);
+	}
+	seq_printf(m, "link_id:\t%u\n", link->id);
+
 	bin2hex(prog_tag, prog->tag, sizeof(prog->tag));
 	seq_printf(m,
-		   "link_type:\t%s\n"
-		   "link_id:\t%u\n"
 		   "prog_tag:\t%s\n"
 		   "prog_id:\t%u\n",
-		   bpf_link_type_strs[link->type],
-		   link->id,
 		   prog_tag,
 		   prog->aux->id);
 	if (link->ops->show_fdinfo)




[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