From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1ZSaPn-0006k5-TD for mharc-grub-devel@gnu.org; Thu, 20 Aug 2015 20:42:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40147) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZS6MH-0007Sm-08 for grub-devel@gnu.org; Wed, 19 Aug 2015 12:37:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZS6MB-0000fx-T7 for grub-devel@gnu.org; Wed, 19 Aug 2015 12:37:00 -0400 Received: from mail-la0-x236.google.com ([2a00:1450:4010:c03::236]:33282) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZS6MB-0000fR-L9 for grub-devel@gnu.org; Wed, 19 Aug 2015 12:36:55 -0400 Received: by lalv9 with SMTP id v9so6612437lal.0 for ; Wed, 19 Aug 2015 09:36:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type; bh=VZ9urFj0D70DyAyiRdvoWM6I5ehoS7nJ1fhvVv8VnOs=; b=qr3foE3XLKdY1CGDnklvPMLhVIgsFsLECHw14COUudzfxxVZy74DT95mbZP9lnPbvD /to/xbQHCoM/2TgN5PAYJ6jHoKl4VF/9uS8QoiqWm18q7ySBTzxfSHRtUQLChO1PT/Bu cLWNiwhCNigA3HuhkRHlED5LvoM/No2Ao7LETllUhVaznIIbYQpZK5i58mr4mayl+Cjb 7xTaqoL7poR1gyjT39s9XCyT7OD0PipdXcgYGrrA2FxVgMCB7DA6pA3UloZQ0wOhREco 5aEjpfXxz/woRZmnotmwqH34hfQ9rtJUdMh0GrvpkZGqZvg/mhjVrGlXjwczm4vBbXwZ bUZQ== X-Received: by 10.152.5.8 with SMTP id o8mr10891663lao.62.1440002214724; Wed, 19 Aug 2015 09:36:54 -0700 (PDT) Received: from [192.168.1.43] (ppp91-76-5-127.pppoe.mtu-net.ru. [91.76.5.127]) by smtp.gmail.com with ESMTPSA id w9sm356863laj.21.2015.08.19.09.36.53 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Aug 2015 09:36:53 -0700 (PDT) Message-ID: <55D4B0A5.9060101@gmail.com> Date: Wed, 19 Aug 2015 19:36:53 +0300 From: Andrei Borzenkov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 To: The development of GNU GRUB , kernel-team@fb.com Subject: Re: [PATCH] net: don't free uninitialized sockets in dns References: <1439921023-3547412-1-git-send-email-jbacik@fb.com> In-Reply-To: <1439921023-3547412-1-git-send-email-jbacik@fb.com> Content-Type: multipart/mixed; boundary="------------000108000804010402030403" X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::236 Cc: Josef Bacik X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Aug 2015 00:42:38 -0000 This is a multi-part message in MIME format. --------------000108000804010402030403 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 18.08.2015 21:03, Josef Bacik пишет: > If we cannot open a connection to our dns server we will have NULL sockets in > our array, so don't do the cleanup on any sockets that didn't get created. > We can avoid having holes to start with. Could you test attached patch? > Signed-off-by: Josef Bacik > --- > grub-core/net/dns.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/grub-core/net/dns.c b/grub-core/net/dns.c > index 9d0c8fc..c356318 100644 > --- a/grub-core/net/dns.c > +++ b/grub-core/net/dns.c > @@ -601,7 +601,10 @@ grub_net_dns_lookup (const char *name, > grub_free (data.name); > grub_netbuff_free (nb); > for (j = 0; j < send_servers; j++) > - grub_net_udp_close (sockets[j]); > + { > + if (sockets[j]) > + grub_net_udp_close (sockets[j]); > + } > > grub_free (sockets); > > --------------000108000804010402030403 Content-Type: text/x-patch; name="dns-null-free.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="dns-null-free.patch" From: Andrei Borzenkov Subject: [PATCH] net: avoid closing NULL socket in DNS lookup Refactor code so that we do not store NULL pointers in array of in-flight DNS servers. Reported-By: Josef Bacik --- grub-core/net/dns.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/grub-core/net/dns.c b/grub-core/net/dns.c index 9d0c8fc..953f3be 100644 --- a/grub-core/net/dns.c +++ b/grub-core/net/dns.c @@ -437,7 +437,7 @@ grub_net_dns_lookup (const char *name, struct recv_data data = {naddresses, addresses, cache, grub_cpu_to_be16 (id++), 0, 0, name, 0}; grub_uint8_t *nbd; - int have_server = 0; + grub_size_t try_server = 0; if (!servers) { @@ -543,33 +543,31 @@ grub_net_dns_lookup (const char *name, for (i = 0; i < n_servers * 4; i++) { /* Connect to a next server. */ - while (!(i & 1) && send_servers < n_servers) + while (!(i & 1) && try_server < n_servers) { - sockets[send_servers] = grub_net_udp_open (servers[send_servers], + sockets[send_servers] = grub_net_udp_open (servers[try_server++], DNS_PORT, recv_hook, &data); - send_servers++; - if (!sockets[send_servers - 1]) + if (!sockets[send_servers]) { err = grub_errno; grub_errno = GRUB_ERR_NONE; } else { - have_server = 1; + send_servers++; break; } } - if (!have_server) + if (!send_servers) goto out; if (*data.naddresses) goto out; for (j = 0; j < send_servers; j++) { grub_err_t err2; - if (!sockets[j]) - continue; + nb->data = nbd; grub_size_t t = 0; -- tg: (ba218c1..) u/dns-NULL-dereference (depends on: master) --------------000108000804010402030403--