b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | From: Sven Eckelmann <sven@narfation.org> |
| 2 | Date: Wed, 2 Mar 2022 19:49:44 +0100 |
| 3 | Subject: batman-adv: Request iflink once in batadv-on-batadv check |
| 4 | |
| 5 | There is no need to call dev_get_iflink multiple times for the same |
| 6 | net_device in batadv_is_on_batman_iface. And since some of the |
| 7 | .ndo_get_iflink callbacks are dynamic (for example via RCUs like in |
| 8 | vxcan_get_iflink), it could easily happen that the returned values are not |
| 9 | stable. The pre-checks before __dev_get_by_index are then of course bogus. |
| 10 | |
| 11 | Fixes: 3d48811b27f5 ("batman-adv: prevent using any virtual device created on batman-adv as hard-interface") |
| 12 | Signed-off-by: Sven Eckelmann <sven@narfation.org> |
| 13 | Origin: upstream, https://git.open-mesh.org/batman-adv.git/commit/f6c0c45356fe3ab9c5e01b81d060f8a436658037 |
| 14 | |
| 15 | --- a/net/batman-adv/hard-interface.c |
| 16 | +++ b/net/batman-adv/hard-interface.c |
| 17 | @@ -149,22 +149,23 @@ static bool batadv_is_on_batman_iface(co |
| 18 | struct net *net = dev_net(net_dev); |
| 19 | struct net_device *parent_dev; |
| 20 | struct net *parent_net; |
| 21 | + int iflink; |
| 22 | bool ret; |
| 23 | |
| 24 | /* check if this is a batman-adv mesh interface */ |
| 25 | if (batadv_softif_is_valid(net_dev)) |
| 26 | return true; |
| 27 | |
| 28 | + iflink = dev_get_iflink(net_dev); |
| 29 | + |
| 30 | /* no more parents..stop recursion */ |
| 31 | - if (dev_get_iflink(net_dev) == 0 || |
| 32 | - dev_get_iflink(net_dev) == net_dev->ifindex) |
| 33 | + if (iflink == 0 || iflink == net_dev->ifindex) |
| 34 | return false; |
| 35 | |
| 36 | parent_net = batadv_getlink_net(net_dev, net); |
| 37 | |
| 38 | /* recurse over the parent device */ |
| 39 | - parent_dev = __dev_get_by_index((struct net *)parent_net, |
| 40 | - dev_get_iflink(net_dev)); |
| 41 | + parent_dev = __dev_get_by_index((struct net *)parent_net, iflink); |
| 42 | /* if we got a NULL parent_dev there is something broken.. */ |
| 43 | if (!parent_dev) { |
| 44 | pr_err("Cannot find parent device\n"); |