rtld: Check __libc_enable_secure before honoring LD_PREFER_MAP_32BIT_EXEC (CVE-2019-19126) [BZ #25204]

Message ID 20191120232015.25936-1-mwk@0x04.net
State New
Headers show
Series
  • rtld: Check __libc_enable_secure before honoring LD_PREFER_MAP_32BIT_EXEC (CVE-2019-19126) [BZ #25204]
Related show

Commit Message

Marcin Kościelnicki Nov. 20, 2019, 11:20 p.m.
The problem was introduced in glibc 2.23, in commit
b9eb92ab05204df772eb4929eccd018637c9f3e9
("Add Prefer_MAP_32BIT_EXEC to map executable pages with MAP_32BIT").
---
 NEWS                                            | 6 +++++-
 sysdeps/unix/sysv/linux/x86_64/64/dl-librecon.h | 3 ++-
 2 files changed, 7 insertions(+), 2 deletions(-)

-- 
2.23.0

Comments

Florian Weimer Nov. 21, 2019, 12:19 p.m. | #1
* Marcin Kościelnicki:

> The problem was introduced in glibc 2.23, in commit

> b9eb92ab05204df772eb4929eccd018637c9f3e9

> ("Add Prefer_MAP_32BIT_EXEC to map executable pages with MAP_32BIT").


Thanks, I have pushed this for you.

Florian

Patch

diff --git a/NEWS b/NEWS
index 50479f17c9..df03f4dc48 100644
--- a/NEWS
+++ b/NEWS
@@ -86,7 +86,11 @@  Changes to build and runtime requirements:
 
 Security related changes:
 
-  [Add security related changes here]
+  CVE-2019-19126: ld.so failed to ignore the LD_PREFER_MAP_32BIT_EXEC
+  environment variable during program execution after a security
+  transition, allowing local attackers to restrict the possible mapping
+  addresses for loaded libraries and thus bypass ASLR for a setuid
+  program.  Reported by Marcin Kościelnicki.
 
 The following bugs are resolved with this release:
 
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/dl-librecon.h b/sysdeps/unix/sysv/linux/x86_64/64/dl-librecon.h
index 0e95221908..e3af239faa 100644
--- a/sysdeps/unix/sysv/linux/x86_64/64/dl-librecon.h
+++ b/sysdeps/unix/sysv/linux/x86_64/64/dl-librecon.h
@@ -31,7 +31,8 @@ 
    environment variable, LD_PREFER_MAP_32BIT_EXEC.  */
 #define EXTRA_LD_ENVVARS \
   case 21:								  \
-    if (memcmp (envline, "PREFER_MAP_32BIT_EXEC", 21) == 0)		  \
+    if (!__libc_enable_secure						  \
+	&& memcmp (envline, "PREFER_MAP_32BIT_EXEC", 21) == 0)		  \
       GLRO(dl_x86_cpu_features).feature[index_arch_Prefer_MAP_32BIT_EXEC] \
 	|= bit_arch_Prefer_MAP_32BIT_EXEC;				  \
     break;