batman-adv: Fix unexpected free of bcast_own on add_if error
authorSven Eckelmann <sven@narfation.org>
Tue, 17 Mar 2020 23:26:51 +0000 (00:26 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 20 Mar 2020 08:06:25 +0000 (09:06 +0100)
commit7ba476d56bd87417a37cba28e19a5f72439ad974
tree6e78fdb1370572029d968075486cf3221ed48a8f
parenta60ac224ec7f4a422e78377ac45b9889f30fffa5
batman-adv: Fix unexpected free of bcast_own on add_if error

commit f7dcdf5fdbe8fec7670d8f65a5db595c98e0ecab upstream.

The function batadv_iv_ogm_orig_add_if allocates new buffers for bcast_own
and bcast_own_sum. It is expected that these buffers are unchanged in case
either bcast_own or bcast_own_sum couldn't be resized.

But the error handling of this function frees the already resized buffer
for bcast_own when the allocation of the new bcast_own_sum buffer failed.
This will lead to an invalid memory access when some code will try to
access bcast_own.

Instead the resized new bcast_own buffer has to be kept. This will not lead
to problems because the size of the buffer was only increased and therefore
no user of the buffer will try to access bytes outside of the new buffer.

Fixes: d0015fdd3d2c ("batman-adv: provide orig_node routing API")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Antonio Quartulli <a@unstable.cc>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/batman-adv/bat_iv_ogm.c