Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bonding: return -ENOMEM instead of BUG in alb_upper_dev_walk

If failed to allocate "tags" or could not find the final upper device from
start_dev's upper list in bond_verify_device_path(), only the loopback
detection of the current upper device should be affected, and the system is
no need to be panic.
So return -ENOMEM in alb_upper_dev_walk to stop walking, print some warn
information when failed to allocate memory for vlan tags in
bond_verify_device_path.

I also think that the following function calls
netdev_walk_all_upper_dev_rcu
---->>>alb_upper_dev_walk
---------->>>bond_verify_device_path
From this way, "end device" can eventually be obtained from "start device"
in bond_verify_device_path, IS_ERR(tags) could be instead of
IS_ERR_OR_NULL(tags) in alb_upper_dev_walk.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
Acked-by: Jay Vosburgh <jay.vosburgh@canonical.com>
Link: https://lore.kernel.org/r/20231118081653.1481260-1-shaozhengchao@huawei.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Zhengchao Shao and committed by
Paolo Abeni
d6b83f1e 0807dc76

+6 -2
+2 -1
drivers/net/bonding/bond_alb.c
··· 985 985 if (netif_is_macvlan(upper) && !strict_match) { 986 986 tags = bond_verify_device_path(bond->dev, upper, 0); 987 987 if (IS_ERR_OR_NULL(tags)) 988 - BUG(); 988 + return -ENOMEM; 989 + 989 990 alb_send_lp_vid(slave, upper->dev_addr, 990 991 tags[0].vlan_proto, tags[0].vlan_id); 991 992 kfree(tags);
+4 -1
drivers/net/bonding/bond_main.c
··· 2973 2973 2974 2974 if (start_dev == end_dev) { 2975 2975 tags = kcalloc(level + 1, sizeof(*tags), GFP_ATOMIC); 2976 - if (!tags) 2976 + if (!tags) { 2977 + net_err_ratelimited("%s: %s: Failed to allocate tags\n", 2978 + __func__, start_dev->name); 2977 2979 return ERR_PTR(-ENOMEM); 2980 + } 2978 2981 tags[level].vlan_proto = BOND_VLAN_PROTO_NONE; 2979 2982 return tags; 2980 2983 }