]> git.baikalelectronics.ru Git - kernel.git/commit
ipv6: fix locking issues with loops over idev->addr_list
authorNiels Dossche <dossche.niels@gmail.com>
Sun, 3 Apr 2022 23:15:24 +0000 (01:15 +0200)
committerJakub Kicinski <kuba@kernel.org>
Thu, 7 Apr 2022 05:09:39 +0000 (22:09 -0700)
commit7ab65e56bf20672b44a4463874661798666776f5
tree8cc0f333a50eed09b36ab035d77a3eab4069ea64
parent630c0017f30ea17e0f6171923b3b3ca6f628ed9d
ipv6: fix locking issues with loops over idev->addr_list

idev->addr_list needs to be protected by idev->lock. However, it is not
always possible to do so while iterating and performing actions on
inet6_ifaddr instances. For example, multiple functions (like
addrconf_{join,leave}_anycast) eventually call down to other functions
that acquire the idev->lock. The current code temporarily unlocked the
idev->lock during the loops, which can cause race conditions. Moving the
locks up is also not an appropriate solution as the ordering of lock
acquisition will be inconsistent with for example mc_lock.

This solution adds an additional field to inet6_ifaddr that is used
to temporarily add the instances to a temporary list while holding
idev->lock. The temporary list can then be traversed without holding
idev->lock. This change was done in two places. In addrconf_ifdown, the
list_for_each_entry_safe variant of the list loop is also no longer
necessary as there is no deletion within that specific loop.

Suggested-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Niels Dossche <dossche.niels@gmail.com>
Acked-by: Paolo Abeni <pabeni@redhat.com>
Link: https://lore.kernel.org/r/20220403231523.45843-1-dossche.niels@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/if_inet6.h
net/ipv6/addrconf.c