libio: Implement vtable verification [BZ #20191]

System Internals / glibc - Florian Weimer [redhat.com] - 23 June 2016 13:01 UTC

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.

db3476a libio: Implement vtable verification [BZ #20191]
ChangeLog | 74 +++++++++++++++++++++++++++++++++++++++++++++
Makerules | 3 ++
debug/obprintf_chk.c | 2 +-
debug/vdprintf_chk.c | 2 +-
debug/vsnprintf_chk.c | 2 +-
debug/vsprintf_chk.c | 2 +-
libio/Makefile | 2 +-
libio/fileops.c | 18 +++++++----
libio/genops.c | 10 +++++--
libio/iofdopen.c | 12 ++++----
libio/iofopen.c | 2 +-
libio/iofopncook.c | 8 ++---
libio/iopopen.c | 6 ++--
libio/iovdprintf.c | 2 +-
libio/libioP.h | 76 +++++++++++++++++++++++++++++++++++++++--------
libio/memstream.c | 4 +--
libio/obprintf.c | 2 +-
libio/oldfileops.c | 12 ++++++--
libio/oldiofdopen.c | 2 +-
libio/oldiofopen.c | 2 +-
libio/oldiopopen.c | 4 +--
libio/strops.c | 2 +-
libio/vsnprintf.c | 2 +-
libio/vswprintf.c | 2 +-
libio/vtables.c | 70 +++++++++++++++++++++++++++++++++++++++++++
libio/wfileops.c | 6 ++--
libio/wmemstream.c | 2 +-
libio/wstrops.c | 2 +-
stdio-common/vfprintf.c | 4 +--
stdlib/strfmon_l.c | 2 +-
30 files changed, 279 insertions(+), 60 deletions(-)

Upstream: sourceware.org


  • Share