Skip to content

Commit 8f325a0

Browse files
aspskKernel Patches Daemon
authored andcommitted
bpf: add a check to make static analysers happy
In [1] Dan Carpenter reported that the following code makes the Smatch static analyser unhappy: 17904 value = map->ops->map_lookup_elem(map, &i); 17905 if (!value) 17906 return -EINVAL; --> 17907 items[i - start] = value->xlated_off; The analyser assumes that the `value` variable may contain an error and thus it should be properly checked before the dereference. On practice this will never happen as array maps do not return error values in map_lookup_elem, but to make the Smatch and other possible analysers happy this patch adds a formal check. Reported-by: Dan Carpenter <[email protected]> Closes: https://lore.kernel.org/bpf/[email protected]/ [1] Fixes: 493d9e0 ("bpf, x86: add support for indirect jumps") Signed-off-by: Anton Protopopov <[email protected]>
1 parent bfb0726 commit 8f325a0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

kernel/bpf/verifier.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17929,7 +17929,13 @@ static int copy_insn_array(struct bpf_map *map, u32 start, u32 end, u32 *items)
1792917929

1793017930
for (i = start; i <= end; i++) {
1793117931
value = map->ops->map_lookup_elem(map, &i);
17932-
if (!value)
17932+
/*
17933+
* map_lookup_elem of an array map will never return an error,
17934+
* but not checking it makes some static analysers to worry
17935+
*/
17936+
if (IS_ERR(value))
17937+
return PTR_ERR(value);
17938+
else if (!value)
1793317939
return -EINVAL;
1793417940
items[i - start] = value->xlated_off;
1793517941
}

0 commit comments

Comments
 (0)