Skip to content

Commit

Permalink
bpf: Free element after unlock in __htab_map_lookup_and_delete_elem()
Browse files Browse the repository at this point in the history
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 <houtao1@huawei.com>
  • Loading branch information
Hou Tao authored and Kernel Patches Daemon committed Jan 10, 2025
1 parent 08b4684 commit 6711fab
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions kernel/bpf/hashtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -1663,14 +1663,16 @@ static int __htab_map_lookup_and_delete_elem(struct bpf_map *map, void *key,
check_and_init_map_value(map, value);
}
hlist_nulls_del_rcu(&l->hash_node);
if (!is_lru_map)
free_htab_elem(htab, l);

out_unlock:
htab_unlock_bucket(htab, b, hash, bflags);

if (is_lru_map && l)
htab_lru_push_free(htab, l);
if (l) {
if (is_lru_map)
htab_lru_push_free(htab, l);
else
free_htab_elem(htab, l);
}

return ret;
}
Expand Down

0 comments on commit 6711fab

Please sign in to comment.