Skip to contentSkip to conversation

bpf: off by one in check_map_func_compatibility()

PATCH In review Dan Carpenter 2 participants 2 messages Aug 13, 2015

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: off by one in check_map_func_compatibility()

The loop iterates one space too far, so we might read beyond the end of the func_limit[] array.

Fixes 35578d798400 ('bpf: Implement function bpf_perf_event_read() that get the selected hardware PMU conuter')
kernel/bpf/verifier.c +1 -1
index 48e1c71..ed12e38 100644
@@ -853,7 +853,7 @@ static int check_map_func_compatibility(struct bpf_map *map, int func_id)
 	if (!map)
 		return 0;
 
-	for (i = 0; i <= ARRAY_SIZE(func_limit); i++) {
+	for (i = 0; i < ARRAY_SIZE(func_limit); i++) {
 		bool_map = (map->map_type = func_limit[i].map_type);
 		bool_func = (func_id = func_limit[i].func_id);
 		/* only when map & func pair match it can continue.
maintainer
#1 lore raw
Quoted 5 lines · Dan Carpenter

The loop iterates one space too far, so we might read beyond the end of the func_limit[] array.

Fixes 35578d798400 ('bpf: Implement function bpf_perf_event_read() that get the selected hardware PMU conuter')

Thanks for the fix, Dan!

There's however already one queued up here:

https://git.kernel.org/cgit/linux/kernel/git/davem/net-next.git/commit/?id0d8b335a9beb234fd0ed9a15aa6a47f47fd771

Quoted 18 lines
kernel/bpf/verifier.c +1 -2
index 48e1c71..ed12e38 100644
@@ -853,7 +853,7 @@ static int check_map_func_compatibility(struct bpf_map *map, int func_id)
  	if (!map)
  		return 0;
 
-	for (i = 0; i <= ARRAY_SIZE(func_limit); i++) {
+	for (i = 0; i < ARRAY_SIZE(func_limit); i++) {
  		bool_map = (map->map_type = func_limit[i].map_type);
  		bool_func = (func_id = func_limit[i].func_id);
  		/* only when map & func pair match it can continue.
--

To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html