From: Florian Weimer Date: Tue, 26 Jun 2018 08:24:52 +0000 (+0200) Subject: libio: Disable vtable validation in case of interposition [BZ #23313] X-Git-Tag: glibc-2.28~161 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c402355dfa7807b8e0adb27c009135a7e2b9f1b0;p=thirdparty%2Fglibc.git libio: Disable vtable validation in case of interposition [BZ #23313] --- diff --git a/ChangeLog b/ChangeLog index f8d28b496ec..664928d5fe7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2018-06-26 Florian Weimer + + [BZ #23313] + * libio/vtables.c (check_stdfiles_vtables): New ELF constructor. + 2018-06-25 Florian Weimer [BZ #18023] diff --git a/libio/vtables.c b/libio/vtables.c index 9fd4ccf642a..9df75668c8a 100644 --- a/libio/vtables.c +++ b/libio/vtables.c @@ -71,3 +71,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