grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
From: Andrei Borzenkov <arvidjaar@gmail.com>
To: The development of GNU GRUB <grub-devel@gnu.org>, kernel-team@fb.com
Cc: Josef Bacik <jbacik@fb.com>
Subject: Re: [PATCH 11/14] dns: reset data->naddresses for every packet we receive
Date: Sat, 13 Feb 2016 19:05:04 +0300	[thread overview]
Message-ID: <56BF5430.5000508@gmail.com> (raw)
In-Reply-To: <1455139268-3241273-12-git-send-email-jbacik@fb.com>

11.02.2016 00:21, Josef Bacik пишет:
> I noticed when debugging a problem that we'd corrupt memory if our dns server
> didn't respond fast enough and we ended up asking for both an AAAA and A record
> for a server.  The problem is we alloc data->addresses based on the number of
> addresses in the packet, but we populate it based on data->naddresses.  So we
> get the AAAA record with one address, and we add that, then we get the A record
> with one address and now data->naddresses == 1 but the ancount is 1, so we
> allocate data->addresses to hold one address but write the new address outside
> the array.  We also leak the old addresses memory.  So fix this by noticing if
> we already have an address and free the old memory and reset naddresses so we
> don't overflow our new array.
> 
> Signed-off-by: Josef Bacik <jbacik@fb.com>
> ---
>  grub-core/net/dns.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/grub-core/net/dns.c b/grub-core/net/dns.c
> index 86e609b..7a6c4b4 100644
> --- a/grub-core/net/dns.c
> +++ b/grub-core/net/dns.c
> @@ -276,6 +276,9 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
>        ptr++;
>        ptr += 4;
>      }
> +  if (*data->naddresses)
> +    grub_free (*data->addresses);
> +  *data->naddresses = 0;
>    *data->addresses = grub_malloc (sizeof ((*data->addresses)[0])
>  				 * grub_be_to_cpu16 (head->ancount));

Hmm ... cannot we resize it?

*data->addresses = grub_realloc (*data->addresses,
sizeof ((*data->addresses)[0]) * (*data->naddresses += grub_be_to_cpu16
(head->ancount)))

as adjusted to not leak old pointer.

This way answers we got before would not be lost.

>    if (!*data->addresses)
> 



  reply	other threads:[~2016-02-13 16:05 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-10 21:20 [PATCH 00/14] Facebook's netbooting patches Josef Bacik
2016-02-10 21:20 ` [PATCH 01/14] Added net_bootp6 command Josef Bacik
2016-02-10 21:20 ` [PATCH 02/14] UEFI IPv6 PXE support Josef Bacik
2016-02-10 21:20 ` [PATCH 03/14] Use UEFI MAC device as default configured by net_bootp6 Josef Bacik
2016-02-10 21:20 ` [PATCH 04/14] tcp: add window scaling and RTTM support Josef Bacik
2016-02-10 21:20 ` [PATCH 05/14] net: don't free uninitialized sockets in dns Josef Bacik
2016-02-13 17:59   ` Andrei Borzenkov
2016-02-16 16:13     ` Josef Bacik
2016-02-10 21:21 ` [PATCH 06/14] net: fix ipv6 routing Josef Bacik
2016-02-25 19:39   ` Andrei Borzenkov
2016-02-10 21:21 ` [PATCH 07/14] efinet: retransmit if our device is busy Josef Bacik
2016-02-10 21:21 ` [PATCH 08/14] efinet: filter multicast traffic based on addresses Josef Bacik
2016-02-10 21:21 ` [PATCH 09/14] efinet: clear the txbuffer before modifying the receive filters Josef Bacik
2016-02-10 21:21 ` [PATCH 10/14] dns: poll card between each dns request Josef Bacik
2016-02-15  6:45   ` Andrei Borzenkov
2016-02-16 16:16     ` Josef Bacik
2016-02-23 22:02     ` Josef Bacik
2016-02-24  3:25       ` Andrei Borzenkov
2016-02-10 21:21 ` [PATCH 11/14] dns: reset data->naddresses for every packet we receive Josef Bacik
2016-02-13 16:05   ` Andrei Borzenkov [this message]
2016-02-16 16:18     ` Josef Bacik
2016-02-10 21:21 ` [PATCH 12/14] icmp6: use default interface as the route interface Josef Bacik
2016-02-10 21:21 ` [PATCH 13/14] bootp: don't add multiple interfaces for the same address Josef Bacik
2016-02-10 21:21 ` [PATCH 14/14] net: add interfaces when we open a card Josef Bacik

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=56BF5430.5000508@gmail.com \
    --to=arvidjaar@gmail.com \
    --cc=grub-devel@gnu.org \
    --cc=jbacik@fb.com \
    --cc=kernel-team@fb.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).