All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrei Borzenkov <arvidjaar@gmail.com>
To: The development of GNU GRUB <grub-devel@gnu.org>
Cc: Matthew Garrett <mjg59@coreos.com>
Subject: Re: [PATCH 3/4] Don't allocate a new address buffer if we receive multiple DNS responses
Date: Tue, 24 Jan 2017 06:55:30 +0300	[thread overview]
Message-ID: <71fb5b8f-0e1c-f6ca-0a85-200f60695268@gmail.com> (raw)
In-Reply-To: <20170124003601.24612-4-mjg59@coreos.com>

24.01.2017 03:36, Matthew Garrett пишет:
> The current logic in the DNS resolution code allocates an address buffer
> based on the number of addresses in the response packet. If we receive
> multiple response packets in response to a single query packet, this means
> that we will reallocate a new buffer large enough for only the addresses in
> that specific packet, discarding any previous results in the process. Worse,
> we still keep track of the *total* number of addresses resolved in response
> to this query, not merely the number in the packet being currently processed.
> Use realloc() rather than malloc() to avoid overwriting the existing data,
> and allocate a buffer large enough for the total set of addresses rather
> than merely the number in this specific response.
> ---
>  grub-core/net/dns.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/grub-core/net/dns.c b/grub-core/net/dns.c
> index 5d9afe0..5deb1ef 100644
> --- a/grub-core/net/dns.c
> +++ b/grub-core/net/dns.c
> @@ -285,8 +285,8 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
>        ptr++;
>        ptr += 4;
>      }
> -  *data->addresses = grub_malloc (sizeof ((*data->addresses)[0])
> -				 * grub_be_to_cpu16 (head->ancount));
> +  *data->addresses = grub_realloc (*data->addresses, sizeof ((*data->addresses)[0])
> +		     * (grub_be_to_cpu16 (head->ancount) + *data->naddresses));

If *data->addresses was not NULL, we should not reach this code.

  /* Code apparently assumed that only one packet is received as response.
     We may get multiple responses due to network condition, so check here
     and quit early. */
  if (*data->addresses)
    {
      grub_netbuff_free (nb);
      return GRUB_ERR_NONE;
    }

This was noted previously by Josef, we discussed it and my position is
that resolver code requires redesign to correctly merge multiple answers
and prioritize A vs AAAA requests.

Do you get actual errors with current master? If yes, could you provide
more information what this patch fixes?

>    if (!*data->addresses)
>      {
>        grub_errno = GRUB_ERR_NONE;
> 



  reply	other threads:[~2017-01-24  3:55 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-24  0:35 Misc network boot patches Matthew Garrett
2017-01-24  0:35 ` [PATCH 1/4] Allow non-default ports for HTTP requests Matthew Garrett
2017-01-29  6:50   ` Andrei Borzenkov
2017-01-24  0:35 ` [PATCH 2/4] Send a user class identifier in bootp requests and tag it as DHCP discover Matthew Garrett
2017-01-24  6:09   ` Michael Marineau
2017-01-24  0:36 ` [PATCH 3/4] Don't allocate a new address buffer if we receive multiple DNS responses Matthew Garrett
2017-01-24  3:55   ` Andrei Borzenkov [this message]
2017-01-24 20:52     ` Matthew Garrett
2017-01-24  0:36 ` [PATCH 4/4] Allow protocol to be separated from host with a semicolon Matthew Garrett
2017-01-24  4:02   ` Andrei Borzenkov
2017-01-24 20:50     ` Matthew Garrett
2017-01-25  3:48       ` Andrei Borzenkov
2017-01-25  4:06         ` Matthew Garrett
2017-01-25  4:15           ` Andrei Borzenkov
2017-01-25  4:25             ` Matthew Garrett
2017-01-25  6:56               ` Andrei Borzenkov
2017-01-25  7:16                 ` Matthew Garrett
2017-01-25  7:37                   ` Andrei Borzenkov
2017-01-25  9:00                     ` Matthew Garrett
2017-01-25  6:18       ` Michael Chang
2017-01-25  6:21         ` Matthew Garrett
2017-01-25  8:35           ` Michael Chang
2017-01-25  9:02             ` Matthew Garrett
2017-01-25 17:30       ` Andrei Borzenkov
2017-01-25 23:33         ` Matthew Garrett
  -- strict thread matches above, loose matches on Subject: below --
2017-01-23 23:45 [PATCH 1/4] Allow non-default ports for HTTP requests Matthew Garrett
2017-01-23 23:45 ` [PATCH 3/4] Don't allocate a new address buffer if we receive multiple DNS responses Matthew Garrett

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=71fb5b8f-0e1c-f6ca-0a85-200f60695268@gmail.com \
    --to=arvidjaar@gmail.com \
    --cc=grub-devel@gnu.org \
    --cc=mjg59@coreos.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.