linux-stable/net/batman-adv
Pavel Skripkin fbf150b16a net: batman-adv: fix error handling
commit 6f68cd6348 upstream.

Syzbot reported ODEBUG warning in batadv_nc_mesh_free(). The problem was
in wrong error handling in batadv_mesh_init().

Before this patch batadv_mesh_init() was calling batadv_mesh_free() in case
of any batadv_*_init() calls failure. This approach may work well, when
there is some kind of indicator, which can tell which parts of batadv are
initialized; but there isn't any.

All written above lead to cleaning up uninitialized fields. Even if we hide
ODEBUG warning by initializing bat_priv->nc.work, syzbot was able to hit
GPF in batadv_nc_purge_paths(), because hash pointer in still NULL. [1]

To fix these bugs we can unwind batadv_*_init() calls one by one.
It is good approach for 2 reasons: 1) It fixes bugs on error handling
path 2) It improves the performance, since we won't call unneeded
batadv_*_free() functions.

So, this patch makes all batadv_*_init() clean up all allocated memory
before returning with an error to no call correspoing batadv_*_free()
and open-codes batadv_mesh_free() with proper order to avoid touching
uninitialized fields.

Link: https://lore.kernel.org/netdev/000000000000c87fbd05cef6bcb0@google.com/ [1]
Reported-and-tested-by: syzbot+28b0702ada0bf7381f58@syzkaller.appspotmail.com
Fixes: c6c8fea297 ("net: Add batman-adv meshing protocol")
Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
Acked-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-11-02 18:26:45 +01:00
..
bat_algo.c batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
bat_algo.h batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
bat_iv_ogm.c batman-adv: Avoid WARN_ON timing related checks 2021-06-30 08:48:15 -04:00
bat_iv_ogm.h batman-adv: Unify include guards style 2018-07-07 22:02:17 +02:00
bat_v.c batman-adv: Fix bat_v best gw refcnt after netlink dump 2018-06-23 10:29:33 +02:00
bat_v.h batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
bat_v_elp.c batman-adv: Revert "disable ethtool link speed detection when auto negotiation off" 2020-06-22 09:05:12 +02:00
bat_v_elp.h batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
bat_v_ogm.c batman-adv: Fix own OGM check in aggregated OGMs 2020-09-09 19:04:24 +02:00
bat_v_ogm.h batman-adv: Unify include guards style 2018-07-07 22:02:17 +02:00
bitarray.c batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
bitarray.h batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
bridge_loop_avoidance.c net: batman-adv: fix error handling 2021-11-02 18:26:45 +01:00
bridge_loop_avoidance.h batman-adv: mcast: fix duplicate mcast packets in BLA backbone from mesh 2020-10-01 13:14:52 +02:00
debugfs.c Merge ra.kernel.org:/pub/scm/linux/kernel/git/torvalds/linux 2018-07-20 21:17:12 -07:00
debugfs.h batman-adv: Fix debugfs path for renamed softif 2018-06-23 10:29:33 +02:00
distributed-arp-table.c batman-adv: Fix DAT candidate selection on little endian systems 2020-01-23 08:21:34 +01:00
distributed-arp-table.h batman-adv: add DAT cache netlink support 2018-03-14 10:15:08 +01:00
fragmentation.c batman-adv: Expand merged fragment buffer for full packet 2018-12-13 09:16:10 +01:00
fragmentation.h batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
gateway_client.c batman-adv: Avoid uninitialized chaddr when handling DHCP 2020-09-09 19:04:24 +02:00
gateway_client.h batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
gateway_common.c batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
gateway_common.h batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
hard-interface.c batman-adv: Avoid free/alloc race when handling OGM buffer 2019-11-06 13:06:22 +01:00
hard-interface.h batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
hash.c batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
hash.h batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
icmp_socket.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2018-03-23 11:31:58 -04:00
icmp_socket.h batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
Kconfig batman-adv: Remove "default n" in Kconfig 2018-06-23 10:30:06 +02:00
log.c batman-adv: set .owner to THIS_MODULE 2020-12-02 08:48:10 +01:00
log.h batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
main.c net: batman-adv: fix error handling 2021-11-02 18:26:45 +01:00
main.h batman-adv: Increase version number to 2018.3 2018-09-14 17:59:20 +02:00
Makefile batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
multicast.c batman-adv: mcast: fix multicast tt/tvlv worker locking 2019-05-31 06:46:05 -07:00
multicast.h batman-adv: add multicast flags netlink support 2018-03-14 10:15:34 +01:00
netlink.c batman-adv: fix uninit-value in batadv_netlink_get_ifindex() 2019-09-16 08:21:41 +02:00
netlink.h batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
network-coding.c net: batman-adv: fix error handling 2021-11-02 18:26:45 +01:00
network-coding.h batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
originator.c batman-adv: Join batadv_purge_orig_ref and _batadv_purge_orig 2018-07-07 22:02:17 +02:00
originator.h Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2018-03-06 01:20:46 -05:00
routing.c batman-adv: mcast/TT: fix wrongly dropped or rerouted packets 2020-10-01 13:14:51 +02:00
routing.h batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
send.c batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
send.h batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
soft-interface.c batman-adv: mcast: fix duplicate mcast packets in BLA backbone from mesh 2020-10-01 13:14:52 +02:00
soft-interface.h batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
sysfs.c batman-adv: Fix refcnt leak in batadv_store_throughput_override 2020-05-14 07:57:22 +02:00
sysfs.h batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
tp_meter.c batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
tp_meter.h batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
translation-table.c net: batman-adv: fix error handling 2021-11-02 18:26:45 +01:00
translation-table.h batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
tvlv.c batman-adv: Prevent duplicated tvlv handler 2018-09-06 14:37:13 +02:00
tvlv.h batman-adv: Update copyright years for 2018 2018-02-26 17:57:39 +01:00
types.h batman-adv: Avoid free/alloc race when handling OGM2 buffer 2020-03-18 07:14:25 +01:00