Skip to content

Commit ee20ff2

Browse files
nandedamanaopsiff
authored andcommitted
libbpf: Fix out-of-bound read
[ Upstream commit 236d391 ] 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 <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected] Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit ecd205a5241dff6b9030aa69f90c65a364511adb)
1 parent 7b1dcd4 commit ee20ff2

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
@@ -1802,7 +1802,7 @@ static int set_kcfg_value_str(struct extern_desc *ext, char *ext_val,
18021802
}
18031803

18041804
len = strlen(value);
1805-
if (value[len - 1] != '"') {
1805+
if (len < 2 || value[len - 1] != '"') {
18061806
pr_warn("extern (kcfg) '%s': invalid string config '%s'\n",
18071807
ext->name, value);
18081808
return -EINVAL;

0 commit comments

Comments
 (0)