]> git.proxmox.com Git - mirror_iproute2.git/commit
ip/netns: use flock when setting up /run/netns
authorLuca Boccassi <bluca@debian.org>
Fri, 27 Nov 2020 18:06:51 +0000 (18:06 +0000)
committerStephen Hemminger <stephen@networkplumber.org>
Thu, 3 Dec 2020 16:31:23 +0000 (08:31 -0800)
commit975c4944e8d57b9f51960611e2bc2c0da6cd6864
treeb3a43f4b10578c627541ca1347f229c148245206
parentfb054cb3362158d25088cd4eb26fa713684d6428
ip/netns: use flock when setting up /run/netns

If multiple ip processes are ran at the same time to set up
separate network namespaces, and it is the first time so /run/netns
has to be set up first, and they end up doing it at the same time,
the processes might enter a recursive loop creating thousands of
mount points, which might crash the system depending on resources
available.

Try to take a flock on /run/netns before doing the mount() dance, to
ensure this cannot happen. But do not try too hard, and if it fails
continue after printing a warning, to avoid introducing regressions.

First reported on Debian: https://bugs.debian.org/949235

To reproduce (WARNING: run in a VM to avoid system lockups):

for i in {0..9}
do
        strace -e trace=mount -e inject=mount:delay_exit=1000000 ip \
 netns add "testnetns$i" 2>&1 | tee "$i.log" &
done
wait

The strace is to ensure the problem always reproduces, to add an
artificial synchronization point after the first mount().

Reported-by: Etienne Dechamps <etienne@edechamps.fr>
Signed-off-by: Luca Boccassi <bluca@debian.org>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
ip/ipnetns.c