Skip to contentSkip to conversation

Fixed UAF and double free in network

PATCH In review Lidong Chen via Grub-devel 1 participant 4 messages Oct 22, 2025

lore
Share & tools
lore
#0 lore raw

cover Fixed UAF and double free in network

Fixed UAF and double free issues found by fuzzing.

Lidong Chen (2):
net/bootp: Prevent a UAF in network interface unregister. net/dns: Prevent UAF and double free

 grub-core/net/bootp.c | 7 +++++--
 grub-core/net/dns.c   | 5 ++++-
 2 files changed, 9 insertions(+), 3 deletions(-)
Signature · 7 lines
2.43.0


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#1 lore raw

PATCH 1/2 net/bootp: Prevent a UAF in network interface unregister.

A UAF occurs in grub_net_network_level_interface_unregister() when inter->name is accessed after being freed in grub_cmd_bootp(). Fix it by deferring grub_free(ifaces[j].name) until after grub_net_network_level_interface_unregister() completes.

---
 grub-core/net/bootp.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
grub-core/net/bootp.c +5 -2
index 2f45a3cc2..fa3834f63 100644
@@ -901,14 +901,17 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)),
   err = GRUB_ERR_NONE;
   for (j = 0; j < ncards; j++)
     {
-      grub_free (ifaces[j].name);
       if (!ifaces[j].prev)
-	continue;
+	{
+	  grub_free (ifaces[j].name);
+	  continue;
+	}
       grub_error_push ();
       grub_net_network_level_interface_unregister (&ifaces[j]);
       err = grub_error (GRUB_ERR_FILE_NOT_FOUND,
 			N_("couldn't autoconfigure %s"),
 			ifaces[j].card->name);
+      grub_free (ifaces[j].name);
     }
 
   grub_free (ifaces);
Signature · 7 lines
2.43.0


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#2 lore raw

PATCH 2/2 net/dns: Prevent UAF and double free

In reply to Lidong Chen via Grub-devel

In recv_hook(), *data->addresses is freed without being set to NULL. Since *data->addresses can be cached in dns_cache[h].addresses, this can lead to UAF or double free if dns_cache[h].addresses is accessed or cleared later.

The fix sets *data->addresses to NULL after freeing to avoid dangling pointer.

---
 grub-core/net/dns.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
grub-core/net/dns.c +4 -1
index f20cd6f83..bef697d98 100644
@@ -424,7 +424,10 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
   grub_netbuff_free (nb);
   grub_free (redirect_save);
   if (!*data->naddresses)
-    grub_free (*data->addresses);
+    {
+      grub_free (*data->addresses);
+      *data->addresses = NULL;
+    }
   return GRUB_ERR_NONE;
 }
 
Signature · 7 lines
2.43.0


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#3 lore raw
In reply to Lidong Chen via Grub-devel
Quoted 5 lines · Lidong Chen

Fixed UAF and double free issues found by fuzzing.

Lidong Chen (2):
net/bootp: Prevent a UAF in network interface unregister. net/dns: Prevent UAF and double free

For all patches Reviewed-by: Daniel Kiper <[email protected]>...

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel