]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
libbpf: Fix out-of-bound read
authorNandakumar Edamana <nandakumar@nandakumar.co.in>
Fri, 21 Feb 2025 21:01:11 +0000 (02:31 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 4 Jun 2025 12:40:11 +0000 (14:40 +0200)
commit75b01247b43015fe168273540bba8ea4ac0608e8
treeaa5b22f483f9d48270de58401ee0f62ae5fc68d1
parent01b4545bbc23391646354f94441ad2cc75e8e3f8
libbpf: Fix out-of-bound read

[ Upstream commit 236d3910117e9f97ebf75e511d8bcc950f1a4e5f ]

In `set_kcfg_value_str`, an untrusted string is accessed with the assumption
that it will be at least two characters long due to the presence of checks for
opening and closing quotes. But the check for the closing quote
(value[len - 1] != '"') misses the fact that it could be checking the opening
quote itself in case of an invalid input that consists of just the opening
quote.

This commit adds an explicit check to make sure the string is at least two
characters long.

Signed-off-by: Nandakumar Edamana <nandakumar@nandakumar.co.in>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250221210110.3182084-1-nandakumar@nandakumar.co.in
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/lib/bpf/libbpf.c