mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-11-07 07:26:13 -05:00
gnu: glibc: Fix replacement on i686.
This is followup to 665d6a5916
.
Fixes <https://bugs.gnu.org/27489>.
* gnu/packages/base.scm (glibc-2.25-patched, glibc-2.24, glibc-2.23)
(glibc-2.22): Add glibc-vectorized-strcspn-guards.patch to patches.
Move a comment where it belongs.
* gnu/packages/patches/glibc-CVE-2017-1000366-pt2.patch: Swap with ...
* gnu/packages/patches/glibc-CVE-2017-1000366-pt3.patch: ... this.
* gnu/packages/patches/glibc-vectorized-strcspn-guards.patch: New file.
* gnu/local.mk (dist_patch_DATA): Add it. Fix formatting.
This commit is contained in:
parent
afc9d8ec2b
commit
ffc015bea2
5 changed files with 311 additions and 283 deletions
|
@ -630,14 +630,15 @@ dist_patch_DATA = \
|
||||||
%D%/packages/patches/ghostscript-runpath.patch \
|
%D%/packages/patches/ghostscript-runpath.patch \
|
||||||
%D%/packages/patches/glib-networking-ssl-cert-file.patch \
|
%D%/packages/patches/glib-networking-ssl-cert-file.patch \
|
||||||
%D%/packages/patches/glib-tests-timer.patch \
|
%D%/packages/patches/glib-tests-timer.patch \
|
||||||
%D%/packages/patches/glibc-CVE-2017-1000366-pt1.patch \
|
%D%/packages/patches/glibc-CVE-2017-1000366-pt1.patch \
|
||||||
%D%/packages/patches/glibc-CVE-2017-1000366-pt2.patch \
|
%D%/packages/patches/glibc-CVE-2017-1000366-pt2.patch \
|
||||||
%D%/packages/patches/glibc-CVE-2017-1000366-pt3.patch \
|
%D%/packages/patches/glibc-CVE-2017-1000366-pt3.patch \
|
||||||
%D%/packages/patches/glibc-bootstrap-system.patch \
|
%D%/packages/patches/glibc-bootstrap-system.patch \
|
||||||
%D%/packages/patches/glibc-ldd-x86_64.patch \
|
%D%/packages/patches/glibc-ldd-x86_64.patch \
|
||||||
%D%/packages/patches/glibc-locales.patch \
|
%D%/packages/patches/glibc-locales.patch \
|
||||||
%D%/packages/patches/glibc-memchr-overflow-i686.patch \
|
%D%/packages/patches/glibc-memchr-overflow-i686.patch \
|
||||||
%D%/packages/patches/glibc-o-largefile.patch \
|
%D%/packages/patches/glibc-o-largefile.patch \
|
||||||
|
%D%/packages/patches/glibc-vectorized-strcspn-guards.patch \
|
||||||
%D%/packages/patches/glibc-versioned-locpath.patch \
|
%D%/packages/patches/glibc-versioned-locpath.patch \
|
||||||
%D%/packages/patches/glog-gcc-5-demangling.patch \
|
%D%/packages/patches/glog-gcc-5-demangling.patch \
|
||||||
%D%/packages/patches/gmp-arm-asm-nothumb.patch \
|
%D%/packages/patches/gmp-arm-asm-nothumb.patch \
|
||||||
|
|
|
@ -902,9 +902,6 @@ (define* (glibc-for-target #:optional
|
||||||
(define-syntax glibc
|
(define-syntax glibc
|
||||||
(identifier-syntax (glibc-for-target)))
|
(identifier-syntax (glibc-for-target)))
|
||||||
|
|
||||||
;; Below are old libc versions, which we use mostly to build locale data in
|
|
||||||
;; the old format (which the new libc cannot cope with.)
|
|
||||||
|
|
||||||
(define glibc-2.25-patched
|
(define glibc-2.25-patched
|
||||||
(package
|
(package
|
||||||
(inherit glibc)
|
(inherit glibc)
|
||||||
|
@ -914,10 +911,14 @@ (define glibc-2.25-patched
|
||||||
(patches (search-patches "glibc-ldd-x86_64.patch"
|
(patches (search-patches "glibc-ldd-x86_64.patch"
|
||||||
"glibc-versioned-locpath.patch"
|
"glibc-versioned-locpath.patch"
|
||||||
"glibc-o-largefile.patch"
|
"glibc-o-largefile.patch"
|
||||||
|
"glibc-vectorized-strcspn-guards.patch"
|
||||||
"glibc-CVE-2017-1000366-pt1.patch"
|
"glibc-CVE-2017-1000366-pt1.patch"
|
||||||
"glibc-CVE-2017-1000366-pt2.patch"
|
"glibc-CVE-2017-1000366-pt2.patch"
|
||||||
"glibc-CVE-2017-1000366-pt3.patch"))))))
|
"glibc-CVE-2017-1000366-pt3.patch"))))))
|
||||||
|
|
||||||
|
;; Below are old libc versions, which we use mostly to build locale data in
|
||||||
|
;; the old format (which the new libc cannot cope with.)
|
||||||
|
|
||||||
(define-public glibc-2.24
|
(define-public glibc-2.24
|
||||||
(package
|
(package
|
||||||
(inherit glibc)
|
(inherit glibc)
|
||||||
|
@ -933,6 +934,7 @@ (define-public glibc-2.24
|
||||||
(patches (search-patches "glibc-ldd-x86_64.patch"
|
(patches (search-patches "glibc-ldd-x86_64.patch"
|
||||||
"glibc-versioned-locpath.patch"
|
"glibc-versioned-locpath.patch"
|
||||||
"glibc-o-largefile.patch"
|
"glibc-o-largefile.patch"
|
||||||
|
"glibc-vectorized-strcspn-guards.patch"
|
||||||
"glibc-CVE-2017-1000366-pt1.patch"
|
"glibc-CVE-2017-1000366-pt1.patch"
|
||||||
"glibc-CVE-2017-1000366-pt2.patch"
|
"glibc-CVE-2017-1000366-pt2.patch"
|
||||||
"glibc-CVE-2017-1000366-pt3.patch"))))))
|
"glibc-CVE-2017-1000366-pt3.patch"))))))
|
||||||
|
@ -952,6 +954,7 @@ (define-public glibc-2.23
|
||||||
(patches (search-patches "glibc-ldd-x86_64.patch"
|
(patches (search-patches "glibc-ldd-x86_64.patch"
|
||||||
"glibc-versioned-locpath.patch"
|
"glibc-versioned-locpath.patch"
|
||||||
"glibc-o-largefile.patch"
|
"glibc-o-largefile.patch"
|
||||||
|
"glibc-vectorized-strcspn-guards.patch"
|
||||||
"glibc-CVE-2017-1000366-pt1.patch"
|
"glibc-CVE-2017-1000366-pt1.patch"
|
||||||
"glibc-CVE-2017-1000366-pt2.patch"
|
"glibc-CVE-2017-1000366-pt2.patch"
|
||||||
"glibc-CVE-2017-1000366-pt3.patch"))))))
|
"glibc-CVE-2017-1000366-pt3.patch"))))))
|
||||||
|
@ -969,6 +972,7 @@ (define-public glibc-2.22
|
||||||
(base32
|
(base32
|
||||||
"0j49682pm2nh4qbdw35bas82p1pgfnz4d2l7iwfyzvrvj0318wzb"))
|
"0j49682pm2nh4qbdw35bas82p1pgfnz4d2l7iwfyzvrvj0318wzb"))
|
||||||
(patches (search-patches "glibc-ldd-x86_64.patch"
|
(patches (search-patches "glibc-ldd-x86_64.patch"
|
||||||
|
"glibc-vectorized-strcspn-guards.patch"
|
||||||
"glibc-CVE-2017-1000366-pt1.patch"
|
"glibc-CVE-2017-1000366-pt1.patch"
|
||||||
"glibc-CVE-2017-1000366-pt2.patch"
|
"glibc-CVE-2017-1000366-pt2.patch"
|
||||||
"glibc-CVE-2017-1000366-pt3.patch"))))
|
"glibc-CVE-2017-1000366-pt3.patch"))))
|
||||||
|
|
|
@ -1,206 +1,124 @@
|
||||||
From 81b82fb966ffbd94353f793ad17116c6088dedd9 Mon Sep 17 00:00:00 2001
|
From 6d0ba622891bed9d8394eef1935add53003b12e8 Mon Sep 17 00:00:00 2001
|
||||||
From: Florian Weimer <fweimer@redhat.com>
|
From: Florian Weimer <fweimer@redhat.com>
|
||||||
Date: Mon, 19 Jun 2017 22:32:12 +0200
|
Date: Mon, 19 Jun 2017 22:31:04 +0200
|
||||||
Subject: [PATCH] ld.so: Reject overly long LD_AUDIT path elements
|
Subject: [PATCH] ld.so: Reject overly long LD_PRELOAD path elements
|
||||||
|
|
||||||
Also only process the last LD_AUDIT entry.
|
|
||||||
|
|
||||||
patch from:
|
patch from:
|
||||||
https://sourceware.org/git/?p=glibc.git;a=commit;h=81b82fb966ffbd94353f793ad17116c6088dedd9
|
https://sourceware.org/git/?p=glibc.git;a=patch;h=6d0ba622891bed9d8394eef1935add53003b12e8
|
||||||
|
|
||||||
---
|
---
|
||||||
ChangeLog | 11 +++++++
|
ChangeLog | 7 ++++++
|
||||||
elf/rtld.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------
|
elf/rtld.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++------------
|
||||||
2 files changed, 106 insertions(+), 15 deletions(-)
|
2 files changed, 73 insertions(+), 16 deletions(-)
|
||||||
|
|
||||||
diff --git a/elf/rtld.c b/elf/rtld.c
|
diff --git a/elf/rtld.c b/elf/rtld.c
|
||||||
index 86ae20c..65647fb 100644
|
index 2269dbe..86ae20c 100644
|
||||||
--- a/elf/rtld.c
|
--- a/elf/rtld.c
|
||||||
+++ b/elf/rtld.c
|
+++ b/elf/rtld.c
|
||||||
@@ -129,13 +129,91 @@ dso_name_valid_for_suid (const char *p)
|
@@ -99,6 +99,35 @@ uintptr_t __pointer_chk_guard_local
|
||||||
return *p != '\0';
|
strong_alias (__pointer_chk_guard_local, __pointer_chk_guard)
|
||||||
}
|
#endif
|
||||||
|
|
||||||
-/* List of auditing DSOs. */
|
+/* Length limits for names and paths, to protect the dynamic linker,
|
||||||
+/* LD_AUDIT variable contents. Must be processed before the
|
+ particularly when __libc_enable_secure is active. */
|
||||||
+ audit_list below. */
|
+#ifdef NAME_MAX
|
||||||
+const char *audit_list_string;
|
+# define SECURE_NAME_LIMIT NAME_MAX
|
||||||
|
+#else
|
||||||
|
+# define SECURE_NAME_LIMIT 255
|
||||||
|
+#endif
|
||||||
|
+#ifdef PATH_MAX
|
||||||
|
+# define SECURE_PATH_LIMIT PATH_MAX
|
||||||
|
+#else
|
||||||
|
+# define SECURE_PATH_LIMIT 1024
|
||||||
|
+#endif
|
||||||
+
|
+
|
||||||
+/* Cyclic list of auditing DSOs. audit_list->next is the first
|
+/* Check that AT_SECURE=0, or that the passed name does not contain
|
||||||
+ element. */
|
+ directories and is not overly long. Reject empty names
|
||||||
|
+ unconditionally. */
|
||||||
|
+static bool
|
||||||
|
+dso_name_valid_for_suid (const char *p)
|
||||||
|
+{
|
||||||
|
+ if (__glibc_unlikely (__libc_enable_secure))
|
||||||
|
+ {
|
||||||
|
+ /* Ignore pathnames with directories for AT_SECURE=1
|
||||||
|
+ programs, and also skip overlong names. */
|
||||||
|
+ size_t len = strlen (p);
|
||||||
|
+ if (len >= SECURE_NAME_LIMIT || memchr (p, '/', len) != NULL)
|
||||||
|
+ return false;
|
||||||
|
+ }
|
||||||
|
+ return *p != '\0';
|
||||||
|
+}
|
||||||
|
|
||||||
|
/* List of auditing DSOs. */
|
||||||
static struct audit_list
|
static struct audit_list
|
||||||
{
|
@@ -718,6 +747,42 @@ static const char *preloadlist attribute_relro;
|
||||||
const char *name;
|
/* Nonzero if information about versions has to be printed. */
|
||||||
struct audit_list *next;
|
static int version_info attribute_relro;
|
||||||
} *audit_list;
|
|
||||||
|
|
||||||
+/* Iterator for audit_list_string followed by audit_list. */
|
+/* The LD_PRELOAD environment variable gives list of libraries
|
||||||
+struct audit_list_iter
|
+ separated by white space or colons that are loaded before the
|
||||||
|
+ executable's dependencies and prepended to the global scope list.
|
||||||
|
+ (If the binary is running setuid all elements containing a '/' are
|
||||||
|
+ ignored since it is insecure.) Return the number of preloads
|
||||||
|
+ performed. */
|
||||||
|
+unsigned int
|
||||||
|
+handle_ld_preload (const char *preloadlist, struct link_map *main_map)
|
||||||
+{
|
+{
|
||||||
+ /* Tail of audit_list_string still needing processing, or NULL. */
|
+ unsigned int npreloads = 0;
|
||||||
+ const char *audit_list_tail;
|
+ const char *p = preloadlist;
|
||||||
|
+ char fname[SECURE_PATH_LIMIT];
|
||||||
+
|
+
|
||||||
+ /* The list element returned in the previous iteration. NULL before
|
+ while (*p != '\0')
|
||||||
+ the first element. */
|
|
||||||
+ struct audit_list *previous;
|
|
||||||
+
|
|
||||||
+ /* Scratch buffer for returning a name which is part of
|
|
||||||
+ audit_list_string. */
|
|
||||||
+ char fname[SECURE_NAME_LIMIT];
|
|
||||||
+};
|
|
||||||
+
|
|
||||||
+/* Initialize an audit list iterator. */
|
|
||||||
+static void
|
|
||||||
+audit_list_iter_init (struct audit_list_iter *iter)
|
|
||||||
+{
|
|
||||||
+ iter->audit_list_tail = audit_list_string;
|
|
||||||
+ iter->previous = NULL;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+/* Iterate through both audit_list_string and audit_list. */
|
|
||||||
+static const char *
|
|
||||||
+audit_list_iter_next (struct audit_list_iter *iter)
|
|
||||||
+{
|
|
||||||
+ if (iter->audit_list_tail != NULL)
|
|
||||||
+ {
|
+ {
|
||||||
+ /* First iterate over audit_list_string. */
|
+ /* Split preload list at space/colon. */
|
||||||
+ while (*iter->audit_list_tail != '\0')
|
+ size_t len = strcspn (p, " :");
|
||||||
|
+ if (len > 0 && len < sizeof (fname))
|
||||||
+ {
|
+ {
|
||||||
+ /* Split audit list at colon. */
|
+ memcpy (fname, p, len);
|
||||||
+ size_t len = strcspn (iter->audit_list_tail, ":");
|
+ fname[len] = '\0';
|
||||||
+ if (len > 0 && len < sizeof (iter->fname))
|
|
||||||
+ {
|
|
||||||
+ memcpy (iter->fname, iter->audit_list_tail, len);
|
|
||||||
+ iter->fname[len] = '\0';
|
|
||||||
+ }
|
|
||||||
+ else
|
|
||||||
+ /* Do not return this name to the caller. */
|
|
||||||
+ iter->fname[0] = '\0';
|
|
||||||
+
|
|
||||||
+ /* Skip over the substring and the following delimiter. */
|
|
||||||
+ iter->audit_list_tail += len;
|
|
||||||
+ if (*iter->audit_list_tail == ':')
|
|
||||||
+ ++iter->audit_list_tail;
|
|
||||||
+
|
|
||||||
+ /* If the name is valid, return it. */
|
|
||||||
+ if (dso_name_valid_for_suid (iter->fname))
|
|
||||||
+ return iter->fname;
|
|
||||||
+ /* Otherwise, wrap around and try the next name. */
|
|
||||||
+ }
|
+ }
|
||||||
+ /* Fall through to the procesing of audit_list. */
|
+ else
|
||||||
+ }
|
+ fname[0] = '\0';
|
||||||
+
|
+
|
||||||
+ if (iter->previous == NULL)
|
+ /* Skip over the substring and the following delimiter. */
|
||||||
+ {
|
+ p += len;
|
||||||
+ if (audit_list == NULL)
|
+ if (*p != '\0')
|
||||||
+ /* No pre-parsed audit list. */
|
+ ++p;
|
||||||
+ return NULL;
|
+
|
||||||
+ /* Start of audit list. The first list element is at
|
+ if (dso_name_valid_for_suid (fname))
|
||||||
+ audit_list->next (cyclic list). */
|
+ npreloads += do_preload (fname, main_map, "LD_PRELOAD");
|
||||||
+ iter->previous = audit_list->next;
|
|
||||||
+ return iter->previous->name;
|
|
||||||
+ }
|
+ }
|
||||||
+ if (iter->previous == audit_list)
|
+ return npreloads;
|
||||||
+ /* Cyclic list wrap-around. */
|
|
||||||
+ return NULL;
|
|
||||||
+ iter->previous = iter->previous->next;
|
|
||||||
+ return iter->previous->name;
|
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
#ifndef HAVE_INLINED_SYSCALLS
|
static void
|
||||||
/* Set nonzero during loading and initialization of executable and
|
dl_main (const ElfW(Phdr) *phdr,
|
||||||
libraries, cleared before the executable's entry point runs. This
|
ElfW(Word) phnum,
|
||||||
@@ -1305,11 +1383,13 @@ of this helper program; chances are you did not intend to run this program.\n\
|
@@ -1464,23 +1529,8 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
|
||||||
GL(dl_rtld_map).l_tls_modid = _dl_next_tls_modid ();
|
|
||||||
|
|
||||||
/* If we have auditing DSOs to load, do it now. */
|
if (__glibc_unlikely (preloadlist != NULL))
|
||||||
- if (__glibc_unlikely (audit_list != NULL))
|
|
||||||
+ bool need_security_init = true;
|
|
||||||
+ if (__glibc_unlikely (audit_list != NULL)
|
|
||||||
+ || __glibc_unlikely (audit_list_string != NULL))
|
|
||||||
{
|
{
|
||||||
- /* Iterate over all entries in the list. The order is important. */
|
- /* The LD_PRELOAD environment variable gives list of libraries
|
||||||
struct audit_ifaces *last_audit = NULL;
|
- separated by white space or colons that are loaded before the
|
||||||
- struct audit_list *al = audit_list->next;
|
- executable's dependencies and prepended to the global scope
|
||||||
+ struct audit_list_iter al_iter;
|
- list. If the binary is running setuid all elements
|
||||||
+ audit_list_iter_init (&al_iter);
|
- containing a '/' are ignored since it is insecure. */
|
||||||
|
- char *list = strdupa (preloadlist);
|
||||||
/* Since we start using the auditing DSOs right away we need to
|
- char *p;
|
||||||
initialize the data structures now. */
|
|
||||||
@@ -1320,9 +1400,14 @@ of this helper program; chances are you did not intend to run this program.\n\
|
|
||||||
use different values (especially the pointer guard) and will
|
|
||||||
fail later on. */
|
|
||||||
security_init ();
|
|
||||||
+ need_security_init = false;
|
|
||||||
|
|
||||||
- do
|
|
||||||
+ while (true)
|
|
||||||
{
|
|
||||||
+ const char *name = audit_list_iter_next (&al_iter);
|
|
||||||
+ if (name == NULL)
|
|
||||||
+ break;
|
|
||||||
+
|
|
||||||
int tls_idx = GL(dl_tls_max_dtv_idx);
|
|
||||||
|
|
||||||
/* Now it is time to determine the layout of the static TLS
|
|
||||||
@@ -1331,7 +1416,7 @@ of this helper program; chances are you did not intend to run this program.\n\
|
|
||||||
no DF_STATIC_TLS bit is set. The reason is that we know
|
|
||||||
glibc will use the static model. */
|
|
||||||
struct dlmopen_args dlmargs;
|
|
||||||
- dlmargs.fname = al->name;
|
|
||||||
+ dlmargs.fname = name;
|
|
||||||
dlmargs.map = NULL;
|
|
||||||
|
|
||||||
const char *objname;
|
|
||||||
@@ -1344,7 +1429,7 @@ of this helper program; chances are you did not intend to run this program.\n\
|
|
||||||
not_loaded:
|
|
||||||
_dl_error_printf ("\
|
|
||||||
ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
|
|
||||||
- al->name, err_str);
|
|
||||||
+ name, err_str);
|
|
||||||
if (malloced)
|
|
||||||
free ((char *) err_str);
|
|
||||||
}
|
|
||||||
@@ -1448,10 +1533,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
|
|
||||||
goto not_loaded;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-
|
-
|
||||||
- al = al->next;
|
HP_TIMING_NOW (start);
|
||||||
}
|
-
|
||||||
- while (al != audit_list->next);
|
- /* Prevent optimizing strsep. Speed is not important here. */
|
||||||
|
- while ((p = (strsep) (&list, " :")) != NULL)
|
||||||
/* If we have any auditing modules, announce that we already
|
- if (p[0] != '\0'
|
||||||
have two objects loaded. */
|
- && (__builtin_expect (! __libc_enable_secure, 1)
|
||||||
@@ -1715,7 +1797,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
|
- || strchr (p, '/') == NULL))
|
||||||
if (tcbp == NULL)
|
- npreloads += do_preload (p, main_map, "LD_PRELOAD");
|
||||||
tcbp = init_tls ();
|
-
|
||||||
|
+ npreloads += handle_ld_preload (preloadlist, main_map);
|
||||||
- if (__glibc_likely (audit_list == NULL))
|
HP_TIMING_NOW (stop);
|
||||||
+ if (__glibc_likely (need_security_init))
|
HP_TIMING_DIFF (diff, start, stop);
|
||||||
/* Initialize security features. But only if we have not done it
|
HP_TIMING_ACCUM_NT (load_time, diff);
|
||||||
earlier. */
|
|
||||||
security_init ();
|
|
||||||
@@ -2346,9 +2428,7 @@ process_dl_audit (char *str)
|
|
||||||
char *p;
|
|
||||||
|
|
||||||
while ((p = (strsep) (&str, ":")) != NULL)
|
|
||||||
- if (p[0] != '\0'
|
|
||||||
- && (__builtin_expect (! __libc_enable_secure, 1)
|
|
||||||
- || strchr (p, '/') == NULL))
|
|
||||||
+ if (dso_name_valid_for_suid (p))
|
|
||||||
{
|
|
||||||
/* This is using the local malloc, not the system malloc. The
|
|
||||||
memory can never be freed. */
|
|
||||||
@@ -2412,7 +2492,7 @@ process_envvars (enum mode *modep)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (memcmp (envline, "AUDIT", 5) == 0)
|
|
||||||
- process_dl_audit (&envline[6]);
|
|
||||||
+ audit_list_string = &envline[6];
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 7:
|
|
||||||
--
|
--
|
||||||
2.9.3
|
2.9.3
|
||||||
|
|
||||||
|
|
|
@ -1,124 +1,206 @@
|
||||||
From 6d0ba622891bed9d8394eef1935add53003b12e8 Mon Sep 17 00:00:00 2001
|
From 81b82fb966ffbd94353f793ad17116c6088dedd9 Mon Sep 17 00:00:00 2001
|
||||||
From: Florian Weimer <fweimer@redhat.com>
|
From: Florian Weimer <fweimer@redhat.com>
|
||||||
Date: Mon, 19 Jun 2017 22:31:04 +0200
|
Date: Mon, 19 Jun 2017 22:32:12 +0200
|
||||||
Subject: [PATCH] ld.so: Reject overly long LD_PRELOAD path elements
|
Subject: [PATCH] ld.so: Reject overly long LD_AUDIT path elements
|
||||||
|
|
||||||
|
Also only process the last LD_AUDIT entry.
|
||||||
|
|
||||||
patch from:
|
patch from:
|
||||||
https://sourceware.org/git/?p=glibc.git;a=patch;h=6d0ba622891bed9d8394eef1935add53003b12e8
|
https://sourceware.org/git/?p=glibc.git;a=commit;h=81b82fb966ffbd94353f793ad17116c6088dedd9
|
||||||
|
|
||||||
---
|
---
|
||||||
ChangeLog | 7 ++++++
|
ChangeLog | 11 +++++++
|
||||||
elf/rtld.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++------------
|
elf/rtld.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------
|
||||||
2 files changed, 73 insertions(+), 16 deletions(-)
|
2 files changed, 106 insertions(+), 15 deletions(-)
|
||||||
|
|
||||||
diff --git a/elf/rtld.c b/elf/rtld.c
|
diff --git a/elf/rtld.c b/elf/rtld.c
|
||||||
index 2269dbe..86ae20c 100644
|
index 86ae20c..65647fb 100644
|
||||||
--- a/elf/rtld.c
|
--- a/elf/rtld.c
|
||||||
+++ b/elf/rtld.c
|
+++ b/elf/rtld.c
|
||||||
@@ -99,6 +99,35 @@ uintptr_t __pointer_chk_guard_local
|
@@ -129,13 +129,91 @@ dso_name_valid_for_suid (const char *p)
|
||||||
strong_alias (__pointer_chk_guard_local, __pointer_chk_guard)
|
return *p != '\0';
|
||||||
#endif
|
}
|
||||||
|
|
||||||
+/* Length limits for names and paths, to protect the dynamic linker,
|
-/* List of auditing DSOs. */
|
||||||
+ particularly when __libc_enable_secure is active. */
|
+/* LD_AUDIT variable contents. Must be processed before the
|
||||||
+#ifdef NAME_MAX
|
+ audit_list below. */
|
||||||
+# define SECURE_NAME_LIMIT NAME_MAX
|
+const char *audit_list_string;
|
||||||
+#else
|
|
||||||
+# define SECURE_NAME_LIMIT 255
|
|
||||||
+#endif
|
|
||||||
+#ifdef PATH_MAX
|
|
||||||
+# define SECURE_PATH_LIMIT PATH_MAX
|
|
||||||
+#else
|
|
||||||
+# define SECURE_PATH_LIMIT 1024
|
|
||||||
+#endif
|
|
||||||
+
|
+
|
||||||
+/* Check that AT_SECURE=0, or that the passed name does not contain
|
+/* Cyclic list of auditing DSOs. audit_list->next is the first
|
||||||
+ directories and is not overly long. Reject empty names
|
+ element. */
|
||||||
+ unconditionally. */
|
|
||||||
+static bool
|
|
||||||
+dso_name_valid_for_suid (const char *p)
|
|
||||||
+{
|
|
||||||
+ if (__glibc_unlikely (__libc_enable_secure))
|
|
||||||
+ {
|
|
||||||
+ /* Ignore pathnames with directories for AT_SECURE=1
|
|
||||||
+ programs, and also skip overlong names. */
|
|
||||||
+ size_t len = strlen (p);
|
|
||||||
+ if (len >= SECURE_NAME_LIMIT || memchr (p, '/', len) != NULL)
|
|
||||||
+ return false;
|
|
||||||
+ }
|
|
||||||
+ return *p != '\0';
|
|
||||||
+}
|
|
||||||
|
|
||||||
/* List of auditing DSOs. */
|
|
||||||
static struct audit_list
|
static struct audit_list
|
||||||
@@ -718,6 +747,42 @@ static const char *preloadlist attribute_relro;
|
{
|
||||||
/* Nonzero if information about versions has to be printed. */
|
const char *name;
|
||||||
static int version_info attribute_relro;
|
struct audit_list *next;
|
||||||
|
} *audit_list;
|
||||||
|
|
||||||
+/* The LD_PRELOAD environment variable gives list of libraries
|
+/* Iterator for audit_list_string followed by audit_list. */
|
||||||
+ separated by white space or colons that are loaded before the
|
+struct audit_list_iter
|
||||||
+ executable's dependencies and prepended to the global scope list.
|
|
||||||
+ (If the binary is running setuid all elements containing a '/' are
|
|
||||||
+ ignored since it is insecure.) Return the number of preloads
|
|
||||||
+ performed. */
|
|
||||||
+unsigned int
|
|
||||||
+handle_ld_preload (const char *preloadlist, struct link_map *main_map)
|
|
||||||
+{
|
+{
|
||||||
+ unsigned int npreloads = 0;
|
+ /* Tail of audit_list_string still needing processing, or NULL. */
|
||||||
+ const char *p = preloadlist;
|
+ const char *audit_list_tail;
|
||||||
+ char fname[SECURE_PATH_LIMIT];
|
|
||||||
+
|
+
|
||||||
+ while (*p != '\0')
|
+ /* The list element returned in the previous iteration. NULL before
|
||||||
+ {
|
+ the first element. */
|
||||||
+ /* Split preload list at space/colon. */
|
+ struct audit_list *previous;
|
||||||
+ size_t len = strcspn (p, " :");
|
|
||||||
+ if (len > 0 && len < sizeof (fname))
|
|
||||||
+ {
|
|
||||||
+ memcpy (fname, p, len);
|
|
||||||
+ fname[len] = '\0';
|
|
||||||
+ }
|
|
||||||
+ else
|
|
||||||
+ fname[0] = '\0';
|
|
||||||
+
|
+
|
||||||
+ /* Skip over the substring and the following delimiter. */
|
+ /* Scratch buffer for returning a name which is part of
|
||||||
+ p += len;
|
+ audit_list_string. */
|
||||||
+ if (*p != '\0')
|
+ char fname[SECURE_NAME_LIMIT];
|
||||||
+ ++p;
|
+};
|
||||||
+
|
+
|
||||||
+ if (dso_name_valid_for_suid (fname))
|
+/* Initialize an audit list iterator. */
|
||||||
+ npreloads += do_preload (fname, main_map, "LD_PRELOAD");
|
+static void
|
||||||
+ }
|
+audit_list_iter_init (struct audit_list_iter *iter)
|
||||||
+ return npreloads;
|
+{
|
||||||
|
+ iter->audit_list_tail = audit_list_string;
|
||||||
|
+ iter->previous = NULL;
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
static void
|
+/* Iterate through both audit_list_string and audit_list. */
|
||||||
dl_main (const ElfW(Phdr) *phdr,
|
+static const char *
|
||||||
ElfW(Word) phnum,
|
+audit_list_iter_next (struct audit_list_iter *iter)
|
||||||
@@ -1464,23 +1529,8 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
|
+{
|
||||||
|
+ if (iter->audit_list_tail != NULL)
|
||||||
|
+ {
|
||||||
|
+ /* First iterate over audit_list_string. */
|
||||||
|
+ while (*iter->audit_list_tail != '\0')
|
||||||
|
+ {
|
||||||
|
+ /* Split audit list at colon. */
|
||||||
|
+ size_t len = strcspn (iter->audit_list_tail, ":");
|
||||||
|
+ if (len > 0 && len < sizeof (iter->fname))
|
||||||
|
+ {
|
||||||
|
+ memcpy (iter->fname, iter->audit_list_tail, len);
|
||||||
|
+ iter->fname[len] = '\0';
|
||||||
|
+ }
|
||||||
|
+ else
|
||||||
|
+ /* Do not return this name to the caller. */
|
||||||
|
+ iter->fname[0] = '\0';
|
||||||
|
+
|
||||||
|
+ /* Skip over the substring and the following delimiter. */
|
||||||
|
+ iter->audit_list_tail += len;
|
||||||
|
+ if (*iter->audit_list_tail == ':')
|
||||||
|
+ ++iter->audit_list_tail;
|
||||||
|
+
|
||||||
|
+ /* If the name is valid, return it. */
|
||||||
|
+ if (dso_name_valid_for_suid (iter->fname))
|
||||||
|
+ return iter->fname;
|
||||||
|
+ /* Otherwise, wrap around and try the next name. */
|
||||||
|
+ }
|
||||||
|
+ /* Fall through to the procesing of audit_list. */
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (iter->previous == NULL)
|
||||||
|
+ {
|
||||||
|
+ if (audit_list == NULL)
|
||||||
|
+ /* No pre-parsed audit list. */
|
||||||
|
+ return NULL;
|
||||||
|
+ /* Start of audit list. The first list element is at
|
||||||
|
+ audit_list->next (cyclic list). */
|
||||||
|
+ iter->previous = audit_list->next;
|
||||||
|
+ return iter->previous->name;
|
||||||
|
+ }
|
||||||
|
+ if (iter->previous == audit_list)
|
||||||
|
+ /* Cyclic list wrap-around. */
|
||||||
|
+ return NULL;
|
||||||
|
+ iter->previous = iter->previous->next;
|
||||||
|
+ return iter->previous->name;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
#ifndef HAVE_INLINED_SYSCALLS
|
||||||
|
/* Set nonzero during loading and initialization of executable and
|
||||||
|
libraries, cleared before the executable's entry point runs. This
|
||||||
|
@@ -1305,11 +1383,13 @@ of this helper program; chances are you did not intend to run this program.\n\
|
||||||
|
GL(dl_rtld_map).l_tls_modid = _dl_next_tls_modid ();
|
||||||
|
|
||||||
if (__glibc_unlikely (preloadlist != NULL))
|
/* If we have auditing DSOs to load, do it now. */
|
||||||
|
- if (__glibc_unlikely (audit_list != NULL))
|
||||||
|
+ bool need_security_init = true;
|
||||||
|
+ if (__glibc_unlikely (audit_list != NULL)
|
||||||
|
+ || __glibc_unlikely (audit_list_string != NULL))
|
||||||
{
|
{
|
||||||
- /* The LD_PRELOAD environment variable gives list of libraries
|
- /* Iterate over all entries in the list. The order is important. */
|
||||||
- separated by white space or colons that are loaded before the
|
struct audit_ifaces *last_audit = NULL;
|
||||||
- executable's dependencies and prepended to the global scope
|
- struct audit_list *al = audit_list->next;
|
||||||
- list. If the binary is running setuid all elements
|
+ struct audit_list_iter al_iter;
|
||||||
- containing a '/' are ignored since it is insecure. */
|
+ audit_list_iter_init (&al_iter);
|
||||||
- char *list = strdupa (preloadlist);
|
|
||||||
- char *p;
|
/* Since we start using the auditing DSOs right away we need to
|
||||||
|
initialize the data structures now. */
|
||||||
|
@@ -1320,9 +1400,14 @@ of this helper program; chances are you did not intend to run this program.\n\
|
||||||
|
use different values (especially the pointer guard) and will
|
||||||
|
fail later on. */
|
||||||
|
security_init ();
|
||||||
|
+ need_security_init = false;
|
||||||
|
|
||||||
|
- do
|
||||||
|
+ while (true)
|
||||||
|
{
|
||||||
|
+ const char *name = audit_list_iter_next (&al_iter);
|
||||||
|
+ if (name == NULL)
|
||||||
|
+ break;
|
||||||
|
+
|
||||||
|
int tls_idx = GL(dl_tls_max_dtv_idx);
|
||||||
|
|
||||||
|
/* Now it is time to determine the layout of the static TLS
|
||||||
|
@@ -1331,7 +1416,7 @@ of this helper program; chances are you did not intend to run this program.\n\
|
||||||
|
no DF_STATIC_TLS bit is set. The reason is that we know
|
||||||
|
glibc will use the static model. */
|
||||||
|
struct dlmopen_args dlmargs;
|
||||||
|
- dlmargs.fname = al->name;
|
||||||
|
+ dlmargs.fname = name;
|
||||||
|
dlmargs.map = NULL;
|
||||||
|
|
||||||
|
const char *objname;
|
||||||
|
@@ -1344,7 +1429,7 @@ of this helper program; chances are you did not intend to run this program.\n\
|
||||||
|
not_loaded:
|
||||||
|
_dl_error_printf ("\
|
||||||
|
ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
|
||||||
|
- al->name, err_str);
|
||||||
|
+ name, err_str);
|
||||||
|
if (malloced)
|
||||||
|
free ((char *) err_str);
|
||||||
|
}
|
||||||
|
@@ -1448,10 +1533,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
|
||||||
|
goto not_loaded;
|
||||||
|
}
|
||||||
|
}
|
||||||
-
|
-
|
||||||
HP_TIMING_NOW (start);
|
- al = al->next;
|
||||||
-
|
}
|
||||||
- /* Prevent optimizing strsep. Speed is not important here. */
|
- while (al != audit_list->next);
|
||||||
- while ((p = (strsep) (&list, " :")) != NULL)
|
|
||||||
- if (p[0] != '\0'
|
/* If we have any auditing modules, announce that we already
|
||||||
- && (__builtin_expect (! __libc_enable_secure, 1)
|
have two objects loaded. */
|
||||||
- || strchr (p, '/') == NULL))
|
@@ -1715,7 +1797,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
|
||||||
- npreloads += do_preload (p, main_map, "LD_PRELOAD");
|
if (tcbp == NULL)
|
||||||
-
|
tcbp = init_tls ();
|
||||||
+ npreloads += handle_ld_preload (preloadlist, main_map);
|
|
||||||
HP_TIMING_NOW (stop);
|
- if (__glibc_likely (audit_list == NULL))
|
||||||
HP_TIMING_DIFF (diff, start, stop);
|
+ if (__glibc_likely (need_security_init))
|
||||||
HP_TIMING_ACCUM_NT (load_time, diff);
|
/* Initialize security features. But only if we have not done it
|
||||||
|
earlier. */
|
||||||
|
security_init ();
|
||||||
|
@@ -2346,9 +2428,7 @@ process_dl_audit (char *str)
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
while ((p = (strsep) (&str, ":")) != NULL)
|
||||||
|
- if (p[0] != '\0'
|
||||||
|
- && (__builtin_expect (! __libc_enable_secure, 1)
|
||||||
|
- || strchr (p, '/') == NULL))
|
||||||
|
+ if (dso_name_valid_for_suid (p))
|
||||||
|
{
|
||||||
|
/* This is using the local malloc, not the system malloc. The
|
||||||
|
memory can never be freed. */
|
||||||
|
@@ -2412,7 +2492,7 @@ process_envvars (enum mode *modep)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (memcmp (envline, "AUDIT", 5) == 0)
|
||||||
|
- process_dl_audit (&envline[6]);
|
||||||
|
+ audit_list_string = &envline[6];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 7:
|
||||||
--
|
--
|
||||||
2.9.3
|
2.9.3
|
||||||
|
|
||||||
|
|
23
gnu/packages/patches/glibc-vectorized-strcspn-guards.patch
Normal file
23
gnu/packages/patches/glibc-vectorized-strcspn-guards.patch
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
Copied from Debian.
|
||||||
|
|
||||||
|
2017-06-14 Florian Weimer <fweimer@redhat.com>
|
||||||
|
|
||||||
|
* sysdeps/i386/i686/multiarch/strcspn-c.c: Add IS_IN (libc) guard.
|
||||||
|
* sysdeps/i386/i686/multiarch/varshift.c: Likewise.
|
||||||
|
|
||||||
|
--- a/sysdeps/i386/i686/multiarch/strcspn-c.c
|
||||||
|
+++ b/sysdeps/i386/i686/multiarch/strcspn-c.c
|
||||||
|
@@ -1,2 +1,4 @@
|
||||||
|
-#define __strcspn_sse2 __strcspn_ia32
|
||||||
|
-#include <sysdeps/x86_64/multiarch/strcspn-c.c>
|
||||||
|
+#if IS_IN (libc)
|
||||||
|
+# define __strcspn_sse2 __strcspn_ia32
|
||||||
|
+# include <sysdeps/x86_64/multiarch/strcspn-c.c>
|
||||||
|
+#endif
|
||||||
|
--- a/sysdeps/i386/i686/multiarch/varshift.c
|
||||||
|
+++ b/sysdeps/i386/i686/multiarch/varshift.c
|
||||||
|
@@ -1 +1,3 @@
|
||||||
|
-#include <sysdeps/x86_64/multiarch/varshift.c>
|
||||||
|
+#if IS_IN (libc)
|
||||||
|
+# include <sysdeps/x86_64/multiarch/varshift.c>
|
||||||
|
+#endif
|
Loading…
Reference in a new issue