bonding: fix send_peer_notif overflow
Subsystems (6)
v2 cover bonding: fix send_peer_notif overflow
Bonding send_peer_notif was defined as u8. But the value is num_peer_notif multiplied by peer_notif_delay, which is u8 * u32. This would cause the send_peer_notif overflow.
Before the fix:
TEST: num_grat_arp (active-backup miimon num_grat_arp 10) [ OK ]
TEST: num_grat_arp (active-backup miimon num_grat_arp 20) [ OK ]
4 garp packets sent on active slave eth1
TEST: num_grat_arp (active-backup miimon num_grat_arp 30) [FAIL]
24 garp packets sent on active slave eth1
TEST: num_grat_arp (active-backup miimon num_grat_arp 50) [FAIL]
After the fix:
TEST: num_grat_arp (active-backup miimon num_grat_arp 10) [ OK ]
TEST: num_grat_arp (active-backup miimon num_grat_arp 20) [ OK ]
TEST: num_grat_arp (active-backup miimon num_grat_arp 30) [ OK ]
TEST: num_grat_arp (active-backup miimon num_grat_arp 50) [ OK ]
Hangbin Liu (4):
bonding: fix send_peer_notif overflow
Documentation: bonding: fix the doc of peer_notif_delay
selftests: forwarding: lib: add netns support for tc rule handle stats
get
kselftest: bonding: add num_grat_arp test
Documentation/networking/bonding.rst | 9 ++-- drivers/net/bonding/bond_netlink.c | 6 +++ drivers/net/bonding/bond_options.c | 8 ++- include/net/bonding.h | 2 +- .../drivers/net/bonding/bond_options.sh | 50 +++++++++++++++++++ .../drivers/net/bonding/bond_topo_3d1c.sh | 2 + tools/testing/selftests/net/forwarding/lib.sh | 3 +- 7 files changed, 73 insertions(+), 7 deletions(-)
Signature · 1 line
2.38.1
PATCH v2 1/4 bonding: fix send_peer_notif overflow
Bonding send_peer_notif was defined as u8. Since commit 07a4ddec3ce9 ("bonding: add an option to specify a delay between peer notifications"). the bond->send_peer_notif will be num_peer_notif multiplied by peer_notif_delay, which is u8 * u32. This would cause the send_peer_notif overflow easily. e.g.
ip link add bond0 type bond mode 1 miimon 100 num_grat_arp 30 peer_notify_delay 1000
To fix the overflow, let's set the send_peer_notif to u32 and limit peer_notif_delay to 300s.
---
v2: define send_peer_notif as u32 and limit the peer_notif_delay to 300s
--- drivers/net/bonding/bond_netlink.c | 6 ++++++ drivers/net/bonding/bond_options.c | 8 +++++++- include/net/bonding.h | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-)
drivers/net/bonding/bond_netlink.c +6 -0
@@ -244,6 +244,12 @@ static int bond_changelink(struct net_device *bond_dev, struct nlattr *tb[],if (data[IFLA_BOND_PEER_NOTIF_DELAY ]) {int delay =nla_get_u32 (data[IFLA_BOND_PEER_NOTIF_DELAY ]); +if (delay >300000 ) { +NL_SET_ERR_MSG_ATTR (extack, data[IFLA_BOND_PEER_NOTIF_DELAY ], +"peer_notif_delay should be less than 300s" ); +return -EINVAL ; + } +bond_opt_initval (&newval, delay); err =__bond_opt_set (bond,BOND_OPT_PEER_NOTIF_DELAY , &newval, data[IFLA_BOND_PEER_NOTIF_DELAY ], extack);
drivers/net/bonding/bond_options.c +7 -1
@@ -169,6 +169,12 @@ static const struct bond_opt_value bond_num_peer_notif_tbl[] = { { NULL, -1, 0} }; +static const struct bond_opt_value bond_peer_notif_delay_tbl[] = { + {"off" ,0 ,0 }, + {"maxval" ,300000 ,BOND_VALFLAG_MAX }, + {NULL ,-1 ,0 } +}; +static const struct bond_opt_value bond_primary_reselect_tbl[] = { {"always" ,BOND_PRI_RESELECT_ALWAYS ,BOND_VALFLAG_DEFAULT }, {"better" ,BOND_PRI_RESELECT_BETTER ,0 },
@@ -488,7 +494,7 @@ static const struct bond_option bond_opts[BOND_OPT_LAST] = { .id = BOND_OPT_PEER_NOTIF_DELAY, .name = "peer_notif_delay", .desc = "Delay between each peer notification on failover event, in milliseconds", - .values = bond_intmax_tbl, + .values = bond_peer_notif_delay_tbl, .set = bond_option_peer_notif_delay_set } };
include/net/bonding.h +1 -1
@@ -233,7 +233,7 @@ struct bonding {*/ spinlock_t mode_lock;spinlock_t stats_lock; -u8 send_peer_notif; +u32 send_peer_notif;u8 igmp_retrans;#ifdef CONFIG_PROC_FS struct proc_dir_entry *proc_entry;
Signature · 1 line
2.38.1
On Thu, Apr 27, 2023 at 11:39:06AM +0800, Hangbin Liu wrote:
...
drivers/net/bonding/bond_netlink.c static int bond_changelink(struct net_device *bond_dev, struct nlattr *tb[], · line 251
Quoted 13 lines
drivers/net/bonding/bond_netlink.c +5
-0@@ -244,6 +244,12 @@ static int bond_changelink(struct net_device *bond_dev, struct nlattr *tb[],if (data[IFLA_BOND_PEER_NOTIF_DELAY ]) {int delay =nla_get_u32 (data[IFLA_BOND_PEER_NOTIF_DELAY ]); +if (delay >300000 ) { +NL_SET_ERR_MSG_ATTR (extack, data[IFLA_BOND_PEER_NOTIF_DELAY ], +"peer_notif_delay should be less than 300s" ); +return -EINVAL ; + }
Hi Hangbin,
can this limit be implemented using NLA_POLICY_MAX() in bond_policy ?
Quoted 4 lines
drivers/net/bonding/bond_netlink.c +1
-0+bond_opt_initval (&newval, delay); err =__bond_opt_set (bond,BOND_OPT_PEER_NOTIF_DELAY , &newval, data[IFLA_BOND_PEER_NOTIF_DELAY ], extack);
...
Quoted 20 lines · Simon Horman
On Thu, Apr 27, 2023 at 11:39:06AM +0800, Hangbin Liu wrote:
...
drivers/net/bonding/bond_netlink.c static int bond_changelink(struct net_device *bond_dev, struct nlattr *tb[], · line 251
Quoted 13 lines
drivers/net/bonding/bond_netlink.c +5
-0@@ -244,6 +244,12 @@ static int bond_changelink(struct net_device *bond_dev, struct nlattr *tb[],if (data[IFLA_BOND_PEER_NOTIF_DELAY ]) {int delay =nla_get_u32 (data[IFLA_BOND_PEER_NOTIF_DELAY ]); +if (delay >300000 ) { +NL_SET_ERR_MSG_ATTR (extack, data[IFLA_BOND_PEER_NOTIF_DELAY ], +"peer_notif_delay should be less than 300s" ); +return -EINVAL ; + }Hi Hangbin,
Quoted 1 line
can this limit be implemented using
NLA_POLICY_MAX()inbond_policy?
Thanks for the comment, I will update the patch after backing from holiday next week.
Hangbin
PATCH v2 2/4 Documentation: bonding: fix the doc of peer_notif_delay
In reply to Hangbin LiuBonding only supports setting peer_notif_delay with miimon set.
--- Documentation/networking/bonding.rst | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
Documentation/networking/bonding.rst +5 -4
@@ -776,10 +776,11 @@ peer_notif_delay Specify the delay, in milliseconds, between each peer notification (gratuitous ARP and unsolicited IPv6 Neighbor Advertisement) when they are issued after a failover event. - This delay should be a multiple of the link monitor interval - (arp_interval or miimon, whichever is active). The default - value is 0 which means to match the value of the link monitor - interval. + This delay should be a multiple of the MII link monitor interval + (miimon). + + The valid range is 0 - 300000. The default value is 0, which means + to match the value of the MII link monitor interval. prio Slave priority. A higher number means higher priority.
Signature · 1 line
2.38.1
PATCH v2 3/4 selftests: forwarding: lib: add netns support for tc rule handle stats get
In reply to Hangbin Liu--- tools/testing/selftests/net/forwarding/lib.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/net/forwarding/lib.sh +2 -1
@@ -773,8 +773,9 @@ tc_rule_handle_stats_get() local id=$1; shift local handle=$1; shift local selector=${1:-.packets}; shift + local netns=${1:-""}; shift - tc -j -s filter show $id \ + tc $netns -j -s filter show $id \ | jq ".[] | select(.options.handle == $handle) | \ .options.actions[0].stats$selector" }
Signature · 1 line
2.38.1
Re: [PATCHv2 net 3/4] selftests: forwarding: lib: add netns support for tc rule handle stats get
On Thu, Apr 27, 2023 at 11:39:08AM +0800, Hangbin Liu wrote:
Hi Hangbin,
a commit description should go here.
F.e. explaining why this change is being made.
Quoted 23 lines
Signed-off-by Hangbin Liu <[email protected]>--- tools/testing/selftests/net/forwarding/lib.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tools/testing/selftests/net/forwarding/lib.sh +2
-1@@ -773,8 +773,9 @@ tc_rule_handle_stats_get() local id=$1; shift local handle=$1; shift local selector=${1:-.packets}; shift + local netns=${1:-""}; shift - tc -j -s filter show $id \ + tc $netns -j -s filter show $id \ | jq ".[] | select(.options.handle == $handle) | \ .options.actions[0].stats$selector" }Signature · 1 line
2.38.1
PATCH v2 4/4 kselftest: bonding: add num_grat_arp test
In reply to Hangbin LiuTEST: num_grat_arp (active-backup miimon num_grat_arp 10) [ OK ]
TEST: num_grat_arp (active-backup miimon num_grat_arp 20) [ OK ]
TEST: num_grat_arp (active-backup miimon num_grat_arp 30) [ OK ]
TEST: num_grat_arp (active-backup miimon num_grat_arp 50) [ OK ]
--- .../drivers/net/bonding/bond_options.sh | 50 +++++++++++++++++++ .../drivers/net/bonding/bond_topo_3d1c.sh | 2 + 2 files changed, 52 insertions(+)
tools/testing/selftests/drivers/net/bonding/bond_options.sh +50 -0
@@ -6,6 +6,7 @@ ALL_TESTS=" prio arp_validate + num_grat_arp " REQUIRE_MZ=no
@@ -255,6 +256,55 @@ arp_validate() arp_validate_ns "active-backup" } +garp_test() +{ + local param="$1" + local active_slave exp_num real_num i + RET=0 + + # create bond + bond_reset "${param}" + + bond_check_connection + [ $RET -ne 0 ] && log_test "num_grat_arp" "$retmsg" + + + # Add tc rules to count GARP number + for i in $(seq 0 2); do + tc -n ${g_ns} filter add dev s$i ingress protocol arp pref 1 handle 101 \ + flower skip_hw arp_op request arp_sip ${s_ip4} arp_tip ${s_ip4} action pass + done + + # Do failover + active_slave=$(cmd_jq "ip -n ${s_ns} -d -j link show bond0" ".[].linkinfo.info_data.active_slave") + ip -n ${s_ns} link set ${active_slave} down + + exp_num=$(echo "${param}" | cut -f6 -d ' ') + sleep $((exp_num + 2)) + + active_slave=$(cmd_jq "ip -n ${s_ns} -d -j link show bond0" ".[].linkinfo.info_data.active_slave") + + # check result + real_num=$(tc_rule_handle_stats_get "dev s${active_slave#eth} ingress" 101 ".packets" "-n ${g_ns}") + if [ "${real_num}" -ne "${exp_num}" ]; then + echo "$real_num garp packets sent on active slave ${active_slave}" + RET=1 + fi + + for i in $(seq 0 2); do + tc -n ${g_ns} filter del dev s$i ingress + done +} + +num_grat_arp() +{ + local val + for val in 10 20 30 50; do + garp_test "mode active-backup miimon 100 num_grat_arp $val peer_notify_delay 1000" + log_test "num_grat_arp" "active-backup miimon num_grat_arp $val" + done +} + trap cleanup EXIT setup_prepare
tools/testing/selftests/drivers/net/bonding/bond_topo_3d1c.sh +2 -0
@@ -61,6 +61,8 @@ server_create() ip -n ${g_ns} link set s${i} up ip -n ${g_ns} link set s${i} master br0 ip -n ${s_ns} link set eth${i} master bond0 + + tc -n ${g_ns} qdisc add dev s${i} clsact done ip -n ${s_ns} link set bond0 up
Signature · 1 line
2.38.1