feature_test_macros.7: document -D_FORTIFY_SOURCE=3
PATCH 1/1 feature_test_macros.7: document -D_FORTIFY_SOURCE=3
Reference: https://developers.redhat.com/blog/2021/04/16/broadening-compiler-checks-for-buffer-overflows-in-_fortify_source
Reference: https://developers.redhat.com/articles/2022/09/17/gccs-new-fortification-level
--- man7/feature_test_macros.7 | 11 +++++++++++ 1 file changed, 11 insertions(+)
man7/feature_test_macros.7 +11 -0
@@ -643,9 +643,20 @@ and result in compiler warnings; other checks take place at run time, and result in a run-time error if the check fails. .IP +With +.B _FORTIFY_SOURCE +set to 3, additional checking is added to capture some function +calls used with an argument of variable size. +.IP Use of this macro requires compiler support, available with .BR gcc (1) since version 4.0. +.IP +For use of +.B _FORTIFY_SOURCE +set to 3, then +.BR gcc (1) +version 12.0 or later is required. .SS Default definitions, implicit definitions, and combining definitions If no feature test macros are explicitly defined, then the following feature test macros are defined by default:
Signature · 1 line
2.38.0
Hi Sam,
Quoted 12 lines · Sam James
Reference: https://developers.redhat.com/blog/2021/04/16/broadening-compiler-checks-for-buffer-overflows-in-_fortify_source
Reference: https://developers.redhat.com/articles/2022/09/17/gccs-new-fortification-levelSigned-off-by Sam James <[email protected]>--- man7/feature_test_macros.7 | 11 +++++++++++ 1 file changed, 11 insertions(+)man7/feature_test_macros.7 +0
-0
man7/feature_test_macros.7 and result in compiler warnings; · line 648
Quoted 6 lines
man7/feature_test_macros.7 +3
-0@@ -643,9 +643,20 @@ and result in compiler warnings; other checks take place at run time, and result in a run-time error if the check fails. .IP +With +.B _FORTIFY_SOURCE +set to 3, additional checking is added to capture some function
What do you mean by "capture"?
Cheers,
Alex
Quoted 14 lines
man7/feature_test_macros.7 +8
-0+calls used with an argument of variable size. +.IP Use of this macro requires compiler support, available with .BR gcc (1) since version 4.0. +.IP +For use of +.B _FORTIFY_SOURCE +set to 3, then +.BR gcc (1) +version 12.0 or later is required. .SS Default definitions, implicit definitions, and combining definitions If no feature test macros are explicitly defined, then the following feature test macros are defined by default:
Signature · 1 line
<http://www.alejandro-colomar.es/>
Quoted 18 lines · Alejandro Colomar
Hi Sam,
Quoted 11 lines · Sam James
Reference: https://developers.redhat.com/blog/2021/04/16/broadening-compiler-checks-for-buffer-overflows-in-_fortify_source
Reference: https://developers.redhat.com/articles/2022/09/17/gccs-new-fortification-levelSigned-off-by Sam James <[email protected]>--- man7/feature_test_macros.7 | 11 +++++++++++ 1 file changed, 11 insertions(+)man7/feature_test_macros.7 +0
-0@@ -643,9 +643,20 @@ and result in compiler warnings;
Quoted 9 lines
man7/feature_test_macros.7 and result in compiler warnings; · line 648
Quoted 6 lines
man7/feature_test_macros.7 +3
-0other checks take place at run time, and result in a run-time error if the check fails. .IP +With +.B _FORTIFY_SOURCE +set to 3, additional checking is added to capture some functionWhat do you mean by "capture"?
Maybe "capture" is not the best word. Maybe hooked / intercepted is better?
F_S=3 lets cases where say, malloc size is based on a variable, still get detected because the compiler recognises such cases and adds scaffolding in to hook the functions.
(The malloc example at
https://developers.redhat.com/articles/2022/09/17/gccs-new-fortification-level#1__a_new_builtin_provides_enhanced_buffer_size_detection
is what I'm referring to).
To be clear though: the semantics are similar to FORTIFY_SOURCE=2, it's just that FORITFY_SOURCE=3 uses an extra bit of information (__builtin_dynamic_object_size) to hook more cases.
So whatever word works for FORTIFY_SOURCE < 3 works for 3 too.
I'm definitely feeling like "capture" is not the best word but I'm struggling for the right one.
--
Additional question: there's actually some confusing constraints about when we can use F_S=3.
It needs GCC 12 or Clang 9 as a compiler,
and >= glibc-2.34.
musl does not, at this time, support any
built-in fortification. I don't know if we should
mention that part.
Quoted 3 lines
Cheers,
Alex
Best,
sam
Hi Sam,
Quoted 22 lines · Sam James
Quoted 12 lines · Sam James
Quoted 11 lines
Reference: https://developers.redhat.com/blog/2021/04/16/broadening-compiler-checks-for-buffer-overflows-in-_fortify_source
Reference: https://developers.redhat.com/articles/2022/09/17/gccs-new-fortification-levelSigned-off-by Sam James <[email protected]>--- man7/feature_test_macros.7 | 11 +++++++++++ 1 file changed, 11 insertions(+)man7/feature_test_macros.7 +0
-0@@ -643,9 +643,20 @@ and result in compiler warnings;Quoted 9 lines
man7/feature_test_macros.7 and result in compiler warnings; · line 648
Quoted 6 lines
man7/feature_test_macros.7 +3
-0other checks take place at run time, and result in a run-time error if the check fails. .IP +With +.B _FORTIFY_SOURCE +set to 3, additional checking is added to capture some functionWhat do you mean by "capture"?
Quoted 2 lines
Maybe "capture" is not the best word. Maybe hooked / intercepted is better?
Yeah intercepted might be better.
Quoted 4 lines
F_S=3 lets cases where say, malloc size is based on a variable, still get detected because the compiler recognises such cases and adds scaffolding in to hook the functions.
Adding something like this to the page might be helpful.
Quoted 8 lines
(The malloc example at
https://developers.redhat.com/articles/2022/09/17/gccs-new-fortification-level#1__a_new_builtin_provides_enhanced_buffer_size_detection
is what I'm referring to).To be clear though: the semantics are similar to FORTIFY_SOURCE=2, it's just that FORITFY_SOURCE=3 uses an extra bit of information (
__builtin_dynamic_object_size) to hook more cases.
Maybe this is interesting (although maybe a bit too much into implementation details.
I'd like to know, from the point of view of a user who knows little about the different fortify levels (that actually matches me quite well :), what would be the constant differences (i.e., ones that the compiler will respect in the future (if there are any). What kind of guarantees there are or not.
Quoted 5 lines
So whatever word works for
FORTIFY_SOURCE< 3 works for 3 too.I'm definitely feeling like "capture" is not the best word but I'm struggling for the right one.
If you're not inspired now, I'm fine adding whatever you want to add now; and we can revise it in the future. That's fine.
Quoted 11 lines
--
Additional question: there's actually some confusing constraints about when we can use F_S=3.It needs GCC 12 or Clang 9 as a compiler,
and >= glibc-2.34.musl does not, at this time, support any
built-in fortification. I don't know if we should
mention that part.
For sure. I was considering mailing musl maintainers to suggest that we could officially/consistently document musl, as it's become an important libc alternative in Linux distros.
Cheers,
Alex
Signature · 1 line
<http://www.alejandro-colomar.es/>
Quoted 5 lines · Alejandro Colomar
Hi Sam,
Hi!
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
[snip]
Maybe "capture" is not the best word. Maybe hooked / intercepted is better?
Yeah intercepted might be better.
Done.
Quoted 5 lines
Quoted 3 lines
F_S=3 lets cases where say, malloc size is based on a variable, still get detected because the compiler recognises such cases and adds scaffolding in to hook the functions.
Adding something like this to the page might be helpful.
I've put it in -- please let me know if it's helpful as-is or not.
Quoted 9 lines
Quoted 7 lines
(The malloc example at
https://developers.redhat.com/articles/2022/09/17/gccs-new-fortification-level#1__a_new_builtin_provides_enhanced_buffer_size_detection
is what I'm referring to).
To be clear though: the semantics are similar to FORTIFY_SOURCE=2, it's just that FORITFY_SOURCE=3 uses an extra bit of information (__builtin_dynamic_object_size) to hook more cases.Maybe this is interesting (although maybe a bit too much into implementation details.
I'll leave this part out for now, but keep the reference in the commit message.
Quoted 3 lines
I'd like to know, from the point of view of a user who knows little about the different fortify levels (that actually matches me quite well :), what would be the constant differences (i.e., ones that the compiler will respect in the future (if there are any). What kind of guarantees there are or not.
What do you think about the latest state (I'll send v2 now)?
It's hard because it's reliant on what the compiler can deduce, but the general idea is that it can go a step beyond and try to come up with an upper bound based on a variable, even if it can't get the exact size right, so it at least knows if you overshoot by a lot now.
Quoted 15 lines
Quoted 3 lines
So whatever word works for
FORTIFY_SOURCE< 3 works for 3 too. I'm definitely feeling like "capture" is not the best word but I'm struggling for the right one.If you're not inspired now, I'm fine adding whatever you want to add now; and we can revise it in the future. That's fine.
Quoted 8 lines
--
Additional question: there's actually some confusing constraints about when we can use F_S=3.
It needs GCC 12 or Clang 9 as a compiler, and >= glibc-2.34.
musl does not, at this time, support any built-in fortification. I don't know if we should mention that part.
Quoted 2 lines
For sure. I was considering mailing musl maintainers to suggest that we could officially/consistently document musl, as it's become an important libc alternative in Linux distros.
I think this is a good idea. They might say the POSIX man pages should serve as documentation enough, but I think specifically documenting it will be useful -- not just for this fortification bit, but another example is actually time64 -- musl made a hard break in 1.2.x, hence no need for macros.
I feel like that sort of information is useful for people so you have my full support in that and I'm happy to help.
Best,
sam