batman-adv: Avoid race in TT TVLV allocator helper
authorSven Eckelmann <sven@narfation.org>
Wed, 9 May 2018 19:07:40 +0000 (21:07 +0200)
committerSimon Wunderlich <sw@simonwunderlich.de>
Thu, 10 May 2018 14:08:54 +0000 (16:08 +0200)
commit8ba0f9bd3bdea1058c2b2676bec7905724418e40
tree3666991dea22d6dc49d10eec987d9668fcf9f0ae
parent65cc02a8e1d4449daedf3a84e9dfdda2e44a5d97
batman-adv: Avoid race in TT TVLV allocator helper

The functions batadv_tt_prepare_tvlv_local_data and
batadv_tt_prepare_tvlv_global_data are responsible for preparing a buffer
which can be used to store the TVLV container for TT and add the VLAN
information to it.

This will be done in three phases:

1. count the number of VLANs and their entries
2. allocate the buffer using the counters from the previous step and limits
   from the caller (parameter tt_len)
3. insert the VLAN information to the buffer

The step 1 and 3 operate on a list which contains the VLANs. The access to
these lists must be protected with an appropriate lock or otherwise they
might operate on on different entries. This could for example happen when
another context is adding VLAN entries to this list.

This could lead to a buffer overflow in these functions when enough entries
were added between step 1 and 3 to the VLAN lists that the buffer room for
the entries (*tt_change) is smaller then the now required extra buffer for
new VLAN entries.

Fixes: 7ea7b4a14275 ("batman-adv: make the TT CRC logic VLAN specific")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Acked-by: Antonio Quartulli <a@unstable.cc>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
net/batman-adv/translation-table.c