Skip to content

Commit de64926

Browse files
Hou TaoKernel Patches Daemon
authored andcommitted
bpf: Free element after unlock in __htab_map_lookup_and_delete_elem()
The freeing of special fields in map value may acquire a spin-lock (e.g., the freeing of bpf_timer), however, the lookup_and_delete_elem procedure has already held a raw-spin-lock, which violates the lockdep rule. The running context of __htab_map_lookup_and_delete_elem() has already disabled the migration. Therefore, it is OK to invoke free_htab_elem() after unlocking the bucket lock. Fix the potential problem by freeing element after unlocking bucket lock in __htab_map_lookup_and_delete_elem(). Signed-off-by: Hou Tao <[email protected]>
1 parent 0c16cd5 commit de64926

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

kernel/bpf/hashtab.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,14 +1663,16 @@ static int __htab_map_lookup_and_delete_elem(struct bpf_map *map, void *key,
16631663
check_and_init_map_value(map, value);
16641664
}
16651665
hlist_nulls_del_rcu(&l->hash_node);
1666-
if (!is_lru_map)
1667-
free_htab_elem(htab, l);
16681666

16691667
out_unlock:
16701668
htab_unlock_bucket(htab, b, hash, bflags);
16711669

1672-
if (is_lru_map && l)
1673-
htab_lru_push_free(htab, l);
1670+
if (l) {
1671+
if (is_lru_map)
1672+
htab_lru_push_free(htab, l);
1673+
else
1674+
free_htab_elem(htab, l);
1675+
}
16741676

16751677
return ret;
16761678
}

0 commit comments

Comments
 (0)