Bug 28998 - Document -D_FORTIFY_SOURCE
Summary: Document -D_FORTIFY_SOURCE
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: manual (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Siddhesh Poyarekar
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-03-24 11:58 UTC by Martin Liska
Modified: 2023-01-10 15:25 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2022-12-08 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Liska 2022-03-24 11:58:54 UTC
Moved from: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105043

I would like to see documentation of the feature, as well as what each level (1-3) enables. If it's documented in glibc, then please provide a link to the feature.

And I would add a caveat about the usage of malloc_usable_size.
Comment 1 Adhemerval Zanella 2022-03-24 12:27:10 UTC
It is documented briefly on manual/creature.texi:

303 @defvr Macro _FORTIFY_SOURCE
304 @standards{GNU, (none)}
305 If this macro is defined to @math{1}, security hardening is added to
306 various library functions.  If defined to @math{2}, even stricter
307 checks are applied. If defined to @math{3}, @theglibc{} may also use
308 checks that may have an additional performance overhead.
309 @end defvr

But there is no further explanation of exactly each level enables, the functions covered, and how it plays with compiler.
Comment 2 Martin Liska 2022-08-02 13:24:22 UTC
@Siddhesh: May I please remind you this issue?
Comment 3 Siddhesh Poyarekar 2022-08-02 22:43:14 UTC
Do we need documentation beyond the stuff above, which appears to describe the interface to sufficient detail?  Anything more seems like implementation detail.
Comment 4 Martin Liska 2022-08-03 07:18:47 UTC
Ok, so can you please adapt the documentation entry to the GCC compiler. The macro is already mentioned in the manual page, so it would be nice having that explained. Thanks.
Comment 5 Byron Stanoszek 2022-12-06 03:45:17 UTC
I too am looking for documentation on this feature. More specifically, what is the action of the program when the check fails? Does it act like a failed assert() and call abort()? Is there a way to catch the exception like one would catch SIGSEGV using a signal handler?
Thanks.
Comment 6 Martin Liska 2022-12-08 08:52:14 UTC
(In reply to Byron Stanoszek from comment #5)
> I too am looking for documentation on this feature. More specifically, what
> is the action of the program when the check fails?

abort is called.

> Does it act like a failed
> assert() and call abort()? Is there a way to catch the exception like one
> would catch SIGSEGV using a signal handler?

Likely not, Siddhesh, please correct me if I'm wrong.

> Thanks.

Anyway, the documentation should be really improved and taken to GCC compiler as well.
Comment 7 Siddhesh Poyarekar 2022-12-08 15:04:30 UTC
(In reply to Martin Liska from comment #6)
> > Does it act like a failed
> > assert() and call abort()? Is there a way to catch the exception like one
> > would catch SIGSEGV using a signal handler?
> 
> Likely not, Siddhesh, please correct me if I'm wrong.

You could trap SIGABRT if you really really want to, but that's not a recommendation.

> > Thanks.
> 
> Anyway, the documentation should be really improved and taken to GCC
> compiler as well.

I'm going to try writing something up for the glibc manual and gcc documentation.
Comment 8 Sourceware Commits 2023-01-10 15:23:36 UTC
The master branch has been updated by Siddhesh Poyarekar <siddhesh@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=3d3a2911ba65e613eac878d8eb02a0aba4ad7651

commit 3d3a2911ba65e613eac878d8eb02a0aba4ad7651
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
Date:   Tue Jan 10 10:22:38 2023 -0500

    Add _FORTIFY_SOURCE implementation documentation [BZ #28998]
    
    There have been multiple requests to provide more detail on how the
    _FORTIFY_SOURCE macro works, so this patch adds a new node in the
    Library Maintenance section that does this.  A lot of the description is
    implementation detail, which is why I put this in the appendix and not
    in the main documentation.
    
    Resolves: BZ #28998.
    Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
    Reviewed-by: Florian Weimer <fweimer@redhat.com>
Comment 9 Siddhesh Poyarekar 2023-01-10 15:25:49 UTC
Fixed on main branch, the gcc complement of _FORTIFY_SOURCE documentation change is here:

https://gcc.gnu.org/g:b3009222b7bb26654c1e93d34e65e8f80ae20595