Skip to contentSkip to conversation

bonding: fix send_peer_notif data truncation

PATCH In review liaichun 2 participants 2 messages Jan 27, 2021 – Jan 28, 2021

Subsystems (3)
lore
Share & tools
lore

liaichun

author
#0 lore raw

PATCH v2 1/1 bonding: fix send_peer_notif data truncation

send_peer_notif is u8, the value of this parameter is obtained from
u8*int, it's easy to be truncated. And in practice, more than u8(256)
characters are used.

Fixes 07a4ddec3ce9 ("bonding: add an option to specify a delay between peer notifications")
---
 include/net/bonding.h | 2 +-
 drivers/net/bonding/bond_main.c | 4 ++--
 2 file changed, 3 insertion(+), 3 deletion(-)
include/net/bonding.h +1 -1
@@ -215,7 +215,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;
drivers/net/bonding/bond_main.c +2 -2
@@ -880,8 +880,8 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
 
 			if (netif_running(bond->dev)) {
 				bond->send_peer_notif =
-					bond->params.num_peer_notif *
-					max(1, bond->params.peer_notif_delay);
+					(u32)(bond->params.num_peer_notif *
+					max(1, bond->params.peer_notif_delay));
 				should_notify_peers =
 					bond_should_notify_peers(bond);
 			}

--
2.19.1

maintainer
#1 lore raw

Please make sure you CC the author of the original code.

Quoted 3 lines · On Wed, 27 Jan 2021 03:57:22 +0000 liaichun wrote:

send_peer_notif is u8, the value of this parameter is obtained from
u8*int, it's easy to be truncated. And in practice, more than u8(256)
characters are used.

Did you find this through code inspection of is it really a problem? What's your miimon setting?

Quoted 23 lines
Fixes 07a4ddec3ce9 ("bonding: add an option to specify a delay between peer notifications")
---
 include/net/bonding.h | 2 +-
 drivers/net/bonding/bond_main.c | 4 ++--
 2 file changed, 3 insertion(+), 3 deletion(-)
include/net/bonding.h +1 -1
@@ -215,7 +215,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;

drivers/net/bonding/bond_main.c void bond_change_active_slave(struct bonding *bond, struct slave *new_active) · line 883

Quoted 6 lines
drivers/net/bonding/bond_main.c +1 -2
@@ -880,8 +880,8 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
 
 			if (netif_running(bond->dev)) {
 				bond->send_peer_notif =
-					bond->params.num_peer_notif *
-					max(1, bond->params.peer_notif_delay);
+					(u32)(bond->params.num_peer_notif *

Why do you add the cast?

Quoted 7 lines
drivers/net/bonding/bond_main.c +1 -1
+					max(1, bond->params.peer_notif_delay));
 				should_notify_peers =
 					bond_should_notify_peers(bond);
 			}
--

2.19.1