public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v6 0/2] _FORTIFY_SOURCE=3
@ 2020-12-19  6:33 Siddhesh Poyarekar
  2020-12-19  6:33 ` [PATCH 1/2] string: _FORTIFY_SOURCE=3 using __builtin_dynamic_object_size Siddhesh Poyarekar
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Siddhesh Poyarekar @ 2020-12-19  6:33 UTC (permalink / raw)
  To: libc-alpha; +Cc: carlos, fweimer, jakub, eggert

This patchset implements a new fortification level, _FORTIFY_SOURCE=3.
This level allows size information to be dynamic, which may potentially
have a noticeable performance impact.  It uses the
__builtin_dynamic_object_size builtin available in clang to expand
coverage of fortifications at the expense of some performance.

Patch 1/2 implements the base support and support for functions that
have builtins of string functions.  Additionally, the patch also
describes the use case and tradeoffs.

Patch 2/2 adds support for non-string functions that are
fortification-ready for levels 1 and 2.

Testing:

The glibc testsuite doesn't directly support clang at the moment, so
having tests in the glibc source tree is pointless as long as gcc does
not have support for __builtin_dynamic_object_size.  There is a separate
project on GitHub called fortify-test-suite[1] that houses fortification
tests and is capable of testing multiple levels of fortification with
multiple compilers.  I have proposed a PR[2] to add support for
_FORTIFY_SOURCE=3 and have verified my changes with those tests.

Those tests run clean for clang when run with these changes and PR[2]
and they fail at level 3 for gcc, as expected.

[1] https://github.com/serge-sans-paille/fortify-test-suite
[2] https://github.com/serge-sans-paille/fortify-test-suite/pull/9

Changes from previous series:

- Adopted Paul Eggert's macro soup because it has better texture while
  retaining the flavour.

Siddhesh Poyarekar (2):
  string: _FORTIFY_SOURCE=3 using __builtin_dynamic_object_size
  nonstring: _FORTIFY_SOURCE=3 using __builtin_dynamic_object_size

 NEWS                            |   6 ++
 include/features.h              |   8 ++
 include/string.h                |   5 +-
 io/bits/poll2.h                 |  16 ++--
 libio/bits/stdio.h              |   2 +-
 libio/bits/stdio2.h             |  53 ++++++-------
 manual/creature.texi            |   3 +-
 misc/sys/cdefs.h                |   9 +++
 posix/bits/unistd.h             | 112 ++++++++++++++-------------
 socket/bits/socket2.h           |  18 ++---
 stdlib/bits/stdlib.h            |  37 ++++-----
 string/bits/string_fortified.h  |  22 +++---
 string/bits/strings_fortified.h |   4 +-
 wcsmbs/bits/wchar2.h            | 131 ++++++++++++++++----------------
 14 files changed, 230 insertions(+), 196 deletions(-)

-- 
2.29.2


^ permalink raw reply	[flat|nested] 14+ messages in thread
* [PATCH 0/2] _FORTIFY_SOURCE=3
@ 2020-12-10 18:13 Siddhesh Poyarekar
  2020-12-10 18:13 ` [PATCH 1/2] string: _FORTIFY_SOURCE=3 using __builtin_dynamic_object_size Siddhesh Poyarekar
  0 siblings, 1 reply; 14+ messages in thread
From: Siddhesh Poyarekar @ 2020-12-10 18:13 UTC (permalink / raw)
  To: libc-alpha; +Cc: carlos, jakub, fweimer, law

This patchset implements a new fortification level, _FORTIFY_SOURCE=3.
This level allows allows more computationally expensive fortifications,
as is the case when size information is dynamic.  In this patchset it
uses the __builtin_dynamic_object_size builtin available in clang to
expand coverage of fortifications at the expense of some performance.

Patch 1/2 implements the base support and support for functions that
have builtins of string functions.  Additionally, the patch also
describes the use case and tradeoffs.

Patch 2/2 adds support for non-string functions that are already
forfified for levels 1 and 2.  These use a specific idiom that is
currently suboptimal in llvm.

Documentation                                                                                                                                                                                                      
-------------                                                                                                                                                                                                      
                                                                                                                                                                                                                   
The _FORTIFY_SOURCE documentation is not explicit about the technology                                                                                                                                             
used to implement checks and in that spirit, I have kept the                                                                                                                                                       
description for _FORTIFY_SOURCE=3 broad as well, without mentioning                                                                                                                                                
__builtin_dynamic_object_size.  Essentially, 3 is where we want to add                                                                                                                                             
computationally expensive checks and so that's the only thing that                                                                                                                                                 
gets mentioned along with the fact that it is compiler-specific.

Testing
-------

The glibc testsuite doesn't directly support clang at the moment, so
having tests in the glibc source tree is pointless as long as gcc does
not have support for __builtin_dynamic_object_size.  I will write the
tests when I work on the gcc builtin next year.

In the meantime there is a separate project on GitHub,
fortify-test-suite[1], that houses fortification tests and is capable of
testing multiple levels of fortification with multiple compilers.  I
have proposed a PR[2] to add support for _FORTIFY_SOURCE=3 and have
verified my changes with those tests.

Those tests run clean for clang when run with these changes and PR[2]
and they fail at level 3 for gcc, as expected.

[1] https://github.com/serge-sans-paille/fortify-test-suite
[2] https://github.com/serge-sans-paille/fortify-test-suite/pull/9

Siddhesh Poyarekar (2):
  string: _FORTIFY_SOURCE=3 using __builtin_dynamic_object_size
  nonstring: _FORTIFY_SOURCE=3 using __builtin_dynamic_object_size

 NEWS                            |   4 +
 include/features.h              |   6 +-
 include/string.h                |   5 +-
 io/bits/poll2.h                 |  16 ++--
 libio/bits/stdio.h              |   2 +-
 libio/bits/stdio2.h             |  53 ++++++-------
 manual/creature.texi            |   3 +-
 misc/sys/cdefs.h                |   9 +++
 posix/bits/unistd.h             | 112 ++++++++++++++-------------
 socket/bits/socket2.h           |  18 ++---
 stdlib/bits/stdlib.h            |  37 ++++-----
 string/bits/string_fortified.h  |  22 +++---
 string/bits/strings_fortified.h |   4 +-
 wcsmbs/bits/wchar2.h            | 131 ++++++++++++++++----------------
 14 files changed, 223 insertions(+), 199 deletions(-)

-- 
2.28.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2020-12-29 15:14 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-19  6:33 [PATCH v6 0/2] _FORTIFY_SOURCE=3 Siddhesh Poyarekar
2020-12-19  6:33 ` [PATCH 1/2] string: _FORTIFY_SOURCE=3 using __builtin_dynamic_object_size Siddhesh Poyarekar
2020-12-28 16:44   ` Adhemerval Zanella
2020-12-29 15:14     ` Siddhesh Poyarekar
2020-12-19  6:33 ` [PATCH 2/2] nonstring: " Siddhesh Poyarekar
2020-12-28 17:36   ` Adhemerval Zanella
2020-12-29 14:04     ` Siddhesh Poyarekar
2020-12-29 14:26     ` Jakub Jelinek
2020-12-22 13:00 ` [PATCH v6 0/2] _FORTIFY_SOURCE=3 Siddhesh Poyarekar
2020-12-22 21:49   ` Adhemerval Zanella
  -- strict thread matches above, loose matches on Subject: below --
2020-12-10 18:13 [PATCH " Siddhesh Poyarekar
2020-12-10 18:13 ` [PATCH 1/2] string: _FORTIFY_SOURCE=3 using __builtin_dynamic_object_size Siddhesh Poyarekar
2020-12-10 19:10   ` Paul Eggert
2020-12-11  1:36     ` Siddhesh Poyarekar
2020-12-11  2:42       ` Paul Eggert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).