From patchwork Thu Oct 16 15:39:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Griffis X-Patchwork-Id: 121974 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 247D83857C5F for ; Thu, 16 Oct 2025 15:41:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 247D83857C5F Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=igalia.com header.i=@igalia.com header.a=rsa-sha256 header.s=20170329 header.b=M+yi1gI1 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by sourceware.org (Postfix) with ESMTPS id 9C44B3858D1E for ; Thu, 16 Oct 2025 15:40:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9C44B3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=igalia.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9C44B3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1760629211; cv=none; b=AJi9kby1IL5yEsIvgLP2r8joWKUdVQYk/h2BUKsOIA2MhqBE5ubzz9OJdQHXP9L8q+AwOVVPvx6zbZ97n1sN1+3b6CJrCx6PVvXsg+Kxe9HW4rTIi1sgqbW3OTQvC8itqV3ViomAHOgALXkGbhEJNGTnL1b9vGlN/HyMiM1yWMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1760629211; c=relaxed/simple; bh=1ikAaEQHCz2wn0lQIOTNWQkroFw1BuA9d2YzjO0YHnM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=PAOY/c69jEfSFg+1c6rrBmbCRovbqO6YxwTlzsPdWdQMRu0pYlxM1/SbUcMQ5mpNsalTMF0uXkzwbHJ403uSfJ3EUhoMJwndFrLrT2SaQ67sjs3vg7BJAOBzc5KlK2hEn+qZB18uaJG0P1ot2HwVikl6wQgU8/cjHo/H3KhZD84= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C44B3858D1E DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=iZWk8NVXThI9jkLtgmoKyV9XgDQjCO3UNlctX39m3nc=; b=M+yi1gI12TERxNfAyHRTdJg0v3 +TKXPNwMwXcLR4MJ15TBBTXR8OIwK8XQ4KLkZXHGu9hdkbf+5/CDEtDwFVexQG60wjIC74osoX5hA qBJfHRkIA1Zg4QNMlzSxi+qYKZA6VkqhtxJQATy3xKB+1KHe+o6vfSJRoYy11l+pw6hB6/wO3wwC9 +evoh5JIZyzFnZ/J5tK9wygZL1BokHo2LFuT8mPVmdTviMViCL9nIJc4A83thjEoxWo4j8c2jLXNR vMw+qVgxaBfDRw+g8efb8d8olGgD1+zUwx+eIY2e1jmHDymV9K7/E48uauPwjTzl4adcr3eVwjoFN CAr+K0Ww==; Received: from [65.128.106.6] (helo=desktop) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1v9Q5J-00AVlB-O8; Thu, 16 Oct 2025 17:40:10 +0200 From: Patrick Griffis To: libc-alpha@sourceware.org Cc: Patrick Griffis Subject: [PATCH] nss: Use gethostbyname4_r when requesting IPv6 addresses (bug 14413) Date: Thu, 16 Oct 2025 10:39:51 -0500 Message-ID: <20251016153951.1079645-1-pgriffis@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251007191236.1717898-1-pgriffis@igalia.com> References: <20251007191236.1717898-1-pgriffis@igalia.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org If getaddrinfo() is called with family of AF_INET6 it would return IPv6 addresses lacking scope_id information. This was a regression caused by bug 14505. That patch avoided calling gethostbyname4_r unless AF_UNSPEC is passed. The reasoning was that gethostbyname4_r has no ability to only ask for a specific family. That is true however gethostbyname3_r returns a list of hostent structs which lack scope_id information. The solution is to always use gethostbyname4_r if IPv6 is requested. This does have the downside of IPv4 addresses being looked up by modules even when they are not needed. --- nss/getaddrinfo.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/nss/getaddrinfo.c b/nss/getaddrinfo.c index 6726ace6fd..67f7223ac7 100644 --- a/nss/getaddrinfo.c +++ b/nss/getaddrinfo.c @@ -644,9 +644,12 @@ get_nss_addresses (const char *name, const struct addrinfo *req, no_data = 0; nss_gethostbyname4_r *fct4 = NULL; - /* gethostbyname4_r sends out parallel A and AAAA queries and - is thus only suitable for PF_UNSPEC. */ - if (req->ai_family == PF_UNSPEC) + /* The gethostbyname4_r API is always expected to return both address families + * which means we would prefer gethostbyname3_r when requesting only IPv4 addresses. + * Unfortunately when requesting IPv6 only we have to use this API for link-local + * information (scope_id is not in the hostent struct). + * This means we may collect unncessary IPv4 addresses. */ + if (req->ai_family != AF_INET) fct4 = __nss_lookup_function (nip, "gethostbyname4_r"); if (fct4 != NULL) @@ -856,6 +859,11 @@ get_nss_addresses (const char *name, const struct addrinfo *req, /* If both requests timed out report this. */ if (no_data == EAI_AGAIN && no_inet6_data == EAI_AGAIN) result = -EAI_AGAIN; + else if (req->ai_family == AF_INET6 && !res->got_ipv6) + /* If only IPv6 addresses were requested and we only got IPv4 addresses + * we ignore those. This is less accurate but matches previous behavior. + * The cause of this is commented above when using gethostbyname4_r */ + result = -EAI_NONAME; else /* We made requests but they turned out no data. The name is known, though. */