about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2018-06-26 10:24:52 +0200
committerFlorian Weimer <fweimer@redhat.com>2019-11-28 16:21:26 +0100
commit8440c51d8981e8e40d611a2cbf9850091e7d5a72 (patch)
tree69db74157d20169b01a52a93834a306a0e658fbc
parente73ac9ce9098d36699231b435168a0a904500ed9 (diff)
downloadglibc-8440c51d8981e8e40d611a2cbf9850091e7d5a72.tar.gz
glibc-8440c51d8981e8e40d611a2cbf9850091e7d5a72.tar.xz
glibc-8440c51d8981e8e40d611a2cbf9850091e7d5a72.zip
libio: Disable vtable validation in case of interposition [BZ #23313]
(cherry picked from commit c402355dfa7807b8e0adb27c009135a7e2b9f1b0)
-rw-r--r--ChangeLog5
-rw-r--r--libio/vtables.c16
2 files changed, 21 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 9a8840b968..94788a98c6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2018-06-26  Florian Weimer  <fweimer@redhat.com>
+
+	[BZ #23313]
+	* libio/vtables.c (check_stdfiles_vtables): New ELF constructor.
+
 2019-11-01  Dragan Mladjenovic  <dmladjenovic@wavecomp.com>
 
 	* sysdeps/unix/sysv/linux/mips/Makefile
diff --git a/libio/vtables.c b/libio/vtables.c
index 41b48db98c..a11226ab17 100644
--- a/libio/vtables.c
+++ b/libio/vtables.c
@@ -70,3 +70,19 @@ _IO_vtable_check (void)
 
   __libc_fatal ("Fatal error: glibc detected an invalid stdio handle\n");
 }
+
+/* Some variants of libstdc++ interpose _IO_2_1_stdin_ etc. and
+   install their own vtables directly, without calling _IO_init or
+   other functions.  Detect this by looking at the vtables values
+   during startup, and disable vtable validation in this case.  */
+#ifdef SHARED
+__attribute__ ((constructor))
+static void
+check_stdfiles_vtables (void)
+{
+  if (_IO_2_1_stdin_.vtable != &_IO_file_jumps
+      || _IO_2_1_stdout_.vtable != &_IO_file_jumps
+      || _IO_2_1_stderr_.vtable != &_IO_file_jumps)
+    IO_set_accept_foreign_vtables (&_IO_vtable_check);
+}
+#endif