Skip to content

Commit d4dd153

Browse files
tmakitaborkmann
authored andcommitted
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 a5e2da6 ("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: a5e2da6 ("bpf: netdev is never null in __dev_map_flush") Signed-off-by: Toshiaki Makita <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 09f6ac2 commit d4dd153

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

kernel/bpf/devmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,10 @@ void __dev_map_flush(struct bpf_map *map)
291291
if (unlikely(!dev))
292292
continue;
293293

294-
__clear_bit(bit, bitmap);
295-
296294
bq = this_cpu_ptr(dev->bulkq);
297295
bq_xmit_all(dev, bq, XDP_XMIT_FLUSH, true);
296+
297+
__clear_bit(bit, bitmap);
298298
}
299299
}
300300

0 commit comments

Comments
 (0)