1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-08 17:42:12 +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

@@ -114,7 +114,7 @@ extern int errno;
void
attribute_compat_text_section
_IO_old_file_init (struct _IO_FILE_plus *fp)
_IO_old_file_init_internal (struct _IO_FILE_plus *fp)
{
/* POSIX.1 allows another file handle to be used to change the position
of our file descriptor. Hence we actually don't know the actual
@@ -138,6 +138,14 @@ _IO_old_file_init (struct _IO_FILE_plus *fp)
#endif
}
void
attribute_compat_text_section
_IO_old_file_init (struct _IO_FILE_plus *fp)
{
IO_set_accept_foreign_vtables (&_IO_vtable_check);
_IO_old_file_init_internal (fp);
}
int
attribute_compat_text_section
_IO_old_file_close_it (_IO_FILE *fp)
@@ -745,7 +753,7 @@ _IO_old_file_xsputn (_IO_FILE *f, const void *data, _IO_size_t n)
}
const struct _IO_jump_t _IO_old_file_jumps =
const struct _IO_jump_t _IO_old_file_jumps libio_vtable =
{
JUMP_INIT_DUMMY,
JUMP_INIT(finish, _IO_old_file_finish),