From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Hou Tao <houtao1@huawei.com>, Andrii Nakryiko <andrii@kernel.org>,
Sasha Levin <sashal@kernel.org>,
ast@kernel.org, daniel@iogearbox.net, bpf@vger.kernel.org
Subject: [PATCH AUTOSEL 6.6 15/15] bpf: Check validity of link->type in bpf_link_show_fdinfo()
Date: Mon, 28 Oct 2024 06:52:11 -0400 [thread overview]
Message-ID: <20241028105218.3559888-15-sashal@kernel.org> (raw)
In-Reply-To: <20241028105218.3559888-1-sashal@kernel.org>
From: Hou Tao <houtao1@huawei.com>
[ Upstream commit 8421d4c8762bd022cb491f2f0f7019ef51b4f0a7 ]
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@huawei.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20241024013558.1135167-3-houtao@huaweicloud.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
kernel/bpf/syscall.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index b1933d074f051..74245c5251915 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -2963,13 +2963,17 @@ 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] = { };
- seq_printf(m,
- "link_type:\t%s\n"
- "link_id:\t%u\n",
- bpf_link_type_strs[link->type],
- link->id);
+ 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);
+
if (prog) {
bin2hex(prog_tag, prog->tag, sizeof(prog->tag));
seq_printf(m,
--
2.43.0
next prev parent reply other threads:[~2024-10-28 10:52 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-28 10:51 [PATCH AUTOSEL 6.6 01/15] xfrm: extract dst lookup parameters into a struct Sasha Levin
2024-10-28 10:51 ` [PATCH AUTOSEL 6.6 02/15] ASoC: amd: yc: Add quirk for ASUS Vivobook S15 M3502RA Sasha Levin
2024-10-28 10:51 ` [PATCH AUTOSEL 6.6 03/15] ASoC: fsl_esai: change dev_warn to dev_dbg in irq handler Sasha Levin
2024-10-28 10:52 ` [PATCH AUTOSEL 6.6 04/15] ASoC: amd: yc: Fix non-functional mic on ASUS E1404FA Sasha Levin
2024-10-28 10:52 ` [PATCH AUTOSEL 6.6 05/15] fs: Fix uninitialized value issue in from_kuid and from_kgid Sasha Levin
2024-10-28 10:52 ` [PATCH AUTOSEL 6.6 06/15] HID: multitouch: Add quirk for Logitech Bolt receiver w/ Casa touchpad Sasha Levin
2024-10-28 10:52 ` [PATCH AUTOSEL 6.6 07/15] HID: lenovo: Add support for Thinkpad X1 Tablet Gen 3 keyboard Sasha Levin
2024-10-28 10:52 ` [PATCH AUTOSEL 6.6 08/15] RISCV: KVM: use raw_spinlock for critical section in imsic Sasha Levin
2024-10-28 10:52 ` [PATCH AUTOSEL 6.6 09/15] fsl/fman: Save device references taken in mac_probe() Sasha Levin
2024-10-28 10:52 ` [PATCH AUTOSEL 6.6 10/15] ASoC: rt722-sdca: increase clk_stop_timeout to fix clock stop issue Sasha Levin
2024-10-28 10:52 ` [PATCH AUTOSEL 6.6 11/15] LoongArch: Use "Exception return address" to comment ERA Sasha Levin
2024-10-28 10:52 ` [PATCH AUTOSEL 6.6 12/15] platform/x86: dell-wmi: Ignore suspend notifications Sasha Levin
2024-10-28 10:52 ` [PATCH AUTOSEL 6.6 13/15] ASoC: fsl_micfil: Add sample rate constraint Sasha Levin
2024-10-28 10:52 ` [PATCH AUTOSEL 6.6 14/15] net: usb: qmi_wwan: add Fibocom FG132 0x0112 composition Sasha Levin
2024-10-28 10:52 ` Sasha Levin [this message]
2024-11-24 17:28 ` [PATCH AUTOSEL 6.6 01/15] xfrm: extract dst lookup parameters into a struct Pavel Machek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241028105218.3559888-15-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=houtao1@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®