]> git.baikalelectronics.ru Git - kernel.git/commit
bpf, devmap: Fix premature entry free on destroying map
authorToshiaki Makita <toshiaki.makita1@gmail.com>
Fri, 14 Jun 2019 08:20:13 +0000 (17:20 +0900)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 14 Jun 2019 22:58:42 +0000 (00:58 +0200)
commit3bcb60409a189a938b2a0c9d06198acf83ab1c45
treed22755648032058eb1fd16f29eb58d32ce5ad683
parente05301e4867a6d18e35e7b1ac601d60021a81b37
bpf, devmap: Fix premature entry free on destroying map

dev_map_free() waits for flush_needed bitmap to be empty in order to
ensure all flush operations have completed before freeing its entries.
However the corresponding clear_bit() was called before using the
entries, so the entries could be used after free.

All access to the entries needs to be done before clearing the bit.
It seems commit 369460032528 ("bpf: netdev is never null in
__dev_map_flush") accidentally changed the clear_bit() and memory access
order.

Note that the problem happens only in __dev_map_flush(), not in
dev_map_flush_old(). dev_map_flush_old() is called only after nulling
out the corresponding netdev_map entry, so dev_map_free() never frees
the entry thus no such race happens there.

Fixes: 369460032528 ("bpf: netdev is never null in __dev_map_flush")
Signed-off-by: Toshiaki Makita <toshiaki.makita1@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
kernel/bpf/devmap.c