Skip to contentSkip to conversation

net: spider_net: Use size_add() in call to struct_size()

PATCH In review Gustavo A. R. Silva 3 participants 3 messages Sep 15, 2023 – Sep 16, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: spider_net: Use size_add() in call to struct_size()

If, for any reason, the open-coded arithmetic causes a wraparound, the protection that struct_size() adds against potential integer overflows is defeated. Fix this by hardening call to struct_size() with size_add().

Fixes 3f1071ec39f7 ("net: spider_net: Use struct_size() helper")
---
 drivers/net/ethernet/toshiba/spider_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/toshiba/spider_net.c +1 -1
index 50d7eacfec58..87e67121477c 100644
@@ -2332,7 +2332,7 @@ spider_net_alloc_card(void)
 	struct spider_net_card *card;
 
 	netdev = alloc_etherdev(struct_size(card, darray,
-					    tx_descriptors + rx_descriptors));
+					    size_add(tx_descriptors, rx_descriptors)));
 	if (!netdev)
 		return NULL;
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Gustavo A. R. Silva

If, for any reason, the open-coded arithmetic causes a wraparound, the protection that struct_size() adds against potential integer overflows is defeated. Fix this by hardening call to struct_size() with size_add().

Fixes 3f1071ec39f7 ("net: spider_net: Use struct_size() helper")
Signature · 1 line
Kees Cook
#2 lore raw
In reply to Gustavo A. R. Silva
Quoted 16 lines · Gustavo A. R. Silva

If, for any reason, the open-coded arithmetic causes a wraparound, the protection that struct_size() adds against potential integer overflows is defeated. Fix this by hardening call to struct_size() with size_add().

Fixes 3f1071ec39f7 ("net: spider_net: Use struct_size() helper")
---
 drivers/net/ethernet/toshiba/spider_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/toshiba/spider_net.c +0 -0
index 50d7eacfec58..87e67121477c 100644

drivers/net/ethernet/toshiba/spider_net.c spider_net_alloc_card(void) · line 2338

Quoted 8 lines
drivers/net/ethernet/toshiba/spider_net.c +1 -1
@@ -2332,7 +2332,7 @@ spider_net_alloc_card(void)
 	struct spider_net_card *card;
 
 	netdev = alloc_etherdev(struct_size(card, darray,
-					    tx_descriptors + rx_descriptors));
+					    size_add(tx_descriptors, rx_descriptors)));
 	if (!netdev)
 		return NULL;
 

Looks good to me. Thanks for your fix-up.