mirror of
https://abf.rosa.ru/djam/glibc40.git
synced 2025-02-23 15:52:52 +00:00
Fix CVE-2015-7547 and several other issues
This commit is contained in:
parent
3f47d5663a
commit
491d5748bd
5 changed files with 755 additions and 1 deletions
163
glibc-rh1170118-CVE-2014-7817.patch
Normal file
163
glibc-rh1170118-CVE-2014-7817.patch
Normal file
|
@ -0,0 +1,163 @@
|
||||||
|
#
|
||||||
|
# commit a39208bd7fb76c1b01c127b4c61f9bfd915bfe7c
|
||||||
|
# Author: Carlos O'Donell <carlos@redhat.com>
|
||||||
|
# Date: Wed Nov 19 11:44:12 2014 -0500
|
||||||
|
#
|
||||||
|
# CVE-2014-7817: wordexp fails to honour WRDE_NOCMD.
|
||||||
|
#
|
||||||
|
# The function wordexp() fails to properly handle the WRDE_NOCMD
|
||||||
|
# flag when processing arithmetic inputs in the form of "$((... ``))"
|
||||||
|
# where "..." can be anything valid. The backticks in the arithmetic
|
||||||
|
# epxression are evaluated by in a shell even if WRDE_NOCMD forbade
|
||||||
|
# command substitution. This allows an attacker to attempt to pass
|
||||||
|
# dangerous commands via constructs of the above form, and bypass
|
||||||
|
# the WRDE_NOCMD flag. This patch fixes this by checking for WRDE_NOCMD
|
||||||
|
# in exec_comm(), the only place that can execute a shell. All other
|
||||||
|
# checks for WRDE_NOCMD are superfluous and removed.
|
||||||
|
#
|
||||||
|
# We expand the testsuite and add 3 new regression tests of roughly
|
||||||
|
# the same form but with a couple of nested levels.
|
||||||
|
#
|
||||||
|
# On top of the 3 new tests we add fork validation to the WRDE_NOCMD
|
||||||
|
# testing. If any forks are detected during the execution of a wordexp()
|
||||||
|
# call with WRDE_NOCMD, the test is marked as failed. This is slightly
|
||||||
|
# heuristic since vfork might be used in the future, but it provides a
|
||||||
|
# higher level of assurance that no shells were executed as part of
|
||||||
|
# command substitution with WRDE_NOCMD in effect. In addition it doesn't
|
||||||
|
# require libpthread or libdl, instead we use the public implementation
|
||||||
|
# namespace function __register_atfork (already part of the public ABI
|
||||||
|
# for libpthread).
|
||||||
|
#
|
||||||
|
# Tested on x86_64 with no regressions.
|
||||||
|
#
|
||||||
|
diff --git glibc-2.17-c758a686/posix/wordexp-test.c glibc-2.17-c758a686/posix/wordexp-test.c
|
||||||
|
index 4957006..bdd65e4 100644
|
||||||
|
--- glibc-2.17-c758a686/posix/wordexp-test.c
|
||||||
|
+++ glibc-2.17-c758a686/posix/wordexp-test.c
|
||||||
|
@@ -27,6 +27,25 @@
|
||||||
|
|
||||||
|
#define IFS " \n\t"
|
||||||
|
|
||||||
|
+extern void *__dso_handle __attribute__ ((__weak__, __visibility__ ("hidden")));
|
||||||
|
+extern int __register_atfork (void (*) (void), void (*) (void), void (*) (void), void *);
|
||||||
|
+
|
||||||
|
+static int __app_register_atfork (void (*prepare) (void), void (*parent) (void), void (*child) (void))
|
||||||
|
+{
|
||||||
|
+ return __register_atfork (prepare, parent, child,
|
||||||
|
+ &__dso_handle == NULL ? NULL : __dso_handle);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+/* Number of forks seen. */
|
||||||
|
+static int registered_forks;
|
||||||
|
+
|
||||||
|
+/* For each fork increment the fork count. */
|
||||||
|
+static void
|
||||||
|
+register_fork (void)
|
||||||
|
+{
|
||||||
|
+ registered_forks++;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
struct test_case_struct
|
||||||
|
{
|
||||||
|
int retval;
|
||||||
|
@@ -206,6 +225,12 @@ struct test_case_struct
|
||||||
|
{ WRDE_SYNTAX, NULL, "$((2+))", 0, 0, { NULL, }, IFS },
|
||||||
|
{ WRDE_SYNTAX, NULL, "`", 0, 0, { NULL, }, IFS },
|
||||||
|
{ WRDE_SYNTAX, NULL, "$((010+4+))", 0, 0, { NULL }, IFS },
|
||||||
|
+ /* Test for CVE-2014-7817. We test 3 combinations of command
|
||||||
|
+ substitution inside an arithmetic expression to make sure that
|
||||||
|
+ no commands are executed and error is returned. */
|
||||||
|
+ { WRDE_CMDSUB, NULL, "$((`echo 1`))", WRDE_NOCMD, 0, { NULL, }, IFS },
|
||||||
|
+ { WRDE_CMDSUB, NULL, "$((1+`echo 1`))", WRDE_NOCMD, 0, { NULL, }, IFS },
|
||||||
|
+ { WRDE_CMDSUB, NULL, "$((1+$((`echo 1`))))", WRDE_NOCMD, 0, { NULL, }, IFS },
|
||||||
|
|
||||||
|
{ -1, NULL, NULL, 0, 0, { NULL, }, IFS },
|
||||||
|
};
|
||||||
|
@@ -258,6 +283,15 @@ main (int argc, char *argv[])
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ /* If we are not allowed to do command substitution, we install
|
||||||
|
+ fork handlers to verify that no forks happened. No forks should
|
||||||
|
+ happen at all if command substitution is disabled. */
|
||||||
|
+ if (__app_register_atfork (register_fork, NULL, NULL) != 0)
|
||||||
|
+ {
|
||||||
|
+ printf ("Failed to register fork handler.\n");
|
||||||
|
+ return -1;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
for (test = 0; test_case[test].retval != -1; test++)
|
||||||
|
if (testit (&test_case[test]))
|
||||||
|
++fail;
|
||||||
|
@@ -367,6 +401,9 @@ testit (struct test_case_struct *tc)
|
||||||
|
|
||||||
|
printf ("Test %d (%s): ", ++tests, tc->words);
|
||||||
|
|
||||||
|
+ if (tc->flags & WRDE_NOCMD)
|
||||||
|
+ registered_forks = 0;
|
||||||
|
+
|
||||||
|
if (tc->flags & WRDE_APPEND)
|
||||||
|
{
|
||||||
|
/* initial wordexp() call, to be appended to */
|
||||||
|
@@ -378,6 +415,13 @@ testit (struct test_case_struct *tc)
|
||||||
|
}
|
||||||
|
retval = wordexp (tc->words, &we, tc->flags);
|
||||||
|
|
||||||
|
+ if ((tc->flags & WRDE_NOCMD)
|
||||||
|
+ && (registered_forks > 0))
|
||||||
|
+ {
|
||||||
|
+ printf ("FAILED fork called for WRDE_NOCMD\n");
|
||||||
|
+ return 1;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
if (tc->flags & WRDE_DOOFFS)
|
||||||
|
start_offs = sav_we.we_offs;
|
||||||
|
|
||||||
|
diff --git glibc-2.17-c758a686/posix/wordexp.c glibc-2.17-c758a686/posix/wordexp.c
|
||||||
|
index b6b65dd..26f3a26 100644
|
||||||
|
--- glibc-2.17-c758a686/posix/wordexp.c
|
||||||
|
+++ glibc-2.17-c758a686/posix/wordexp.c
|
||||||
|
@@ -893,6 +893,10 @@ exec_comm (char *comm, char **word, size_t *word_length, size_t *max_length,
|
||||||
|
pid_t pid;
|
||||||
|
int noexec = 0;
|
||||||
|
|
||||||
|
+ /* Do nothing if command substitution should not succeed. */
|
||||||
|
+ if (flags & WRDE_NOCMD)
|
||||||
|
+ return WRDE_CMDSUB;
|
||||||
|
+
|
||||||
|
/* Don't fork() unless necessary */
|
||||||
|
if (!comm || !*comm)
|
||||||
|
return 0;
|
||||||
|
@@ -2082,9 +2086,6 @@ parse_dollars (char **word, size_t *word_length, size_t *max_length,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- if (flags & WRDE_NOCMD)
|
||||||
|
- return WRDE_CMDSUB;
|
||||||
|
-
|
||||||
|
(*offset) += 2;
|
||||||
|
return parse_comm (word, word_length, max_length, words, offset, flags,
|
||||||
|
quoted? NULL : pwordexp, ifs, ifs_white);
|
||||||
|
@@ -2196,9 +2197,6 @@ parse_dquote (char **word, size_t *word_length, size_t *max_length,
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '`':
|
||||||
|
- if (flags & WRDE_NOCMD)
|
||||||
|
- return WRDE_CMDSUB;
|
||||||
|
-
|
||||||
|
++(*offset);
|
||||||
|
error = parse_backtick (word, word_length, max_length, words,
|
||||||
|
offset, flags, NULL, NULL, NULL);
|
||||||
|
@@ -2357,12 +2355,6 @@ wordexp (const char *words, wordexp_t *pwordexp, int flags)
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '`':
|
||||||
|
- if (flags & WRDE_NOCMD)
|
||||||
|
- {
|
||||||
|
- error = WRDE_CMDSUB;
|
||||||
|
- goto do_error;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
++words_offset;
|
||||||
|
error = parse_backtick (&word, &word_length, &max_length, words,
|
||||||
|
&words_offset, flags, pwordexp, ifs,
|
18
glibc-rh1194143.patch
Normal file
18
glibc-rh1194143.patch
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
commit f9d2d03254a58d92635a311a42253eeed5a40a47
|
||||||
|
Author: Andreas Schwab <schwab@suse.de>
|
||||||
|
Date: Mon May 26 18:01:31 2014 +0200
|
||||||
|
|
||||||
|
Fix invalid file descriptor reuse while sending DNS query (BZ #15946)
|
||||||
|
|
||||||
|
diff --git glibc-2.17-c758a686/resolv/res_send.c glibc-2.17-c758a686/resolv/res_send.c
|
||||||
|
index 3273d55..af42b8a 100644
|
||||||
|
--- glibc-2.17-c758a686/resolv/res_send.c
|
||||||
|
+++ glibc-2.17-c758a686/resolv/res_send.c
|
||||||
|
@@ -1410,6 +1410,7 @@ send_dg(res_state statp,
|
||||||
|
retval = reopen (statp, terrno, ns);
|
||||||
|
if (retval <= 0)
|
||||||
|
return retval;
|
||||||
|
+ pfd[0].fd = EXT(statp).nssocks[ns];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
goto wait;
|
20
glibc-rh1199525.patch
Normal file
20
glibc-rh1199525.patch
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
commit 2959eda9272a033863c271aff62095abd01bd4e3
|
||||||
|
Author: Arjun Shankar <arjun.is@lostca.se>
|
||||||
|
Date: Tue Apr 21 14:06:31 2015 +0200
|
||||||
|
|
||||||
|
CVE-2015-1781: resolv/nss_dns/dns-host.c buffer overflow [BZ#18287]
|
||||||
|
|
||||||
|
diff --git glibc-2.17-c758a686/resolv/nss_dns/dns-host.c glibc-2.17-c758a686/resolv/nss_dns/dns-host.c
|
||||||
|
index b16b0dd..d8c5579 100644
|
||||||
|
--- glibc-2.17-c758a686/resolv/nss_dns/dns-host.c
|
||||||
|
+++ glibc-2.17-c758a686/resolv/nss_dns/dns-host.c
|
||||||
|
@@ -613,7 +613,8 @@
|
||||||
|
int have_to_map = 0;
|
||||||
|
uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct host_data);
|
||||||
|
buffer += pad;
|
||||||
|
- if (__builtin_expect (buflen < sizeof (struct host_data) + pad, 0))
|
||||||
|
+ buflen = buflen > pad ? buflen - pad : 0;
|
||||||
|
+ if (__builtin_expect (buflen < sizeof (struct host_data), 0))
|
||||||
|
{
|
||||||
|
/* The buffer is too small. */
|
||||||
|
too_small:
|
542
glibc-rh1296031.patch
Normal file
542
glibc-rh1296031.patch
Normal file
|
@ -0,0 +1,542 @@
|
||||||
|
diff -Naur glibc-2.19.orig/resolv/nss_dns/dns-host.c glibc-2.19/resolv/nss_dns/dns-host.c
|
||||||
|
--- glibc-2.19.orig/resolv/nss_dns/dns-host.c 2016-02-19 15:40:23.394686772 +0300
|
||||||
|
+++ glibc-2.19/resolv/nss_dns/dns-host.c 2016-02-19 15:40:23.397686773 +0300
|
||||||
|
@@ -1049,7 +1049,10 @@
|
||||||
|
int h_namelen = 0;
|
||||||
|
|
||||||
|
if (ancount == 0)
|
||||||
|
- return NSS_STATUS_NOTFOUND;
|
||||||
|
+ {
|
||||||
|
+ *h_errnop = HOST_NOT_FOUND;
|
||||||
|
+ return NSS_STATUS_NOTFOUND;
|
||||||
|
+ }
|
||||||
|
|
||||||
|
while (ancount-- > 0 && cp < end_of_message && had_error == 0)
|
||||||
|
{
|
||||||
|
@@ -1226,7 +1229,14 @@
|
||||||
|
/* Special case here: if the resolver sent a result but it only
|
||||||
|
contains a CNAME while we are looking for a T_A or T_AAAA record,
|
||||||
|
we fail with NOTFOUND instead of TRYAGAIN. */
|
||||||
|
- return canon == NULL ? NSS_STATUS_TRYAGAIN : NSS_STATUS_NOTFOUND;
|
||||||
|
+ if (canon != NULL)
|
||||||
|
+ {
|
||||||
|
+ *h_errnop = HOST_NOT_FOUND;
|
||||||
|
+ return NSS_STATUS_NOTFOUND;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ *h_errnop = NETDB_INTERNAL;
|
||||||
|
+ return NSS_STATUS_TRYAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1240,11 +1250,101 @@
|
||||||
|
|
||||||
|
enum nss_status status = NSS_STATUS_NOTFOUND;
|
||||||
|
|
||||||
|
+ /* Combining the NSS status of two distinct queries requires some
|
||||||
|
+ compromise and attention to symmetry (A or AAAA queries can be
|
||||||
|
+ returned in any order). What follows is a breakdown of how this
|
||||||
|
+ code is expected to work and why. We discuss only SUCCESS,
|
||||||
|
+ TRYAGAIN, NOTFOUND and UNAVAIL, since they are the only returns
|
||||||
|
+ that apply (though RETURN and MERGE exist). We make a distinction
|
||||||
|
+ between TRYAGAIN (recoverable) and TRYAGAIN' (not-recoverable).
|
||||||
|
+ A recoverable TRYAGAIN is almost always due to buffer size issues
|
||||||
|
+ and returns ERANGE in errno and the caller is expected to retry
|
||||||
|
+ with a larger buffer.
|
||||||
|
+
|
||||||
|
+ Lastly, you may be tempted to make significant changes to the
|
||||||
|
+ conditions in this code to bring about symmetry between responses.
|
||||||
|
+ Please don't change anything without due consideration for
|
||||||
|
+ expected application behaviour. Some of the synthesized responses
|
||||||
|
+ aren't very well thought out and sometimes appear to imply that
|
||||||
|
+ IPv4 responses are always answer 1, and IPv6 responses are always
|
||||||
|
+ answer 2, but that's not true (see the implemetnation of send_dg
|
||||||
|
+ and send_vc to see response can arrive in any order, particlarly
|
||||||
|
+ for UDP). However, we expect it holds roughly enough of the time
|
||||||
|
+ that this code works, but certainly needs to be fixed to make this
|
||||||
|
+ a more robust implementation.
|
||||||
|
+
|
||||||
|
+ ----------------------------------------------
|
||||||
|
+ | Answer 1 Status / | Synthesized | Reason |
|
||||||
|
+ | Answer 2 Status | Status | |
|
||||||
|
+ |--------------------------------------------|
|
||||||
|
+ | SUCCESS/SUCCESS | SUCCESS | [1] |
|
||||||
|
+ | SUCCESS/TRYAGAIN | TRYAGAIN | [5] |
|
||||||
|
+ | SUCCESS/TRYAGAIN' | SUCCESS | [1] |
|
||||||
|
+ | SUCCESS/NOTFOUND | SUCCESS | [1] |
|
||||||
|
+ | SUCCESS/UNAVAIL | SUCCESS | [1] |
|
||||||
|
+ | TRYAGAIN/SUCCESS | TRYAGAIN | [2] |
|
||||||
|
+ | TRYAGAIN/TRYAGAIN | TRYAGAIN | [2] |
|
||||||
|
+ | TRYAGAIN/TRYAGAIN' | TRYAGAIN | [2] |
|
||||||
|
+ | TRYAGAIN/NOTFOUND | TRYAGAIN | [2] |
|
||||||
|
+ | TRYAGAIN/UNAVAIL | TRYAGAIN | [2] |
|
||||||
|
+ | TRYAGAIN'/SUCCESS | SUCCESS | [3] |
|
||||||
|
+ | TRYAGAIN'/TRYAGAIN | TRYAGAIN | [3] |
|
||||||
|
+ | TRYAGAIN'/TRYAGAIN' | TRYAGAIN' | [3] |
|
||||||
|
+ | TRYAGAIN'/NOTFOUND | TRYAGAIN' | [3] |
|
||||||
|
+ | TRYAGAIN'/UNAVAIL | UNAVAIL | [3] |
|
||||||
|
+ | NOTFOUND/SUCCESS | SUCCESS | [3] |
|
||||||
|
+ | NOTFOUND/TRYAGAIN | TRYAGAIN | [3] |
|
||||||
|
+ | NOTFOUND/TRYAGAIN' | TRYAGAIN' | [3] |
|
||||||
|
+ | NOTFOUND/NOTFOUND | NOTFOUND | [3] |
|
||||||
|
+ | NOTFOUND/UNAVAIL | UNAVAIL | [3] |
|
||||||
|
+ | UNAVAIL/SUCCESS | UNAVAIL | [4] |
|
||||||
|
+ | UNAVAIL/TRYAGAIN | UNAVAIL | [4] |
|
||||||
|
+ | UNAVAIL/TRYAGAIN' | UNAVAIL | [4] |
|
||||||
|
+ | UNAVAIL/NOTFOUND | UNAVAIL | [4] |
|
||||||
|
+ | UNAVAIL/UNAVAIL | UNAVAIL | [4] |
|
||||||
|
+ ----------------------------------------------
|
||||||
|
+
|
||||||
|
+ [1] If the first response is a success we return success.
|
||||||
|
+ This ignores the state of the second answer and in fact
|
||||||
|
+ incorrectly sets errno and h_errno to that of the second
|
||||||
|
+ answer. However because the response is a success we ignore
|
||||||
|
+ *errnop and *h_errnop (though that means you touched errno on
|
||||||
|
+ success). We are being conservative here and returning the
|
||||||
|
+ likely IPv4 response in the first answer as a success.
|
||||||
|
+
|
||||||
|
+ [2] If the first response is a recoverable TRYAGAIN we return
|
||||||
|
+ that instead of looking at the second response. The
|
||||||
|
+ expectation here is that we have failed to get an IPv4 response
|
||||||
|
+ and should retry both queries.
|
||||||
|
+
|
||||||
|
+ [3] If the first response was not a SUCCESS and the second
|
||||||
|
+ response is not NOTFOUND (had a SUCCESS, need to TRYAGAIN,
|
||||||
|
+ or failed entirely e.g. TRYAGAIN' and UNAVAIL) then use the
|
||||||
|
+ result from the second response, otherwise the first responses
|
||||||
|
+ status is used. Again we have some odd side-effects when the
|
||||||
|
+ second response is NOTFOUND because we overwrite *errnop and
|
||||||
|
+ *h_errnop that means that a first answer of NOTFOUND might see
|
||||||
|
+ its *errnop and *h_errnop values altered. Whether it matters
|
||||||
|
+ in practice that a first response NOTFOUND has the wrong
|
||||||
|
+ *errnop and *h_errnop is undecided.
|
||||||
|
+
|
||||||
|
+ [4] If the first response is UNAVAIL we return that instead of
|
||||||
|
+ looking at the second response. The expectation here is that
|
||||||
|
+ it will have failed similarly e.g. configuration failure.
|
||||||
|
+
|
||||||
|
+ [5] Testing this code is complicated by the fact that truncated
|
||||||
|
+ second response buffers might be returned as SUCCESS if the
|
||||||
|
+ first answer is a SUCCESS. To fix this we add symmetry to
|
||||||
|
+ TRYAGAIN with the second response. If the second response
|
||||||
|
+ is a recoverable error we now return TRYAGIN even if the first
|
||||||
|
+ response was SUCCESS. */
|
||||||
|
+
|
||||||
|
if (anslen1 > 0)
|
||||||
|
status = gaih_getanswer_slice(answer1, anslen1, qname,
|
||||||
|
&pat, &buffer, &buflen,
|
||||||
|
errnop, h_errnop, ttlp,
|
||||||
|
&first);
|
||||||
|
+
|
||||||
|
if ((status == NSS_STATUS_SUCCESS || status == NSS_STATUS_NOTFOUND
|
||||||
|
|| (status == NSS_STATUS_TRYAGAIN
|
||||||
|
/* We want to look at the second answer in case of an
|
||||||
|
@@ -1260,8 +1360,15 @@
|
||||||
|
&pat, &buffer, &buflen,
|
||||||
|
errnop, h_errnop, ttlp,
|
||||||
|
&first);
|
||||||
|
+ /* Use the second response status in some cases. */
|
||||||
|
if (status != NSS_STATUS_SUCCESS && status2 != NSS_STATUS_NOTFOUND)
|
||||||
|
status = status2;
|
||||||
|
+ /* Do not return a truncated second response (unless it was
|
||||||
|
+ unavoidable e.g. unrecoverable TRYAGAIN). */
|
||||||
|
+ if (status == NSS_STATUS_SUCCESS
|
||||||
|
+ && (status2 == NSS_STATUS_TRYAGAIN
|
||||||
|
+ && *errnop == ERANGE && *h_errnop != NO_RECOVERY))
|
||||||
|
+ status = NSS_STATUS_TRYAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
diff -Naur glibc-2.19.orig/resolv/res_query.c glibc-2.19/resolv/res_query.c
|
||||||
|
--- glibc-2.19.orig/resolv/res_query.c 2016-02-19 15:40:23.394686772 +0300
|
||||||
|
+++ glibc-2.19/resolv/res_query.c 2016-02-19 15:41:27.700691113 +0300
|
||||||
|
@@ -391,6 +391,7 @@
|
||||||
|
{
|
||||||
|
free (*answerp2);
|
||||||
|
*answerp2 = NULL;
|
||||||
|
+ *nanswerp2 = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -431,6 +432,7 @@
|
||||||
|
{
|
||||||
|
free (*answerp2);
|
||||||
|
*answerp2 = NULL;
|
||||||
|
+ *nanswerp2 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
@@ -502,6 +504,7 @@
|
||||||
|
{
|
||||||
|
free (*answerp2);
|
||||||
|
*answerp2 = NULL;
|
||||||
|
+ *nanswerp2 = 0;
|
||||||
|
}
|
||||||
|
if (saved_herrno != -1)
|
||||||
|
RES_SET_H_ERRNO(statp, saved_herrno);
|
||||||
|
diff -Naur glibc-2.19.orig/resolv/res_send.c glibc-2.19/resolv/res_send.c
|
||||||
|
--- glibc-2.19.orig/resolv/res_send.c 2016-02-19 15:40:23.394686772 +0300
|
||||||
|
+++ glibc-2.19/resolv/res_send.c 2016-02-19 15:46:00.356709515 +0300
|
||||||
|
@@ -1,3 +1,20 @@
|
||||||
|
+/* Copyright (C) 2016 Free Software Foundation, Inc.
|
||||||
|
+ This file is part of the GNU C Library.
|
||||||
|
+
|
||||||
|
+ The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
+ modify it under the terms of the GNU Lesser General Public
|
||||||
|
+ License as published by the Free Software Foundation; either
|
||||||
|
+ version 2.1 of the License, or (at your option) any later version.
|
||||||
|
+
|
||||||
|
+ The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
+ Lesser General Public License for more details.
|
||||||
|
+
|
||||||
|
+ You should have received a copy of the GNU Lesser General Public
|
||||||
|
+ License along with the GNU C Library; if not, see
|
||||||
|
+ <http://www.gnu.org/licenses/>. */
|
||||||
|
+
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1985, 1989, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
@@ -360,6 +377,8 @@
|
||||||
|
#ifdef USE_HOOKS
|
||||||
|
if (__builtin_expect (statp->qhook || statp->rhook, 0)) {
|
||||||
|
if (anssiz < MAXPACKET && ansp) {
|
||||||
|
+ /* Always allocate MAXPACKET, callers expect
|
||||||
|
+ this specific size. */
|
||||||
|
u_char *buf = malloc (MAXPACKET);
|
||||||
|
if (buf == NULL)
|
||||||
|
return (-1);
|
||||||
|
@@ -652,6 +671,77 @@
|
||||||
|
|
||||||
|
/* Private */
|
||||||
|
|
||||||
|
+/* The send_vc function is responsible for sending a DNS query over TCP
|
||||||
|
+ to the nameserver numbered NS from the res_state STATP i.e.
|
||||||
|
+ EXT(statp).nssocks[ns]. The function supports sending both IPv4 and
|
||||||
|
+ IPv6 queries at the same serially on the same socket.
|
||||||
|
+
|
||||||
|
+ Please note that for TCP there is no way to disable sending both
|
||||||
|
+ queries, unlike UDP, which honours RES_SNGLKUP and RES_SNGLKUPREOP
|
||||||
|
+ and sends the queries serially and waits for the result after each
|
||||||
|
+ sent query. This implemetnation should be corrected to honour these
|
||||||
|
+ options.
|
||||||
|
+
|
||||||
|
+ Please also note that for TCP we send both queries over the same
|
||||||
|
+ socket one after another. This technically violates best practice
|
||||||
|
+ since the server is allowed to read the first query, respond, and
|
||||||
|
+ then close the socket (to service another client). If the server
|
||||||
|
+ does this, then the remaining second query in the socket data buffer
|
||||||
|
+ will cause the server to send the client an RST which will arrive
|
||||||
|
+ asynchronously and the client's OS will likely tear down the socket
|
||||||
|
+ receive buffer resulting in a potentially short read and lost
|
||||||
|
+ response data. This will force the client to retry the query again,
|
||||||
|
+ and this process may repeat until all servers and connection resets
|
||||||
|
+ are exhausted and then the query will fail. It's not known if this
|
||||||
|
+ happens with any frequency in real DNS server implementations. This
|
||||||
|
+ implementation should be corrected to use two sockets by default for
|
||||||
|
+ parallel queries.
|
||||||
|
+
|
||||||
|
+ The query stored in BUF of BUFLEN length is sent first followed by
|
||||||
|
+ the query stored in BUF2 of BUFLEN2 length. Queries are sent
|
||||||
|
+ serially on the same socket.
|
||||||
|
+
|
||||||
|
+ Answers to the query are stored firstly in *ANSP up to a max of
|
||||||
|
+ *ANSSIZP bytes. If more than *ANSSIZP bytes are needed and ANSCP
|
||||||
|
+ is non-NULL (to indicate that modifying the answer buffer is allowed)
|
||||||
|
+ then malloc is used to allocate a new response buffer and ANSCP and
|
||||||
|
+ ANSP will both point to the new buffer. If more than *ANSSIZP bytes
|
||||||
|
+ are needed but ANSCP is NULL, then as much of the response as
|
||||||
|
+ possible is read into the buffer, but the results will be truncated.
|
||||||
|
+ When truncation happens because of a small answer buffer the DNS
|
||||||
|
+ packets header feild TC will bet set to 1, indicating a truncated
|
||||||
|
+ message and the rest of the socket data will be read and discarded.
|
||||||
|
+
|
||||||
|
+ Answers to the query are stored secondly in *ANSP2 up to a max of
|
||||||
|
+ *ANSSIZP2 bytes, with the actual response length stored in
|
||||||
|
+ *RESPLEN2. If more than *ANSSIZP bytes are needed and ANSP2
|
||||||
|
+ is non-NULL (required for a second query) then malloc is used to
|
||||||
|
+ allocate a new response buffer, *ANSSIZP2 is set to the new buffer
|
||||||
|
+ size and *ANSP2_MALLOCED is set to 1.
|
||||||
|
+
|
||||||
|
+ The ANSP2_MALLOCED argument will eventually be removed as the
|
||||||
|
+ change in buffer pointer can be used to detect the buffer has
|
||||||
|
+ changed and that the caller should use free on the new buffer.
|
||||||
|
+
|
||||||
|
+ Note that the answers may arrive in any order from the server and
|
||||||
|
+ therefore the first and second answer buffers may not correspond to
|
||||||
|
+ the first and second queries.
|
||||||
|
+
|
||||||
|
+ It is not supported to call this function with a non-NULL ANSP2
|
||||||
|
+ but a NULL ANSCP. Put another way, you can call send_vc with a
|
||||||
|
+ single unmodifiable buffer or two modifiable buffers, but no other
|
||||||
|
+ combination is supported.
|
||||||
|
+
|
||||||
|
+ It is the caller's responsibility to free the malloc allocated
|
||||||
|
+ buffers by detecting that the pointers have changed from their
|
||||||
|
+ original values i.e. *ANSCP or *ANSP2 has changed.
|
||||||
|
+
|
||||||
|
+ If errors are encountered then *TERRNO is set to an appropriate
|
||||||
|
+ errno value and a zero result is returned for a recoverable error,
|
||||||
|
+ and a less-than zero result is returned for a non-recoverable error.
|
||||||
|
+
|
||||||
|
+ If no errors are encountered then *TERRNO is left unmodified and
|
||||||
|
+ a the length of the first response in bytes is returned. */
|
||||||
|
static int
|
||||||
|
send_vc(res_state statp,
|
||||||
|
const u_char *buf, int buflen, const u_char *buf2, int buflen2,
|
||||||
|
@@ -661,11 +751,7 @@
|
||||||
|
{
|
||||||
|
const HEADER *hp = (HEADER *) buf;
|
||||||
|
const HEADER *hp2 = (HEADER *) buf2;
|
||||||
|
- u_char *ans = *ansp;
|
||||||
|
- int orig_anssizp = *anssizp;
|
||||||
|
- // XXX REMOVE
|
||||||
|
- // int anssiz = *anssizp;
|
||||||
|
- HEADER *anhp = (HEADER *) ans;
|
||||||
|
+ HEADER *anhp = (HEADER *) *ansp;
|
||||||
|
struct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns];
|
||||||
|
int truncating, connreset, resplen, n;
|
||||||
|
struct iovec iov[4];
|
||||||
|
@@ -741,6 +827,8 @@
|
||||||
|
* Receive length & response
|
||||||
|
*/
|
||||||
|
int recvresp1 = 0;
|
||||||
|
+ /* Skip the second response if there is no second query.
|
||||||
|
+ To do that we mark the second response as received. */
|
||||||
|
int recvresp2 = buf2 == NULL;
|
||||||
|
uint16_t rlen16;
|
||||||
|
read_len:
|
||||||
|
@@ -777,33 +865,14 @@
|
||||||
|
u_char **thisansp;
|
||||||
|
int *thisresplenp;
|
||||||
|
if ((recvresp1 | recvresp2) == 0 || buf2 == NULL) {
|
||||||
|
+ /* We have not received any responses
|
||||||
|
+ yet or we only have one response to
|
||||||
|
+ receive. */
|
||||||
|
thisanssizp = anssizp;
|
||||||
|
thisansp = anscp ?: ansp;
|
||||||
|
assert (anscp != NULL || ansp2 == NULL);
|
||||||
|
thisresplenp = &resplen;
|
||||||
|
} else {
|
||||||
|
- if (*anssizp != MAXPACKET) {
|
||||||
|
- /* No buffer allocated for the first
|
||||||
|
- reply. We can try to use the rest
|
||||||
|
- of the user-provided buffer. */
|
||||||
|
-#ifdef _STRING_ARCH_unaligned
|
||||||
|
- *anssizp2 = orig_anssizp - resplen;
|
||||||
|
- *ansp2 = *ansp + resplen;
|
||||||
|
-#else
|
||||||
|
- int aligned_resplen
|
||||||
|
- = ((resplen + __alignof__ (HEADER) - 1)
|
||||||
|
- & ~(__alignof__ (HEADER) - 1));
|
||||||
|
- *anssizp2 = orig_anssizp - aligned_resplen;
|
||||||
|
- *ansp2 = *ansp + aligned_resplen;
|
||||||
|
-#endif
|
||||||
|
- } else {
|
||||||
|
- /* The first reply did not fit into the
|
||||||
|
- user-provided buffer. Maybe the second
|
||||||
|
- answer will. */
|
||||||
|
- *anssizp2 = orig_anssizp;
|
||||||
|
- *ansp2 = *ansp;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
thisanssizp = anssizp2;
|
||||||
|
thisansp = ansp2;
|
||||||
|
thisresplenp = resplen2;
|
||||||
|
@@ -811,10 +880,14 @@
|
||||||
|
anhp = (HEADER *) *thisansp;
|
||||||
|
|
||||||
|
*thisresplenp = rlen;
|
||||||
|
- if (rlen > *thisanssizp) {
|
||||||
|
- /* Yes, we test ANSCP here. If we have two buffers
|
||||||
|
- both will be allocatable. */
|
||||||
|
- if (__builtin_expect (anscp != NULL, 1)) {
|
||||||
|
+ /* Is the answer buffer too small? */
|
||||||
|
+ if (*thisanssizp < rlen) {
|
||||||
|
+ /* If the current buffer is non-NULL and it's not
|
||||||
|
+ pointing at the static user-supplied buffer then
|
||||||
|
+ we can reallocate it. */
|
||||||
|
+ if (thisansp != NULL && thisansp != ansp) {
|
||||||
|
+ /* Always allocate MAXPACKET, callers expect
|
||||||
|
+ this specific size. */
|
||||||
|
u_char *newp = malloc (MAXPACKET);
|
||||||
|
if (newp == NULL) {
|
||||||
|
*terrno = ENOMEM;
|
||||||
|
@@ -824,6 +897,9 @@
|
||||||
|
*thisanssizp = MAXPACKET;
|
||||||
|
*thisansp = newp;
|
||||||
|
anhp = (HEADER *) newp;
|
||||||
|
+ /* A uint16_t can't be larger than MAXPACKET
|
||||||
|
+ thus it's safe to allocate MAXPACKET but
|
||||||
|
+ read RLEN bytes instead. */
|
||||||
|
len = rlen;
|
||||||
|
} else {
|
||||||
|
Dprint(statp->options & RES_DEBUG,
|
||||||
|
@@ -987,6 +1063,66 @@
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
+/* The send_dg function is responsible for sending a DNS query over UDP
|
||||||
|
+ to the nameserver numbered NS from the res_state STATP i.e.
|
||||||
|
+ EXT(statp).nssocks[ns]. The function supports IPv4 and IPv6 queries
|
||||||
|
+ along with the ability to send the query in parallel for both stacks
|
||||||
|
+ (default) or serially (RES_SINGLKUP). It also supports serial lookup
|
||||||
|
+ with a close and reopen of the socket used to talk to the server
|
||||||
|
+ (RES_SNGLKUPREOP) to work around broken name servers.
|
||||||
|
+
|
||||||
|
+ The query stored in BUF of BUFLEN length is sent first followed by
|
||||||
|
+ the query stored in BUF2 of BUFLEN2 length. Queries are sent
|
||||||
|
+ in parallel (default) or serially (RES_SINGLKUP or RES_SNGLKUPREOP).
|
||||||
|
+
|
||||||
|
+ Answers to the query are stored firstly in *ANSP up to a max of
|
||||||
|
+ *ANSSIZP bytes. If more than *ANSSIZP bytes are needed and ANSCP
|
||||||
|
+ is non-NULL (to indicate that modifying the answer buffer is allowed)
|
||||||
|
+ then malloc is used to allocate a new response buffer and ANSCP and
|
||||||
|
+ ANSP will both point to the new buffer. If more than *ANSSIZP bytes
|
||||||
|
+ are needed but ANSCP is NULL, then as much of the response as
|
||||||
|
+ possible is read into the buffer, but the results will be truncated.
|
||||||
|
+ When truncation happens because of a small answer buffer the DNS
|
||||||
|
+ packets header feild TC will bet set to 1, indicating a truncated
|
||||||
|
+ message, while the rest of the UDP packet is discarded.
|
||||||
|
+
|
||||||
|
+ Answers to the query are stored secondly in *ANSP2 up to a max of
|
||||||
|
+ *ANSSIZP2 bytes, with the actual response length stored in
|
||||||
|
+ *RESPLEN2. If more than *ANSSIZP bytes are needed and ANSP2
|
||||||
|
+ is non-NULL (required for a second query) then malloc is used to
|
||||||
|
+ allocate a new response buffer, *ANSSIZP2 is set to the new buffer
|
||||||
|
+ size and *ANSP2_MALLOCED is set to 1.
|
||||||
|
+
|
||||||
|
+ The ANSP2_MALLOCED argument will eventually be removed as the
|
||||||
|
+ change in buffer pointer can be used to detect the buffer has
|
||||||
|
+ changed and that the caller should use free on the new buffer.
|
||||||
|
+
|
||||||
|
+ Note that the answers may arrive in any order from the server and
|
||||||
|
+ therefore the first and second answer buffers may not correspond to
|
||||||
|
+ the first and second queries.
|
||||||
|
+
|
||||||
|
+ It is not supported to call this function with a non-NULL ANSP2
|
||||||
|
+ but a NULL ANSCP. Put another way, you can call send_vc with a
|
||||||
|
+ single unmodifiable buffer or two modifiable buffers, but no other
|
||||||
|
+ combination is supported.
|
||||||
|
+
|
||||||
|
+ It is the caller's responsibility to free the malloc allocated
|
||||||
|
+ buffers by detecting that the pointers have changed from their
|
||||||
|
+ original values i.e. *ANSCP or *ANSP2 has changed.
|
||||||
|
+
|
||||||
|
+ If an answer is truncated because of UDP datagram DNS limits then
|
||||||
|
+ *V_CIRCUIT is set to 1 and the return value non-zero to indicate to
|
||||||
|
+ the caller to retry with TCP. The value *GOTSOMEWHERE is set to 1
|
||||||
|
+ if any progress was made reading a response from the nameserver and
|
||||||
|
+ is used by the caller to distinguish between ECONNREFUSED and
|
||||||
|
+ ETIMEDOUT (the latter if *GOTSOMEWHERE is 1).
|
||||||
|
+
|
||||||
|
+ If errors are encountered then *TERRNO is set to an appropriate
|
||||||
|
+ errno value and a zero result is returned for a recoverable error,
|
||||||
|
+ and a less-than zero result is returned for a non-recoverable error.
|
||||||
|
+
|
||||||
|
+ If no errors are encountered then *TERRNO is left unmodified and
|
||||||
|
+ a the length of the first response in bytes is returned. */
|
||||||
|
static int
|
||||||
|
send_dg(res_state statp,
|
||||||
|
const u_char *buf, int buflen, const u_char *buf2, int buflen2,
|
||||||
|
@@ -996,8 +1132,6 @@
|
||||||
|
{
|
||||||
|
const HEADER *hp = (HEADER *) buf;
|
||||||
|
const HEADER *hp2 = (HEADER *) buf2;
|
||||||
|
- u_char *ans = *ansp;
|
||||||
|
- int orig_anssizp = *anssizp;
|
||||||
|
struct timespec now, timeout, finish;
|
||||||
|
struct pollfd pfd[1];
|
||||||
|
int ptimeout;
|
||||||
|
@@ -1030,6 +1164,8 @@
|
||||||
|
int need_recompute = 0;
|
||||||
|
int nwritten = 0;
|
||||||
|
int recvresp1 = 0;
|
||||||
|
+ /* Skip the second response if there is no second query.
|
||||||
|
+ To do that we mark the second response as received. */
|
||||||
|
int recvresp2 = buf2 == NULL;
|
||||||
|
pfd[0].fd = EXT(statp).nssocks[ns];
|
||||||
|
pfd[0].events = POLLOUT;
|
||||||
|
@@ -1193,53 +1329,54 @@
|
||||||
|
int *thisresplenp;
|
||||||
|
|
||||||
|
if ((recvresp1 | recvresp2) == 0 || buf2 == NULL) {
|
||||||
|
+ /* We have not received any responses
|
||||||
|
+ yet or we only have one response to
|
||||||
|
+ receive. */
|
||||||
|
thisanssizp = anssizp;
|
||||||
|
thisansp = anscp ?: ansp;
|
||||||
|
assert (anscp != NULL || ansp2 == NULL);
|
||||||
|
thisresplenp = &resplen;
|
||||||
|
} else {
|
||||||
|
- if (*anssizp != MAXPACKET) {
|
||||||
|
- /* No buffer allocated for the first
|
||||||
|
- reply. We can try to use the rest
|
||||||
|
- of the user-provided buffer. */
|
||||||
|
-#ifdef _STRING_ARCH_unaligned
|
||||||
|
- *anssizp2 = orig_anssizp - resplen;
|
||||||
|
- *ansp2 = *ansp + resplen;
|
||||||
|
-#else
|
||||||
|
- int aligned_resplen
|
||||||
|
- = ((resplen + __alignof__ (HEADER) - 1)
|
||||||
|
- & ~(__alignof__ (HEADER) - 1));
|
||||||
|
- *anssizp2 = orig_anssizp - aligned_resplen;
|
||||||
|
- *ansp2 = *ansp + aligned_resplen;
|
||||||
|
-#endif
|
||||||
|
- } else {
|
||||||
|
- /* The first reply did not fit into the
|
||||||
|
- user-provided buffer. Maybe the second
|
||||||
|
- answer will. */
|
||||||
|
- *anssizp2 = orig_anssizp;
|
||||||
|
- *ansp2 = *ansp;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
thisanssizp = anssizp2;
|
||||||
|
thisansp = ansp2;
|
||||||
|
thisresplenp = resplen2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*thisanssizp < MAXPACKET
|
||||||
|
- /* Yes, we test ANSCP here. If we have two buffers
|
||||||
|
- both will be allocatable. */
|
||||||
|
- && anscp
|
||||||
|
+ /* If the current buffer is non-NULL and it's not
|
||||||
|
+ pointing at the static user-supplied buffer then
|
||||||
|
+ we can reallocate it. */
|
||||||
|
+ && (thisansp != NULL && thisansp != ansp)
|
||||||
|
+ /* Is the size too small? */
|
||||||
|
#ifdef FIONREAD
|
||||||
|
&& (ioctl (pfd[0].fd, FIONREAD, thisresplenp) < 0
|
||||||
|
|| *thisanssizp < *thisresplenp)
|
||||||
|
#endif
|
||||||
|
) {
|
||||||
|
+ /* Always allocate MAXPACKET, callers expect
|
||||||
|
+ this specific size. */
|
||||||
|
u_char *newp = malloc (MAXPACKET);
|
||||||
|
if (newp != NULL) {
|
||||||
|
- *anssizp = MAXPACKET;
|
||||||
|
- *thisansp = ans = newp;
|
||||||
|
+ *thisanssizp = MAXPACKET;
|
||||||
|
+ *thisansp = newp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
+ /* We could end up with truncation if anscp was NULL
|
||||||
|
+ (not allowed to change caller's buffer) and the
|
||||||
|
+ response buffer size is too small. This isn't a
|
||||||
|
+ reliable way to detect truncation because the ioctl
|
||||||
|
+ may be an inaccurate report of the UDP message size.
|
||||||
|
+ Therefore we use this only to issue debug output.
|
||||||
|
+ To do truncation accurately with UDP we need
|
||||||
|
+ MSG_TRUNC which is only available on Linux. We
|
||||||
|
+ can abstract out the Linux-specific feature in the
|
||||||
|
+ future to detect truncation. */
|
||||||
|
+ if (__glibc_unlikely (*thisanssizp < *thisresplenp)) {
|
||||||
|
+ Dprint(statp->options & RES_DEBUG,
|
||||||
|
+ (stdout, ";; response may be truncated (UDP)\n")
|
||||||
|
+ );
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
HEADER *anhp = (HEADER *) *thisansp;
|
||||||
|
socklen_t fromlen = sizeof(struct sockaddr_in6);
|
||||||
|
assert (sizeof(from) <= fromlen);
|
13
glibc.spec
13
glibc.spec
|
@ -57,7 +57,7 @@ Summary: The GNU libc libraries
|
||||||
Name: glibc
|
Name: glibc
|
||||||
Epoch: 6
|
Epoch: 6
|
||||||
Version: 2.19
|
Version: 2.19
|
||||||
Release: 21
|
Release: 22
|
||||||
License: LGPLv2+ and LGPLv2+ with exceptions and GPLv2+
|
License: LGPLv2+ and LGPLv2+ with exceptions and GPLv2+
|
||||||
Group: System/Libraries
|
Group: System/Libraries
|
||||||
Url: http://www.eglibc.org/
|
Url: http://www.eglibc.org/
|
||||||
|
@ -163,6 +163,11 @@ Patch54: glibc-rh819430.patch
|
||||||
Patch55: glibc-rh911307.patch
|
Patch55: glibc-rh911307.patch
|
||||||
Patch51: glibc-rh952799.patch
|
Patch51: glibc-rh952799.patch
|
||||||
|
|
||||||
|
Patch501: glibc-rh1170118-CVE-2014-7817.patch
|
||||||
|
Patch502: glibc-rh1194143.patch
|
||||||
|
Patch503: glibc-rh1199525.patch
|
||||||
|
Patch504: glibc-rh1296031.patch
|
||||||
|
|
||||||
#-----------------------------------------------------------------------
|
#-----------------------------------------------------------------------
|
||||||
# mandriva patches
|
# mandriva patches
|
||||||
Patch56: eglibc-mandriva-localedef-archive-follow-symlinks.patch
|
Patch56: eglibc-mandriva-localedef-archive-follow-symlinks.patch
|
||||||
|
@ -853,6 +858,12 @@ their ~/.profile configuration file.
|
||||||
%patch79 -p1
|
%patch79 -p1
|
||||||
%patch80 -p1
|
%patch80 -p1
|
||||||
|
|
||||||
|
%patch501 -p1
|
||||||
|
%patch502 -p1
|
||||||
|
%patch503 -p1
|
||||||
|
%patch504 -p1
|
||||||
|
|
||||||
|
|
||||||
# copy freesec source
|
# copy freesec source
|
||||||
cp %{SOURCE52} %{SOURCE53} crypt/
|
cp %{SOURCE52} %{SOURCE53} crypt/
|
||||||
echo "Applying crypt_blowfish patch:"
|
echo "Applying crypt_blowfish patch:"
|
||||||
|
|
Loading…
Add table
Reference in a new issue