Skip to content

Build/security: Try FORTIFY_SOURCE #3575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2022

Conversation

lgritz
Copy link
Collaborator

@lgritz lgritz commented Sep 30, 2022

Add a new build-time cmake cache variable: FORTIFY_SOURCE

Default to empty, but can be set to 1, 2, or 3, corresponding to setting the _FORTIFY_SOURCE macro available in recent versions of clang and gcc. (I'm not sure exactly which minimum compiler version is needed for each fortification level, except that for level 3, gcc must be 12+.)

Fortification involves replacing several "unsafe" memory-related functions such as memcpy, memset, strcpy, etc, with special versions that do bounds checking, aided by some compiler smarts for understanding the likely bounds of different buffers. If I understand correctly, at level 2 it can figure out bounds of constant-sized arrays, and at level 3 it can figure out certain dynamic cases as well.

There are two use cases for this:

  1. For our own CI, this is yet another bit of static and dynamic anslysis to enable (currently, just in the gcc12 test) to possibly catch bugs.

  2. Users who are building OIIO to deploy it in security-sensitive environment may wish to build with some fortification level enabled to help prevent certain memory errors or security issues, understanding that it may slightly impact performance.

Add a new build-time cmake cache variable: FORTIFY_SOURCE

Default to empty, but can be set to 1, 2, or 3, corresponding to
setting the _FORTIFY_SOURCE macro available in recent versions of
clang and gcc. (I'm not sure exactly which minimum compiler version is
needed for each fortification level, except that for level 3, gcc must
be 12+.)

Fortification involves replacing several "unsafe" memory-related
functions such as memcpy, memset, strcpy, etc, with special versions
that do bounds checking, aided by some compiler smarts for
understanding the likely bounds of different buffers. If I understand
correctly, at level 2 it can figure out bounds of constant-sized
arrays, and at level 3 it can figure out certain dynamic cases as
well.

There are two use cases for this:

1. For our own CI, this is yet another bit of static and dynamic
anslysis to enable (currently, just in the gcc12 test) to possibly
catch bugs.

2. Users who are building OIIO to deploy it in security-sensitive
environment may wish to build with some fortification level enabled to
help prevent certain memory errors or security issues, understanding
that it may slightly impact performance.
@lgritz lgritz merged commit 33c0181 into AcademySoftwareFoundation:master Oct 4, 2022
@lgritz lgritz deleted the lg-fortify branch October 5, 2022 00:08
lgritz added a commit to lgritz/OpenImageIO that referenced this pull request Oct 7, 2022
Add a new build-time cmake cache variable: FORTIFY_SOURCE

Default to empty, but can be set to 1, 2, or 3, corresponding to
setting the _FORTIFY_SOURCE macro available in recent versions of
clang and gcc. (I'm not sure exactly which minimum compiler version is
needed for each fortification level, except that for level 3, gcc must
be 12+.)

Fortification involves replacing several "unsafe" memory-related
functions such as memcpy, memset, strcpy, etc, with special versions
that do bounds checking, aided by some compiler smarts for
understanding the likely bounds of different buffers. If I understand
correctly, at level 2 it can figure out bounds of constant-sized
arrays, and at level 3 it can figure out certain dynamic cases as
well.

There are two use cases for this:

1. For our own CI, this is yet another bit of static and dynamic
anslysis to enable (currently, just in the gcc12 test) to possibly
catch bugs.

2. Users who are building OIIO to deploy it in security-sensitive
environment may wish to build with some fortification level enabled to
help prevent certain memory errors or security issues, understanding
that it may slightly impact performance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant