]> git.ipfire.org Git - thirdparty/iproute2.git/commit
bpf: Fix race condition with map pinning
authorJoe Stringer <joe@wand.net.nz>
Fri, 20 Sep 2019 02:04:47 +0000 (19:04 -0700)
committerStephen Hemminger <stephen@networkplumber.org>
Tue, 24 Sep 2019 19:29:38 +0000 (12:29 -0700)
commite4c4685fd6e4afd3e9b6818c96fded371f350a3f
treeaa03c8cfa41e24c3ad381e4730933a606990680e
parent80d0e626736e9bdff3075915b358ae7b531ac775
bpf: Fix race condition with map pinning

If two processes attempt to invoke bpf_map_attach() at the same time,
then they will both create maps, then the first will successfully pin
the map to the filesystem and the second will not pin the map, but will
continue operating with a reference to its own copy of the map. As a
result, the sharing of the same map will be broken from the two programs
that were concurrently loaded via loaders using this library.

Fix this by adding a retry in the case where the pinning fails because
the map already exists on the filesystem. In that case, re-attempt
opening a fd to the map on the filesystem as it shows that another
program already created and pinned a map at that location.

Signed-off-by: Joe Stringer <joe@wand.net.nz>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
lib/bpf.c