CompilerFlags

Differences between revisions 6 and 8 (spanning 2 versions)
Revision 6 as of 2008-05-02 21:52:03
Size: 3460
Editor: c-76-105-157-155
Comment:
Revision 8 as of 2008-05-02 22:05:34
Size: 4043
Editor: c-76-105-157-155
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
This page documents the Ubuntu-specific default compiler flags in the toolchain. Based on the work from GccSsp, [:Security/HardeningWrapper], and DistCompiler. Please attempt to fix a source package's problems before disabling a given compiler feature. This page documents the Ubuntu-specific default compiler flags in the toolchain. Based on the work from GccSsp, [:Security/HardeningWrapper], and DistCompilerFlags. Please attempt to fix a source package's problems before disabling a given compiler feature, and document the package and bug numbers in the Problems section below.
Line 23: Line 23:
First enabled in Ubuntu 8.10. See [:Security/FortifySource] for further details. Most problems are related to common unsafe uses of certain libc functions. First enabled in Ubuntu 8.10. Most problems are related to common unsafe uses of certain libc functions.
Line 29: Line 29:
  The return value from {{{system()}}} functions should be evaluated and handled appropriately.   The return value from {{{system()}}} functions should be evaluated and handled appropriately, or discarded with a {{{(void)}}} cast if the result can actually be safely ignored.
Line 67: Line 67:
warning: format ‘%s’ expects type ‘char *’, but argument 3 has type ‘int’
}}}
  For packages that aren't already building with {{{-Wall}}}, format character to argument types will be checked. Verify the correct variables for a given format string.

 {{{
Line 69: Line 74:
Line 88: Line 92:

= Problems =
Please open FTBFS bugs and tag them with "hardening-ftbfs". If a compiler option bust be disabled instead of finding a correct fix, document the packages, work-around, and reasons here:

This page documents the Ubuntu-specific default compiler flags in the toolchain. Based on the work from GccSsp, [:Security/HardeningWrapper], and DistCompilerFlags. Please attempt to fix a source package's problems before disabling a given compiler feature, and document the package and bug numbers in the Problems section below.

-fstack-protector

First enabled in Ubuntu 6.10. See GccSsp for further details. Most problems are related to packages that do not use stdlib directly (kernel modules, certain libraries, etc).

Failure examples:

  • '__stack_chk_fail' symbol not found
    • Indicates a program was compiled to expect to have the stdlib available, but did not.
    *** stack smashing detected ***
    Aborted
    • A function did not correctly maintain its stack variables. Usually indicates a stack buffer overflow.

Disabled with -fno-stack-protector or -nostdlib in CPPFLAGS.

-D_FORTIFY_SOURCE=2

First enabled in Ubuntu 8.10. Most problems are related to common unsafe uses of certain libc functions.

Failure examples:

  • error: ignoring return value of 'int system(const char*)', declared with attribute warn_unused_result
    • The return value from system() functions should be evaluated and handled appropriately, or discarded with a (void) cast if the result can actually be safely ignored.

    error: call to '__open_missing_mode' declared with attribute error: open with O_CREAT in second argument needs 3 arguments
    • When using open() with O_CREAT, best-practice is to define a valid mode argument.

    warning: call to ‘__read_chk_warn’ declared with attribute warning: read called with bigger length than size of the destination buffer
    • The call to read() was done into a buffer with the wrong size. Double-check the size argument and the buffer size.

    warning: passing argument 1 of 'memcpy' discards qualifiers from pointer target type
    warning: passing argument 1 of 'strcpy' discards qualifiers from pointer target type
    *** %n in writable segment detected ***
    Aborted
    • Use of "%n" in a format string is limited to read-only memory (not stack or heap allocated strings).

    *** buffer overflow detected ***
    Aborted
    • A call to sprintf should be changed to use snprintf, or a too-small buffer was read into (see read() warnings above).

Reduced checking via -D_FORTIFY_SOURCE=1 in CPPFLAGS. Disabled with -U_FORTIFY_SOURCE or -D_FORTIFY_SOURCE=0 in CPPFLAGS.

-Wformat -Wformat-security

First enabled in Ubuntu 8.10. These options should only cause build failures if the package is compiling with -Werror.

Failure examples:

  • warning: format ‘%s’ expects type ‘char *’, but argument 3 has type ‘int’
    • For packages that aren't already building with -Wall, format character to argument types will be checked. Verify the correct variables for a given format string.

    warning: format not a string literal and no format arguments
    • This is caused by code that forgot to use "%s" for a *printf function. For example:

      • fprintf(stderr,buf);
      should be:
      • fprintf(stderr,"%s",buf);

Disabled with -Wno-format-security or -Wformat=0 in CPPFLAGS.

-Wl,-z,relro

First enabled in Ubuntu 8.10. This option paves the way for using -z now to further harden long-running programs like daemons.

No known failure examples.

Disabled with -Wl,-z,norelro in LDFLAGS.

Problems

Please open FTBFS bugs and tag them with "hardening-ftbfs". If a compiler option bust be disabled instead of finding a correct fix, document the packages, work-around, and reasons here:

ToolChain/CompilerFlags (last edited 2024-03-22 22:52:13 by eslerm)