Skip to contentSkip to conversation

BPF_F_NO_PREALLOC safety

QUESTION Andrew Fenton 1 participant 1 message Jul 1 BPF

lore
Share & tools
lore
#0 lore raw

On review of BPF_F_NO_PREALLOC, it has a history of causing crashes and bugs through deadlock and memory allocator corruption.

The git history shows that initially it was possible to shoot oneself in the foot with this flag, but then check_map_prog_compatibility() was updated to restrict using it in unsafe ways. Since bpf_mem_alloc was introduced, it appears these restrictions have been dropped.

Can I conclude that this flag is now safe to use in all contexts and that, aside from the obvious resource (memory, performance) costs, a preallocated and dynamically-allocated hash map are equivalent in terms of behavior and safety? If not, can I rely on the kernel to prevent me from using this flag in an unsafe way?

Thanks.