From 400f170750a4b2c94a2670ca44de166cc5dd6e3b Mon Sep 17 00:00:00 2001
From: Florian Weimer <fweimer@redhat.com>
Date: Mon, 19 Jun 2017 18:33:26 +0200
Subject: [PATCH] CVE-2017-1000366: Ignore LD_LIBRARY_PATH for AT_SECURE=1
 programs [BZ #21624]

LD_LIBRARY_PATH can only be used to reorder system search paths, which
is not useful functionality.

This makes an exploitable unbounded alloca in _dl_init_paths unreachable
for AT_SECURE=1 programs.

(cherry picked from commit f6110a8fee2ca36f8e2d2abecf3cba9fa7b8ea7d)

Upstream-Status: Backport
https://sourceware.org/git/?p=glibc.git;a=commit;h=87bd4186da10371f46e2f1a7bf7c0a45bb04f1ac
https://anonscm.debian.org/cgit/pkg-glibc/glibc.git/commit/?h=stretch&id=2755c57269f24e9d59c22c49788f92515346c1bb

CVE: CVE-2017-1000366

Signed-off-by: George McCollister <george.mccollister@gmail.com>
---
 ChangeLog  | 7 +++++++
 NEWS       | 1 +
 elf/rtld.c | 3 ++-
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 2bdaf69e43..7a999802dd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2017-06-19  Florian Weimer  <fweimer@redhat.com>
+
+	[BZ #21624]
+	CVE-2017-1000366
+	* elf/rtld.c (process_envvars): Ignore LD_LIBRARY_PATH for
+	__libc_enable_secure.
+
 2016-12-31  Florian Weimer  <fweimer@redhat.com>
 
 	[BZ #18784]
diff --git a/NEWS b/NEWS
index 4b1ca3cb65..66b49dbbc0 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,7 @@ using `glibc' in the "product" field.
   question type which is outside the range of valid question type values.
   (CVE-2015-5180)
 
+  [21624] Unsafe alloca allows local attackers to alias stack and heap (CVE-2017-1000366)
 Version 2.24
 
 * The minimum Linux kernel version that this version of the GNU C Library
diff --git a/elf/rtld.c b/elf/rtld.c
index 647661ca45..215a9aec8f 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -2437,7 +2437,8 @@ process_envvars (enum mode *modep)
 
 	case 12:
 	  /* The library search path.  */
-	  if (memcmp (envline, "LIBRARY_PATH", 12) == 0)
+	  if (!__libc_enable_secure
+	      && memcmp (envline, "LIBRARY_PATH", 12) == 0)
 	    {
 	      library_path = &envline[13];
 	      break;
-- 
2.15.0

