Skip to content

enable hardening=+all and FORTIFY_SOURCE=3 - #349

Merged
lolyu merged 3 commits into
sonic-net:masterfrom
xq9mend:fix/gcc-fortify-source-3
Jul 5, 2026
Merged

enable hardening=+all and FORTIFY_SOURCE=3#349
lolyu merged 3 commits into
sonic-net:masterfrom
xq9mend:fix/gcc-fortify-source-3

Conversation

@xq9mend

@xq9mend xq9mend commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Why I did it

Enable the full set of dpkg-buildflags hardening options and upgrade FORTIFY_SOURCE to level 3.

hardening=+all enables -fstack-protector-strong, RELRO, NX, and related flags. FORTIFY_SOURCE=3 provides stronger compile-time buffer overflow detection than the dpkg default of =2. The -U flag clears the existing =2 before setting =3 to avoid duplicate-definition warnings.

How I did it

  • debian/rules: add DEB_BUILD_MAINT_OPTIONS = hardening=+all and DEB_CPPFLAGS_MAINT_APPEND = -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3

How to verify it

Build the package and confirm -D_FORTIFY_SOURCE=3 appears in compiler invocations.

Add DEB_BUILD_MAINT_OPTIONS = hardening=+all to enable the full set
of dpkg-buildflags hardening options (-fstack-protector-strong,
RELRO, NX, etc.), and upgrade FORTIFY_SOURCE to level 3.

dpkg sets FORTIFY_SOURCE=2 by default; the -U flag clears it before
setting =3 to avoid duplicate-definition warnings.

Signed-off-by: xq9mend <xq9mend@users.noreply.github.com>
@xq9mend
xq9mend requested review from lolyu and zjswhhh as code owners July 2, 2026 00:52
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator

Hi, there are workflow run(s) waiting for approval, you may be first-time contributor. I will notify maintainers to help approve once PR is approved. Thanks!

---Powered by SONiC BuildBot

@zjswhhh

zjswhhh commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

what is the motivation of this pr?

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@xq9mend

xq9mend commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

This PR enables the OpenSSF Compiler Options Hardening Guide baseline for this package. The flags improve exploit mitigation (stack clash protection, control-flow integrity, full RELRO, FORTIFY_SOURCE=3) and align with hardening standards recommended for production C/C++ code. Similar changes are being applied across sonic-net repos.

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@lolyu
lolyu merged commit 298adcd into sonic-net:master Jul 5, 2026
10 checks passed
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.

4 participants