Skip to contentSkip to conversation

sfc: fix NULL dereferences in ef100_process_design_param()

PATCH Applied [email protected] 4 participants 5 messages Apr 1, 2025 – Apr 3, 2025

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

PATCH 1/1 sfc: fix NULL dereferences in ef100_process_design_param()

From: Edward Cree <[email protected]>

Since cited commit, ef100_probe_main() and hence also
ef100_check_design_params() run before efx->net_dev is created; consequently, we cannot netif_set_tso_max_size() or _segs() at this point.
Move those netif calls to ef100_probe_netdev(), and also replace
netif_err within the design params code with pci_err.

Fixes 98ff4c7c8ac7 ("sfc: Separate netdev probe/remove from PCI probe/remove")
---
 drivers/net/ethernet/sfc/ef100_netdev.c |  6 ++--
 drivers/net/ethernet/sfc/ef100_nic.c    | 47 +++++++++++--------------
 2 files changed, 24 insertions(+), 29 deletions(-)
drivers/net/ethernet/sfc/ef100_netdev.c +3 -3
index d941f073f1eb..3a06e3b1bd6b 100644
@@ -450,8 +450,9 @@ int ef100_probe_netdev(struct efx_probe_data *probe_data)
 	net_dev->hw_enc_features |= efx->type->offload_features;
 	net_dev->vlan_features |= NETIF_F_HW_CSUM | NETIF_F_SG |
 				  NETIF_F_HIGHDMA | NETIF_F_ALL_TSO;
-	netif_set_tso_max_segs(net_dev,
-			       ESE_EF100_DP_GZ_TSO_MAX_HDR_NUM_SEGS_DEFAULT);
+	nic_data = efx->nic_data;
+	netif_set_tso_max_size(efx->net_dev, nic_data->tso_max_payload_len);
+	netif_set_tso_max_segs(efx->net_dev, nic_data->tso_max_payload_num_segs);
 
 	rc = efx_ef100_init_datapath_caps(efx);
 	if (rc < 0)
@@ -477,7 +478,6 @@ int ef100_probe_netdev(struct efx_probe_data *probe_data)
 	/* Don't fail init if RSS setup doesn't work. */
 	efx_mcdi_push_default_indir_table(efx, efx->n_rx_channels);
 
-	nic_data = efx->nic_data;
 	rc = ef100_get_mac_address(efx, net_dev->perm_addr, CLIENT_HANDLE_SELF,
 				   efx->type->is_vf);
 	if (rc)
drivers/net/ethernet/sfc/ef100_nic.c +21 -26

93 lines not on this page · raw message

#1 lore raw
Quoted 22 lines · On Tue, Apr 01, 2025 at 11:54:39PM +0100, [email protected] wrote:

From: Edward Cree <[email protected]>

Since cited commit, ef100_probe_main() and hence also
ef100_check_design_params() run before efx->net_dev is created; consequently, we cannot netif_set_tso_max_size() or _segs() at this point.
Move those netif calls to ef100_probe_netdev(), and also replace
netif_err within the design params code with pci_err.

Fixes 98ff4c7c8ac7 ("sfc: Separate netdev probe/remove from PCI probe/remove")
---
 drivers/net/ethernet/sfc/ef100_netdev.c |  6 ++--
 drivers/net/ethernet/sfc/ef100_nic.c    | 47 +++++++++++--------------
 2 files changed, 24 insertions(+), 29 deletions(-)
drivers/net/ethernet/sfc/ef100_netdev.c +0 -0
index d941f073f1eb..3a06e3b1bd6b 100644

drivers/net/ethernet/sfc/ef100_netdev.c int ef100_probe_netdev(struct efx_probe_data *probe_data) · line 455

Quoted 8 lines
drivers/net/ethernet/sfc/ef100_netdev.c +3 -2
@@ -450,8 +450,9 @@ int ef100_probe_netdev(struct efx_probe_data *probe_data)
 	net_dev->hw_enc_features |= efx->type->offload_features;
 	net_dev->vlan_features |= NETIF_F_HW_CSUM | NETIF_F_SG |
 				  NETIF_F_HIGHDMA | NETIF_F_ALL_TSO;
-	netif_set_tso_max_segs(net_dev,
-			       ESE_EF100_DP_GZ_TSO_MAX_HDR_NUM_SEGS_DEFAULT);
+	nic_data = efx->nic_data;
+	netif_set_tso_max_size(efx->net_dev, nic_data->tso_max_payload_len);
+	netif_set_tso_max_segs(efx->net_dev, nic_data->tso_max_payload_num_segs);

Is it fine to drop default value for max segs? Previously if somehow this value wasn't read from HW it was set to default, now it will be 0.

At the beggining of ef100_probe_main() default values for nic_data are set. Maybe it is worth to set also this default for max segs?

Quoted 11 lines
drivers/net/ethernet/sfc/ef100_netdev.c +0 -1
 	rc = efx_ef100_init_datapath_caps(efx);
 	if (rc < 0)
@@ -477,7 +478,6 @@ int ef100_probe_netdev(struct efx_probe_data *probe_data)
 	/* Don't fail init if RSS setup doesn't work. */
 	efx_mcdi_push_default_indir_table(efx, efx->n_rx_channels);
 
-	nic_data = efx->nic_data;
 	rc = ef100_get_mac_address(efx, net_dev->perm_addr, CLIENT_HANDLE_SELF,
 				   efx->type->is_vf);
 	if (rc)

[...]

maintainer
#2 lore raw
Quoted 10 lines · Michal Swiatkowski

drivers/net/ethernet/sfc/ef100_netdev.c int ef100_probe_netdev(struct efx_probe_data *probe_data) · line 455

Quoted 5 lines · On Tue, Apr 01, 2025 at 11:54:39PM +0100, [email protected] wrote:
drivers/net/ethernet/sfc/ef100_netdev.c +3 -2
-	netif_set_tso_max_segs(net_dev,
-			       ESE_EF100_DP_GZ_TSO_MAX_HDR_NUM_SEGS_DEFAULT);
+	nic_data = efx->nic_data;
+	netif_set_tso_max_size(efx->net_dev, nic_data->tso_max_payload_len);
+	netif_set_tso_max_segs(efx->net_dev, nic_data->tso_max_payload_num_segs);

Is it fine to drop default value for max segs? Previously if somehow this value wasn't read from HW it was set to default, now it will be 0.

Quoted 2 lines

At the beggining of ef100_probe_main() default values for nic_data are set. Maybe it is worth to set also this default for max segs?

As I read it, ef100_probe_main() does set a default for this nic_data
field along with the others, and sets it to exactly this same value.

confused,
-ed

Reviewed-by
#3 lore raw
Quoted 11 lines · Edward Cree
Quoted 10 lines · Michal Swiatkowski

drivers/net/ethernet/sfc/ef100_netdev.c int ef100_probe_netdev(struct efx_probe_data *probe_data) · line 455

Quoted 5 lines · On Tue, Apr 01, 2025 at 11:54:39PM +0100, [email protected] wrote:
drivers/net/ethernet/sfc/ef100_netdev.c +3 -2
-	netif_set_tso_max_segs(net_dev,
-			       ESE_EF100_DP_GZ_TSO_MAX_HDR_NUM_SEGS_DEFAULT);
+	nic_data = efx->nic_data;
+	netif_set_tso_max_size(efx->net_dev, nic_data->tso_max_payload_len);
+	netif_set_tso_max_segs(efx->net_dev, nic_data->tso_max_payload_num_segs);

Is it fine to drop default value for max segs? Previously if somehow this value wasn't read from HW it was set to default, now it will be 0.

Quoted 6 lines
Quoted 2 lines

At the beggining of ef100_probe_main() default values for nic_data are set. Maybe it is worth to set also this default for max segs?

As I read it, ef100_probe_main() does set a default for this nic_data
field along with the others, and sets it to exactly this same value.

Sorry, right, I somehow missed it.

Quoted 2 lines

confused,
-ed

#4 lore raw
In reply to [email protected]
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Tue, 1 Apr 2025 23:54:39 +0100 you wrote:

From: Edward Cree <[email protected]>

Since cited commit, ef100_probe_main() and hence also
ef100_check_design_params() run before efx->net_dev is created; consequently, we cannot netif_set_tso_max_size() or _segs() at this point.
Move those netif calls to ef100_probe_netdev(), and also replace
netif_err within the design params code with pci_err.

[...]

Here is the summary with links:
- [net] sfc: fix NULL dereferences in ef100_process_design_param()

    https://git.kernel.org/netdev/net/c/8241ecec1cdc

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html