Skip to content

Commit 0d6a2a4

Browse files
nandedamanasmb49
authored andcommitted
libbpf: Fix out-of-bound read
BugLink: https://bugs.launchpad.net/bugs/2115678 [ 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> Signed-off-by: Manuel Diewald <manuel.diewald@canonical.com> Signed-off-by: Mehmet Basaran <mehmet.basaran@canonical.com>
1 parent d4e470f commit 0d6a2a4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2106,7 +2106,7 @@ static int set_kcfg_value_str(struct extern_desc *ext, char *ext_val,
21062106
}
21072107

21082108
len = strlen(value);
2109-
if (value[len - 1] != '"') {
2109+
if (len < 2 || value[len - 1] != '"') {
21102110
pr_warn("extern (kcfg) '%s': invalid string config '%s'\n",
21112111
ext->name, value);
21122112
return -EINVAL;

0 commit comments

Comments
 (0)