]> git.proxmox.com Git - grub2.git/commit
net/dns: Fix double-free addresses on corrupt DNS response
authorDaniel Axtens <dja@axtens.net>
Wed, 15 Sep 2021 15:29:54 +0000 (01:29 +1000)
committerJulian Andres Klode <julian.klode@canonical.com>
Wed, 8 Jun 2022 10:41:03 +0000 (12:41 +0200)
commit21158c5dfb5e0c5015277346128903397d498da4
tree28bd82b97e2bde7a31ac4a4c46e5bc82fcab8f79
parent2a4f87df650fd2ef639b48b43fc834b97b6b2bfa
net/dns: Fix double-free addresses on corrupt DNS response

grub_net_dns_lookup() takes as inputs a pointer to an array of addresses
("addresses") for the given name, and pointer to a number of addresses
("naddresses"). grub_net_dns_lookup() is responsible for allocating
"addresses", and the caller is responsible for freeing it if
"naddresses" > 0.

The DNS recv_hook will sometimes set and free the addresses array,
for example if the packet is too short:

      if (ptr + 10 >= nb->tail)
{
  if (!*data->naddresses)
    grub_free (*data->addresses);
  grub_netbuff_free (nb);
  return GRUB_ERR_NONE;
}

Later on the nslookup command code unconditionally frees the "addresses"
array. Normally this is fine: the array is either populated with valid
data or is NULL. But in these sorts of error cases it is neither NULL
nor valid and we get a double-free.

Only free "addresses" if "naddresses" > 0.

It looks like the other use of grub_net_dns_lookup() is not affected.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/net/dns.c