In lan966x_remove(), lan966x_vcap_deinit() destroys ctrl->lock and frees
lan966x->vcap_ctrl before lan966x_cleanup_ports() unregisters the netdevs
and before debugfs_remove_recursive() tears down the vcap debugfs entries.
Unregistering a port with active TC flower rules, or concurrent TC, PTP,
or debugfs accesses, can dereference the freed vcap_ctrl pointer.
Move lan966x_vcap_deinit() after lan966x_cleanup_ports(),
lan966x_ptp_deinit(), and debugfs_remove_recursive(), and clear
lan966x->vcap_ctrl before freeing it.
Found by LLM-assisted static analysis. Compile-tested on x86_64.
Fixes: b053122532d7 ("net: lan966x: Add initial VCAP")
Cc: stab…@vger.kernel.org
Signed-off-by: Ziheng Wei <zihe…@163.com>
---
drivers/net/ethernet/microchip/lan966x/lan966x_main.c | 2 +-
drivers/net/ethernet/microchip/lan966x/lan966x_vcap_impl.c | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
index b8696fc7e..7b0c82cc9 100644
--- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
+++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
@@ -1329,7 +1329,6 @@ static void lan966x_remove(struct platform_device *pdev)
struct lan966x *lan966x = platform_get_drvdata(pdev);
lan966x_taprio_deinit(lan966x);
- lan966x_vcap_deinit(lan966x);
lan966x->ops->fdma_deinit(lan966x);
lan966x_cleanup_ports(lan966x);
@@ -1342,6 +1341,7 @@ static void lan966x_remove(struct platform_device *pdev)
lan966x_ptp_deinit(lan966x);
debugfs_remove_recursive(lan966x->debugfs_root);
+ lan966x_vcap_deinit(lan966x);
}
static void lan966x_shutdown(struct platform_device *pdev)
diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_vcap_impl.c b/drivers/net/ethernet/microchip/lan966x/lan966x_vcap_impl.c
index eb28df80b..feeb9fd33 100644
--- a/drivers/net/ethernet/microchip/lan966x/lan966x_vcap_impl.c
+++ b/drivers/net/ethernet/microchip/lan966x/lan966x_vcap_impl.c
@@ -780,6 +780,7 @@ void lan966x_vcap_deinit(struct lan966x *lan966x)
lan966x_vcap_admin_free(admin);
}
+ lan966x->vcap_ctrl = NULL;
mutex_destroy(&ctrl->lock);
kfree(ctrl);
}
base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
--
2.43.0