batman-adv: Prevent duplicated gateway_node entry
authorSven Eckelmann <sven@narfation.org>
Mon, 16 Mar 2020 22:31:01 +0000 (23:31 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 20 Mar 2020 08:07:55 +0000 (09:07 +0100)
commit3c3e542a40ada81a8b1b06fdae1c9a991e99ef6b
treec4aed441fc96ed8e4f170d16ecc041ac98d89830
parentb081203732b8a12ea7700eeeb8e03e206088bb99
batman-adv: Prevent duplicated gateway_node entry

commit dff9bc42ab0b2d38c5e90ddd79b238fed5b4c7ad upstream.

The function batadv_gw_node_add is responsible for adding new gw_node to
the gateway_list. It is expecting that the caller already checked that
there is not already an entry with the same key or not.

But the lock for the list is only held when the list is really modified.
This could lead to duplicated entries because another context could create
an entry with the same key between the check and the list manipulation.

The check and the manipulation of the list must therefore be in the same
locked code section.

Fixes: c6c8fea29769 ("net: Add batman-adv meshing protocol")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Acked-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/batman-adv/gateway_client.c