|
| 1 | +From 6562a534ff741667d0725729ebc521bb0dac0e73 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Kanishk Bansal <kanbansal@microsoft.com> |
| 3 | +Date: Thu, 22 May 2025 08:46:55 +0000 |
| 4 | +Subject: [PATCH] CVE-2023-4527 |
| 5 | + |
| 6 | +Upstream Patch Reference : https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b25508dd774b617f99419bdc3cf2ace4560cd2d6 |
| 7 | + |
| 8 | +https://sourceware.org/cgit/glibc/tree/advisories/GLIBC-SA-2023-0002 |
| 9 | + |
| 10 | +Signed-off-by: Kanishk Bansal <kanbansal@microsoft.com> |
| 11 | +--- |
| 12 | + resolv/Makefile | 2 + |
| 13 | + resolv/nss_dns/dns-host.c | 2 +- |
| 14 | + resolv/tst-resolv-noaaaa-vc.c | 129 ++++++++++++++++++++++++++++++++++ |
| 15 | + 3 files changed, 132 insertions(+), 1 deletion(-) |
| 16 | + create mode 100644 resolv/tst-resolv-noaaaa-vc.c |
| 17 | + |
| 18 | +diff --git a/resolv/Makefile b/resolv/Makefile |
| 19 | +index 054b1fa3..2f99eb38 100644 |
| 20 | +--- a/resolv/Makefile |
| 21 | ++++ b/resolv/Makefile |
| 22 | +@@ -102,6 +102,7 @@ tests += \ |
| 23 | + tst-resolv-invalid-cname \ |
| 24 | + tst-resolv-network \ |
| 25 | + tst-resolv-noaaaa \ |
| 26 | ++ tst-resolv-noaaaa-vc \ |
| 27 | + tst-resolv-nondecimal \ |
| 28 | + tst-resolv-res_init-multi \ |
| 29 | + tst-resolv-search \ |
| 30 | +@@ -293,6 +294,7 @@ $(objpfx)tst-resolv-res_init-thread: $(objpfx)libresolv.so \ |
| 31 | + $(objpfx)tst-resolv-invalid-cname: $(objpfx)libresolv.so \ |
| 32 | + $(shared-thread-library) |
| 33 | + $(objpfx)tst-resolv-noaaaa: $(objpfx)libresolv.so $(shared-thread-library) |
| 34 | ++$(objpfx)tst-resolv-noaaaa-vc: $(objpfx)libresolv.so $(shared-thread-library) |
| 35 | + $(objpfx)tst-resolv-nondecimal: $(objpfx)libresolv.so $(shared-thread-library) |
| 36 | + $(objpfx)tst-resolv-qtypes: $(objpfx)libresolv.so $(shared-thread-library) |
| 37 | + $(objpfx)tst-resolv-rotate: $(objpfx)libresolv.so $(shared-thread-library) |
| 38 | +diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c |
| 39 | +index 1d60c51f..5d0ab30d 100644 |
| 40 | +--- a/resolv/nss_dns/dns-host.c |
| 41 | ++++ b/resolv/nss_dns/dns-host.c |
| 42 | +@@ -427,7 +427,7 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat, |
| 43 | + { |
| 44 | + n = __res_context_search (ctx, name, C_IN, T_A, |
| 45 | + dns_packet_buffer, sizeof (dns_packet_buffer), |
| 46 | +- NULL, NULL, NULL, NULL, NULL); |
| 47 | ++ &alt_dns_packet_buffer, NULL, NULL, NULL, NULL); |
| 48 | + if (n >= 0) |
| 49 | + status = gaih_getanswer_noaaaa (alt_dns_packet_buffer, n, |
| 50 | + &abuf, pat, errnop, herrnop, ttlp); |
| 51 | +diff --git a/resolv/tst-resolv-noaaaa-vc.c b/resolv/tst-resolv-noaaaa-vc.c |
| 52 | +new file mode 100644 |
| 53 | +index 00000000..9f5aebd9 |
| 54 | +--- /dev/null |
| 55 | ++++ b/resolv/tst-resolv-noaaaa-vc.c |
| 56 | +@@ -0,0 +1,129 @@ |
| 57 | ++/* Test the RES_NOAAAA resolver option with a large response. |
| 58 | ++ Copyright (C) 2022-2023 Free Software Foundation, Inc. |
| 59 | ++ This file is part of the GNU C Library. |
| 60 | ++ |
| 61 | ++ The GNU C Library is free software; you can redistribute it and/or |
| 62 | ++ modify it under the terms of the GNU Lesser General Public |
| 63 | ++ License as published by the Free Software Foundation; either |
| 64 | ++ version 2.1 of the License, or (at your option) any later version. |
| 65 | ++ |
| 66 | ++ The GNU C Library is distributed in the hope that it will be useful, |
| 67 | ++ but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 68 | ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 69 | ++ Lesser General Public License for more details. |
| 70 | ++ |
| 71 | ++ You should have received a copy of the GNU Lesser General Public |
| 72 | ++ License along with the GNU C Library; if not, see |
| 73 | ++ <https://www.gnu.org/licenses/>. */ |
| 74 | ++ |
| 75 | ++#include <errno.h> |
| 76 | ++#include <netdb.h> |
| 77 | ++#include <resolv.h> |
| 78 | ++#include <stdbool.h> |
| 79 | ++#include <stdlib.h> |
| 80 | ++#include <support/check.h> |
| 81 | ++#include <support/check_nss.h> |
| 82 | ++#include <support/resolv_test.h> |
| 83 | ++#include <support/support.h> |
| 84 | ++#include <support/xmemstream.h> |
| 85 | ++ |
| 86 | ++/* Used to keep track of the number of queries. */ |
| 87 | ++static volatile unsigned int queries; |
| 88 | ++ |
| 89 | ++/* If true, add a large TXT record at the start of the answer section. */ |
| 90 | ++static volatile bool stuff_txt; |
| 91 | ++ |
| 92 | ++static void |
| 93 | ++response (const struct resolv_response_context *ctx, |
| 94 | ++ struct resolv_response_builder *b, |
| 95 | ++ const char *qname, uint16_t qclass, uint16_t qtype) |
| 96 | ++{ |
| 97 | ++ /* If not using TCP, just force its use. */ |
| 98 | ++ if (!ctx->tcp) |
| 99 | ++ { |
| 100 | ++ struct resolv_response_flags flags = {.tc = true}; |
| 101 | ++ resolv_response_init (b, flags); |
| 102 | ++ resolv_response_add_question (b, qname, qclass, qtype); |
| 103 | ++ return; |
| 104 | ++ } |
| 105 | ++ |
| 106 | ++ /* The test needs to send four queries, the first three are used to |
| 107 | ++ grow the NSS buffer via the ERANGE handshake. */ |
| 108 | ++ ++queries; |
| 109 | ++ TEST_VERIFY (queries <= 4); |
| 110 | ++ |
| 111 | ++ /* AAAA queries are supposed to be disabled. */ |
| 112 | ++ TEST_COMPARE (qtype, T_A); |
| 113 | ++ TEST_COMPARE (qclass, C_IN); |
| 114 | ++ TEST_COMPARE_STRING (qname, "example.com"); |
| 115 | ++ |
| 116 | ++ struct resolv_response_flags flags = {}; |
| 117 | ++ resolv_response_init (b, flags); |
| 118 | ++ resolv_response_add_question (b, qname, qclass, qtype); |
| 119 | ++ |
| 120 | ++ resolv_response_section (b, ns_s_an); |
| 121 | ++ |
| 122 | ++ if (stuff_txt) |
| 123 | ++ { |
| 124 | ++ resolv_response_open_record (b, qname, qclass, T_TXT, 60); |
| 125 | ++ int zero = 0; |
| 126 | ++ for (int i = 0; i <= 15000; ++i) |
| 127 | ++ resolv_response_add_data (b, &zero, sizeof (zero)); |
| 128 | ++ resolv_response_close_record (b); |
| 129 | ++ } |
| 130 | ++ |
| 131 | ++ for (int i = 0; i < 200; ++i) |
| 132 | ++ { |
| 133 | ++ resolv_response_open_record (b, qname, qclass, qtype, 60); |
| 134 | ++ char ipv4[4] = {192, 0, 2, i + 1}; |
| 135 | ++ resolv_response_add_data (b, &ipv4, sizeof (ipv4)); |
| 136 | ++ resolv_response_close_record (b); |
| 137 | ++ } |
| 138 | ++} |
| 139 | ++ |
| 140 | ++static int |
| 141 | ++do_test (void) |
| 142 | ++{ |
| 143 | ++ struct resolv_test *obj = resolv_test_start |
| 144 | ++ ((struct resolv_redirect_config) |
| 145 | ++ { |
| 146 | ++ .response_callback = response |
| 147 | ++ }); |
| 148 | ++ |
| 149 | ++ _res.options |= RES_NOAAAA; |
| 150 | ++ |
| 151 | ++ for (int do_stuff_txt = 0; do_stuff_txt < 2; ++do_stuff_txt) |
| 152 | ++ { |
| 153 | ++ queries = 0; |
| 154 | ++ stuff_txt = do_stuff_txt; |
| 155 | ++ |
| 156 | ++ struct addrinfo *ai = NULL; |
| 157 | ++ int ret; |
| 158 | ++ ret = getaddrinfo ("example.com", "80", |
| 159 | ++ &(struct addrinfo) |
| 160 | ++ { |
| 161 | ++ .ai_family = AF_UNSPEC, |
| 162 | ++ .ai_socktype = SOCK_STREAM, |
| 163 | ++ }, &ai); |
| 164 | ++ |
| 165 | ++ char *expected_result; |
| 166 | ++ { |
| 167 | ++ struct xmemstream mem; |
| 168 | ++ xopen_memstream (&mem); |
| 169 | ++ for (int i = 0; i < 200; ++i) |
| 170 | ++ fprintf (mem.out, "address: STREAM/TCP 192.0.2.%d 80\n", i + 1); |
| 171 | ++ xfclose_memstream (&mem); |
| 172 | ++ expected_result = mem.buffer; |
| 173 | ++ } |
| 174 | ++ |
| 175 | ++ check_addrinfo ("example.com", ai, ret, expected_result); |
| 176 | ++ |
| 177 | ++ free (expected_result); |
| 178 | ++ freeaddrinfo (ai); |
| 179 | ++ } |
| 180 | ++ |
| 181 | ++ resolv_test_end (obj); |
| 182 | ++ return 0; |
| 183 | ++} |
| 184 | ++ |
| 185 | ++#include <support/test-driver.c> |
| 186 | +-- |
| 187 | +2.45.3 |
| 188 | + |
0 commit comments