1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-28 00:21:52 +03:00

libio: Implement vtable verification [BZ #20191]

This commit puts all libio vtables in a dedicated, read-only ELF
section, so that they are consecutive in memory.  Before any indirect
jump, the vtable pointer is checked against the section boundaries,
and the process is terminated if the vtable pointer does not fall into
the special ELF section.

To enable backwards compatibility, a special flag variable
(_IO_accept_foreign_vtables), protected by the pointer guard, avoids
process termination if libio stream object constructor functions have
been called earlier.  Such constructor functions are called by the GCC
2.95 libstdc++ library, and this mechanism ensures compatibility with
old binaries.  Existing callers inside glibc of these functions are
adjusted to call the original functions, not the wrappers which enable
vtable compatiblity.

The compatibility mechanism is used to enable passing FILE * objects
across a static dlopen boundary, too.
This commit is contained in:
Florian Weimer
2016-06-23 20:01:40 +02:00
parent 64ba17317d
commit db3476aff1
30 changed files with 279 additions and 60 deletions

View File

@ -153,15 +153,15 @@ _IO_new_fdopen (int fd, const char *mode)
(use_mmap && (read_write & _IO_NO_WRITES)) ? &_IO_file_jumps_maybe_mmap :
#endif
&_IO_file_jumps;
_IO_file_init (&new_f->fp);
_IO_new_file_init_internal (&new_f->fp);
#if !_IO_UNIFIED_JUMPTABLES
new_f->fp.vtable = NULL;
#endif
/* We only need to record the fd because _IO_file_init will have unset the
offset. It is important to unset the cached offset because the real
offset in the file could change between now and when the handle is
activated and we would then mislead ftell into believing that we have a
valid offset. */
/* We only need to record the fd because _IO_file_init_internal will
have unset the offset. It is important to unset the cached
offset because the real offset in the file could change between
now and when the handle is activated and we would then mislead
ftell into believing that we have a valid offset. */
new_f->fp.file._fileno = fd;
new_f->fp.file._flags &= ~_IO_DELETE_DONT_CLOSE;