diff mbox series

[v7,1/4] Warn on unsupported fortification levels

Message ID 20201230064348.376092-2-siddhesh@sourceware.org
State New
Headers show
Series _FORTIFY_SOURCE=3 | expand

Commit Message

Siddhesh Poyarekar Dec. 30, 2020, 6:43 a.m. UTC
Make the _FORTIFY_SOURCE macro soup in features.h warn about
unsupported fortification levels.  For example, it will warn about
_FORTIFY_SOURCE=3 and over with an indication of which level has been
selected.

Co-authored-by: Paul Eggert <eggert@cs.ucla.edu>
---
 NEWS                 | 6 ++++++
 include/features.h   | 3 +++
 manual/creature.texi | 3 ++-
 3 files changed, 11 insertions(+), 1 deletion(-)

Comments

Adhemerval Zanella Netto Dec. 31, 2020, 10:45 a.m. UTC | #1
On 30/12/2020 03:43, Siddhesh Poyarekar wrote:
> Make the _FORTIFY_SOURCE macro soup in features.h warn about
> unsupported fortification levels.  For example, it will warn about
> _FORTIFY_SOURCE=3 and over with an indication of which level has been
> selected.
> 
> Co-authored-by: Paul Eggert <eggert@cs.ucla.edu>

LGTM, although I think the NEWS entry should move to the second patch.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  NEWS                 | 6 ++++++
>  include/features.h   | 3 +++
>  manual/creature.texi | 3 ++-
>  3 files changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/NEWS b/NEWS
> index 86e05fb023..8e02dbd0f7 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -28,6 +28,12 @@ Major new features:
>    The 32-bit RISC-V port requires at least Linux 5.4, GCC 7.1 and binutils
>    2.28.
>  
> +* A new fortification level _FORTIFY_SOURCE=3 is available.  At this level,
> +  glibc may use additional checks that may have an additional performance
> +  overhead.  At present these checks are available only on LLVM 9 and later.
> +  The latest GCC available at this time (10.2) does not support this level of
> +  fortification.
> +
>  Deprecated and removed features, and other changes affecting compatibility:
>  
>  * The mallinfo function is marked deprecated.  Callers should call

Maybe move this NEWS entry to second patch, where this is actually enabled?

> diff --git a/include/features.h b/include/features.h
> index f3e62d3362..540230b90b 100644
> --- a/include/features.h
> +++ b/include/features.h
> @@ -398,6 +398,9 @@
>  # elif !__GNUC_PREREQ (4, 1)
>  #  warning _FORTIFY_SOURCE requires GCC 4.1 or later
>  # elif _FORTIFY_SOURCE > 1
> +#  if _FORTIFY_SOURCE > 2
> +#   warning _FORTIFY_SOURCE > 2 is treated like 2 on this platform
> +#  endif
>  #  define __USE_FORTIFY_LEVEL 2
>  # else
>  #  define __USE_FORTIFY_LEVEL 1
> diff --git a/manual/creature.texi b/manual/creature.texi
> index be5050468b..31208ccb2b 100644
> --- a/manual/creature.texi
> +++ b/manual/creature.texi
> @@ -254,7 +254,8 @@ included.
>  @standards{GNU, (none)}
>  If this macro is defined to @math{1}, security hardening is added to
>  various library functions.  If defined to @math{2}, even stricter
> -checks are applied.
> +checks are applied. If defined to @math{3}, @theglibc{} may also use
> +checks that may have an additional performance overhead.
>  @end defvr
>  
>  @defvr Macro _REENTRANT
>
Siddhesh Poyarekar Dec. 31, 2020, 11:28 a.m. UTC | #2
On 12/31/20 4:15 PM, Adhemerval Zanella wrote:
> 
> 
> On 30/12/2020 03:43, Siddhesh Poyarekar wrote:
>> Make the _FORTIFY_SOURCE macro soup in features.h warn about
>> unsupported fortification levels.  For example, it will warn about
>> _FORTIFY_SOURCE=3 and over with an indication of which level has been
>> selected.
>>
>> Co-authored-by: Paul Eggert <eggert@cs.ucla.edu>
> 
> LGTM, although I think the NEWS entry should move to the second patch.
> 

Oops, yes.  I've moved the creatures.texi as well as NEWS content to 2/4 
before commit.

Thanks,
Siddhesh
diff mbox series

Patch

diff --git a/NEWS b/NEWS
index 86e05fb023..8e02dbd0f7 100644
--- a/NEWS
+++ b/NEWS
@@ -28,6 +28,12 @@  Major new features:
   The 32-bit RISC-V port requires at least Linux 5.4, GCC 7.1 and binutils
   2.28.
 
+* A new fortification level _FORTIFY_SOURCE=3 is available.  At this level,
+  glibc may use additional checks that may have an additional performance
+  overhead.  At present these checks are available only on LLVM 9 and later.
+  The latest GCC available at this time (10.2) does not support this level of
+  fortification.
+
 Deprecated and removed features, and other changes affecting compatibility:
 
 * The mallinfo function is marked deprecated.  Callers should call
diff --git a/include/features.h b/include/features.h
index f3e62d3362..540230b90b 100644
--- a/include/features.h
+++ b/include/features.h
@@ -398,6 +398,9 @@ 
 # elif !__GNUC_PREREQ (4, 1)
 #  warning _FORTIFY_SOURCE requires GCC 4.1 or later
 # elif _FORTIFY_SOURCE > 1
+#  if _FORTIFY_SOURCE > 2
+#   warning _FORTIFY_SOURCE > 2 is treated like 2 on this platform
+#  endif
 #  define __USE_FORTIFY_LEVEL 2
 # else
 #  define __USE_FORTIFY_LEVEL 1
diff --git a/manual/creature.texi b/manual/creature.texi
index be5050468b..31208ccb2b 100644
--- a/manual/creature.texi
+++ b/manual/creature.texi
@@ -254,7 +254,8 @@  included.
 @standards{GNU, (none)}
 If this macro is defined to @math{1}, security hardening is added to
 various library functions.  If defined to @math{2}, even stricter
-checks are applied.
+checks are applied. If defined to @math{3}, @theglibc{} may also use
+checks that may have an additional performance overhead.
 @end defvr
 
 @defvr Macro _REENTRANT