]> git.ipfire.org Git - ipfire-2.x.git/blob - src/patches/glibc-2.38/0024-Fix-leak-in-getaddrinfo-introduced-by-the-fix-for-CV.patch
90b01ebdee93e669f0a8f104a8c4259bdf39b42f
[ipfire-2.x.git] / src / patches / glibc-2.38 / 0024-Fix-leak-in-getaddrinfo-introduced-by-the-fix-for-CV.patch
1 From 5ee59ca371b99984232d7584fe2b1a758b4421d3 Mon Sep 17 00:00:00 2001
2 From: Romain Geissler <romain.geissler@amadeus.com>
3 Date: Mon, 25 Sep 2023 01:21:51 +0100
4 Subject: [PATCH 24/44] Fix leak in getaddrinfo introduced by the fix for
5 CVE-2023-4806 [BZ #30843]
6
7 This patch fixes a very recently added leak in getaddrinfo.
8
9 This was assigned CVE-2023-5156.
10
11 Resolves: BZ #30884
12 Related: BZ #30842
13
14 Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
15 (cherry picked from commit ec6b95c3303c700eb89eebeda2d7264cc184a796)
16 ---
17 nss/Makefile | 20 ++++++++++++++++++++
18 nss/tst-nss-gai-hv2-canonname.c | 3 +++
19 sysdeps/posix/getaddrinfo.c | 4 +---
20 3 files changed, 24 insertions(+), 3 deletions(-)
21
22 diff --git a/nss/Makefile b/nss/Makefile
23 index 8a5126ecf3..668ba34b18 100644
24 --- a/nss/Makefile
25 +++ b/nss/Makefile
26 @@ -149,6 +149,15 @@ endif
27 extra-test-objs += nss_test1.os nss_test2.os nss_test_errno.os \
28 nss_test_gai_hv2_canonname.os
29
30 +ifeq ($(run-built-tests),yes)
31 +ifneq (no,$(PERL))
32 +tests-special += $(objpfx)mtrace-tst-nss-gai-hv2-canonname.out
33 +endif
34 +endif
35 +
36 +generated += mtrace-tst-nss-gai-hv2-canonname.out \
37 + tst-nss-gai-hv2-canonname.mtrace
38 +
39 include ../Rules
40
41 ifeq (yes,$(have-selinux))
42 @@ -217,6 +226,17 @@ endif
43 $(objpfx)tst-nss-files-alias-leak.out: $(objpfx)/libnss_files.so
44 $(objpfx)tst-nss-files-alias-truncated.out: $(objpfx)/libnss_files.so
45
46 +tst-nss-gai-hv2-canonname-ENV = \
47 + MALLOC_TRACE=$(objpfx)tst-nss-gai-hv2-canonname.mtrace \
48 + LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
49 +$(objpfx)mtrace-tst-nss-gai-hv2-canonname.out: \
50 + $(objpfx)tst-nss-gai-hv2-canonname.out
51 + { test -r $(objpfx)tst-nss-gai-hv2-canonname.mtrace \
52 + || ( echo "tst-nss-gai-hv2-canonname.mtrace does not exist"; exit 77; ) \
53 + && $(common-objpfx)malloc/mtrace \
54 + $(objpfx)tst-nss-gai-hv2-canonname.mtrace; } > $@; \
55 + $(evaluate-test)
56 +
57 # Disable DT_RUNPATH on NSS tests so that the glibc internal NSS
58 # functions can load testing NSS modules via DT_RPATH.
59 LDFLAGS-tst-nss-test1 = -Wl,--disable-new-dtags
60 diff --git a/nss/tst-nss-gai-hv2-canonname.c b/nss/tst-nss-gai-hv2-canonname.c
61 index d5f10c07d6..7db53cf09d 100644
62 --- a/nss/tst-nss-gai-hv2-canonname.c
63 +++ b/nss/tst-nss-gai-hv2-canonname.c
64 @@ -21,6 +21,7 @@
65 #include <netdb.h>
66 #include <stdlib.h>
67 #include <string.h>
68 +#include <mcheck.h>
69 #include <support/check.h>
70 #include <support/xstdio.h>
71 #include "nss/tst-nss-gai-hv2-canonname.h"
72 @@ -41,6 +42,8 @@ static void do_prepare (int a, char **av)
73 static int
74 do_test (void)
75 {
76 + mtrace ();
77 +
78 __nss_configure_lookup ("hosts", "test_gai_hv2_canonname");
79
80 struct addrinfo hints = {};
81 diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
82 index b2236b105c..13082305d3 100644
83 --- a/sysdeps/posix/getaddrinfo.c
84 +++ b/sysdeps/posix/getaddrinfo.c
85 @@ -1196,9 +1196,7 @@ free_and_return:
86 if (malloc_name)
87 free ((char *) name);
88 free (addrmem);
89 - if (res.free_at)
90 - free (res.at);
91 - free (res.canon);
92 + gaih_result_reset (&res);
93
94 return result;
95 }
96 --
97 2.39.2
98