mbox

[00/26] vfprintf rework to remove vtables

Message ID cover.1647544751.git.fweimer@redhat.com (mailing list archive)
Headers

Message

Florian Weimer March 17, 2022, 7:28 p.m. UTC
  This started out as an attempt to fix bug 27124, the vtable hardening
bypass involving obstack_printf.

The new buffers are modeled after the write pointer/end pointer
abstraction used for inline putc_unlocked.  They have considerably lower
setup overhead than the internal stdio-compatible streams used by
sprintf.  Performance seems to be at least on par with the old
implementation, and a bit better for floating point formatting.

The new internal interfaces are added in commit “stdio-common: Introduce
buffers for implementing printf”.  The bulk of the conversions happen in
“stdio-common: Convert vfprintf and related functions to buffers”.
Initially, I converted things piece by piece, but that required
implementing additional bounce buffers for translation, so this one
commit converts the majority of the functions.  The commit message of
this large commit has some suggestions for review order.

Tested on i686-linux-gnu and x86_64-linux-gnu.  Built with
build-many-glibcs.py.

Thanks,
Florian

Florian Weimer (26):
  libio: Convert tst_swprintf to the test framework
  libio: Flush-only _IO_str_overflow must not return EOF (bug 28949)
  stdio-common: Add wide stream coverage to tst-vfprintf-user-type
  stdio-common: Add tst-printf-width-i18n to cover numeric field width
  vfprintf: Move argument processing into vfprintf-process-arg.c
  vfprintf: Consolidate some multibyte/wide character processing
  __printf_fphex always uses LC_NUMERIC
  stdio-common: Add tst-memstream-string for open_memstream overflow
  stdio-common: Add printf specifier registry to <printf.h>
  stdio-common: Move union printf_arg int <printf.h>
  stdio-common: Simplify printf_unknown interface in vfprintf-internal.c
  locale: Call _nl_unload_locale from _nl_archive_subfreeres
  locale: Remove cleanup function pointer from struct __localedata
  locale: Remove private union from struct __locale_data
  locale: Add more cached data to LC_CTYPE
  locale: Implement struct grouping_iterator
  stdio-common: Introduce buffers for implementing printf
  stdio-common: Add __printf_function_invoke
  stdio-common: Add __translated_number_width
  stdio-common: Convert vfprintf and related functions to buffers
  stdio-common: Add lock optimization to vfprintf and vfwprintf
  libio: Convert __vsprintf_internal to buffers
  libio: Convert __vasprintf_internal to buffers
  libio: Convert __vdprintf_internal to buffers
  libio: Convert __obstack_vprintf_internal to buffers (bug 27124)
  libio: Convert __vswprintf_internal to buffers (bug 27857)

 include/printf.h                              |   79 +-
 include/printf_buffer.h                       |  332 +++++
 libio/iovdprintf.c                            |   69 +-
 libio/iovsprintf.c                            |   70 +-
 libio/obprintf.c                              |  170 +--
 libio/strops.c                                |    5 +-
 libio/tst-vtables-common.c                    |    9 +-
 libio/tst_swprintf.c                          |  110 +-
 libio/vasprintf.c                             |  141 +-
 libio/vsnprintf.c                             |  131 +-
 libio/vswprintf.c                             |  100 +-
 libio/wstrops.c                               |    5 +-
 locale/C-address.c                            |    2 +-
 locale/C-collate.c                            |    2 +-
 locale/C-ctype.c                              |    9 +-
 locale/C-identification.c                     |    2 +-
 locale/C-measurement.c                        |    2 +-
 locale/C-messages.c                           |    2 +-
 locale/C-monetary.c                           |    2 +-
 locale/C-name.c                               |    2 +-
 locale/C-numeric.c                            |    2 +-
 locale/C-paper.c                              |    2 +-
 locale/C-telephone.c                          |    2 +-
 locale/C-time.c                               |    2 +-
 locale/findlocale.c                           |    2 +-
 locale/loadarchive.c                          |    8 +-
 locale/loadlocale.c                           |   89 +-
 locale/localeinfo.h                           |   48 +-
 locale/setlocale.c                            |    2 +-
 manual/stdio.texi                             |    7 +-
 stdio-common/Makefile                         |   29 +-
 stdio-common/Xprintf_buffer_done.c            |   40 +
 stdio-common/Xprintf_buffer_flush.c           |   72 +
 stdio-common/Xprintf_buffer_pad_1.c           |   44 +
 stdio-common/Xprintf_buffer_putc_1.c          |   29 +
 stdio-common/Xprintf_buffer_puts_1.c          |   37 +
 stdio-common/Xprintf_buffer_write.c           |   43 +
 stdio-common/Xprintf_function_invoke.c        |   42 +
 stdio-common/grouping_iterator.c              |  125 ++
 stdio-common/grouping_iterator.h              |   65 +
 stdio-common/printf-parse.h                   |   23 -
 stdio-common/printf_buffer-char.h             |   24 +
 stdio-common/printf_buffer-wchar_t.h          |   24 +
 stdio-common/printf_buffer_as_file.c          |  148 ++
 stdio-common/printf_buffer_as_file.h          |   87 ++
 stdio-common/printf_buffer_done.c             |   21 +
 stdio-common/printf_buffer_flush.c            |   81 ++
 stdio-common/printf_buffer_pad_1.c            |   21 +
 stdio-common/printf_buffer_putc_1.c           |   21 +
 stdio-common/printf_buffer_puts_1.c           |   21 +
 stdio-common/printf_buffer_to_file.c          |  122 ++
 stdio-common/printf_buffer_to_file.h          |   57 +
 stdio-common/printf_buffer_write.c            |   21 +
 stdio-common/printf_fp.c                      |  736 +++++-----
 stdio-common/printf_fphex.c                   |  271 ++--
 stdio-common/printf_function_invoke.c         |   22 +
 stdio-common/reg-printf.c                     |    7 -
 stdio-common/translated_number_width.c        |   42 +
 stdio-common/tst-grouping_iterator.c          |  262 ++++
 stdio-common/tst-memstream-string.c           |   85 ++
 stdio-common/tst-printf-width-i18n.c          |   95 ++
 stdio-common/tst-vfprintf-user-type.c         |  128 +-
 stdio-common/vfprintf-internal.c              | 1189 +++--------------
 stdio-common/vfprintf-process-arg.c           |  489 +++++++
 stdio-common/wprintf_buffer_as_file.c         |  153 +++
 stdio-common/wprintf_buffer_done.c            |   21 +
 stdio-common/wprintf_buffer_flush.c           |   42 +
 stdio-common/wprintf_buffer_pad_1.c           |   21 +
 stdio-common/wprintf_buffer_putc_1.c          |   21 +
 stdio-common/wprintf_buffer_puts_1.c          |   21 +
 stdio-common/wprintf_buffer_to_file.c         |   55 +
 stdio-common/wprintf_buffer_write.c           |   21 +
 stdio-common/wprintf_function_invoke.c        |   22 +
 stdlib/strfmon_l.c                            |  196 ++-
 stdlib/strfrom-skeleton.c                     |   38 +-
 sysdeps/ia64/fpu/printf_fphex.c               |    8 +-
 .../ieee754/ldbl-128/printf_fphex_macros.h    |   36 +-
 sysdeps/ieee754/ldbl-128ibm/printf_fphex.c    |   36 +-
 sysdeps/ieee754/ldbl-96/printf_fphex.c        |   22 +-
 sysdeps/x86_64/fpu/printf_fphex.c             |   21 +-
 time/alt_digit.c                              |   49 +-
 time/era.c                                    |   49 +-
 time/lc-time-cleanup.c                        |    5 +-
 wcsmbs/wcsmbsload.c                           |   27 +-
 wcsmbs/wcsmbsload.h                           |   11 +-
 85 files changed, 4275 insertions(+), 2531 deletions(-)
 create mode 100644 include/printf_buffer.h
 create mode 100644 stdio-common/Xprintf_buffer_done.c
 create mode 100644 stdio-common/Xprintf_buffer_flush.c
 create mode 100644 stdio-common/Xprintf_buffer_pad_1.c
 create mode 100644 stdio-common/Xprintf_buffer_putc_1.c
 create mode 100644 stdio-common/Xprintf_buffer_puts_1.c
 create mode 100644 stdio-common/Xprintf_buffer_write.c
 create mode 100644 stdio-common/Xprintf_function_invoke.c
 create mode 100644 stdio-common/grouping_iterator.c
 create mode 100644 stdio-common/grouping_iterator.h
 create mode 100644 stdio-common/printf_buffer-char.h
 create mode 100644 stdio-common/printf_buffer-wchar_t.h
 create mode 100644 stdio-common/printf_buffer_as_file.c
 create mode 100644 stdio-common/printf_buffer_as_file.h
 create mode 100644 stdio-common/printf_buffer_done.c
 create mode 100644 stdio-common/printf_buffer_flush.c
 create mode 100644 stdio-common/printf_buffer_pad_1.c
 create mode 100644 stdio-common/printf_buffer_putc_1.c
 create mode 100644 stdio-common/printf_buffer_puts_1.c
 create mode 100644 stdio-common/printf_buffer_to_file.c
 create mode 100644 stdio-common/printf_buffer_to_file.h
 create mode 100644 stdio-common/printf_buffer_write.c
 create mode 100644 stdio-common/printf_function_invoke.c
 create mode 100644 stdio-common/translated_number_width.c
 create mode 100644 stdio-common/tst-grouping_iterator.c
 create mode 100644 stdio-common/tst-memstream-string.c
 create mode 100644 stdio-common/tst-printf-width-i18n.c
 create mode 100644 stdio-common/vfprintf-process-arg.c
 create mode 100644 stdio-common/wprintf_buffer_as_file.c
 create mode 100644 stdio-common/wprintf_buffer_done.c
 create mode 100644 stdio-common/wprintf_buffer_flush.c
 create mode 100644 stdio-common/wprintf_buffer_pad_1.c
 create mode 100644 stdio-common/wprintf_buffer_putc_1.c
 create mode 100644 stdio-common/wprintf_buffer_puts_1.c
 create mode 100644 stdio-common/wprintf_buffer_to_file.c
 create mode 100644 stdio-common/wprintf_buffer_write.c
 create mode 100644 stdio-common/wprintf_function_invoke.c


base-commit: e297d33c73aa22c86228170343c7b2f9bfac6f1e