Skip to contentSkip to conversation

net: phy: ncsi: fixed not nullify the pointers after free

PATCH In review Jacky Chou 2 participants 2 messages Dec 29, 2023 – Mar 28, 2024

Subsystems (2)
lore
Share & tools
lore

Jacky Chou

author
#0 lore raw

PATCH 1/1 net: phy: ncsi: fixed not nullify the pointers after free

The issue occurs the UAF (use-after-free) to cause double free when do the realloc function for the pointers during the reinitialization NC-SI process, and it will cause the memory management occurs error.
So, nullify these pointers after free.

---
 drivers/net/phy/ncsi.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/phy/ncsi.c +4 -1
index eb3fd65bb4..9689385884 100644
@@ -619,9 +619,12 @@ static void ncsi_handle_aen(struct ip_udp_hdr *ip, unsigned int len)
 
 	/* Link or configuration lost - just redo the discovery process */
 	ncsi_priv->state = NCSI_PROBE_PACKAGE_SP;
-	for (i = 0; i < ncsi_priv->n_packages; i++)
+	for (i = 0; i < ncsi_priv->n_packages; i++) {
 		free(ncsi_priv->packages[i].channels);
+		ncsi_priv->packages[i].channels = NULL;
+	}
 	free(ncsi_priv->packages);
+	ncsi_priv->packages = NULL;
 	ncsi_priv->n_packages = 0;
 
 	ncsi_priv->current_package = NCSI_PACKAGE_MAX;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 7 lines · Jacky Chou

The issue occurs the UAF (use-after-free) to cause double free when do the realloc function for the pointers during the reinitialization NC-SI process, and it will cause the memory management occurs error.
So, nullify these pointers after free.

Applied to u-boot/next, thanks!

Signature · 1 line
Tom