Skip to content

Enable FORTIFY and SP for native builds#9537

Merged
thebentern merged 10 commits intomeshtastic:developfrom
EricSesterhennX41:enablefortifyandnx
Feb 9, 2026
Merged

Enable FORTIFY and SP for native builds#9537
thebentern merged 10 commits intomeshtastic:developfrom
EricSesterhennX41:enablefortifyandnx

Conversation

@EricSesterhennX41
Copy link
Contributor

meshtasticd does have an executable stack and is not built with fortify, which makes exploitation of memory corruption bugs easier than it has to be. This enables fortify and a non-executable stack.

This gives the following improvements on Debian Trixie:

$ checksec --file=./.pio/build/native/meshtasticd
RELRO STACK CANARY NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable FILE
Partial RELRO No canary found NX enabled PIE enabled No RPATH No RUNPATH 13516 Symbols No 0 17 ./.pio/build/native/meshtasticd

$ checksec --file=./.pio/build/native/meshtasticd
RELRO STACK CANARY NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable FILE
Partial RELRO Canary found NX enabled PIE enabled No RPATH No RUNPATH 13519 Symbols Yes 12 20 ./.pio/build/native/meshtasticd

Tested with --sim mode I do not get any crashes or similar.

🤝 Attestations

  • I have compile tested on native and native-tft
  • I have tested that my proposed changes behave as described.
  • I have tested that my proposed changes do not cause any obvious regressions on the following devices:
    • Native, sim mode

meshtasticd does have an executable stack and is not built with fortify, which makes exploitation of memory corruption bugs easier than it has to be. This enables fortify and a non-executable stack.

This gives the following improvements on Debian Trixie:

$ checksec --file=./.pio/build/native/meshtasticd
RELRO           STACK CANARY      NX            PIE             RPATH      RUNPATH	Symbols		FORTIFY	Fortified	Fortifiable	FILE
Partial RELRO   No canary found   NX enabled    PIE enabled     No RPATH   No RUNPATH   13516 Symbols	  No	0		17		./.pio/build/native/meshtasticd

$ checksec --file=./.pio/build/native/meshtasticd
RELRO           STACK CANARY      NX            PIE             RPATH      RUNPATH	Symbols		FORTIFY	Fortified	Fortifiable	FILE
Partial RELRO   Canary found      NX enabled    PIE enabled     No RPATH   No RUNPATH   13519 Symbols	  Yes	12		20		./.pio/build/native/meshtasticd

Tested with --sim mode I do not get any crashes or similar.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds security hardening flags to native Linux builds (meshtasticd) to make exploitation of memory corruption bugs more difficult. The changes enable FORTIFY_SOURCE level 2 and comprehensive stack protection with canaries.

Changes:

  • Added -D_FORTIFY_SOURCE=2 to enable buffer overflow detection at compile-time and runtime
  • Added -fstack-protector-all -Wstack-protector --param ssp-buffer-size=4 to enable stack canaries on all functions with aggressive 4-byte threshold

meshtasticd does have an executable stack and is not built with fortify, which makes exploitation of memory corruption bugs easier than it has to be. This enables fortify and a non-executable stack.

This gives the following improvements on Debian Trixie:

$ checksec --file=./.pio/build/native/meshtasticd
RELRO           STACK CANARY      NX            PIE             RPATH      RUNPATH	Symbols		FORTIFY	Fortified	Fortifiable	FILE
Partial RELRO   No canary found   NX enabled    PIE enabled     No RPATH   No RUNPATH   13516 Symbols	  No	0		17		./.pio/build/native/meshtasticd

$ checksec --file=./.pio/build/native/meshtasticd
RELRO           STACK CANARY      NX            PIE             RPATH      RUNPATH	Symbols		FORTIFY	Fortified	Fortifiable	FILE
Partial RELRO   Canary found      NX enabled    PIE enabled     No RPATH   No RUNPATH   13519 Symbols	  Yes	12		20		./.pio/build/native/meshtasticd

Tested with --sim mode I do not get any crashes or similar.
@vidplace7 vidplace7 requested a review from Jorropo February 5, 2026 13:13
@Jorropo Jorropo changed the title Enable FORITFY and NX for native builds Enable FORTIFY and NX for native builds Feb 5, 2026
Copy link
Member

@Jorropo Jorropo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The title looks wrong, NX should be enabled by default.
I think stack-protector-all enables stack cookies.

This has a CPU performance hit altho meshtastic isn't a performance heavy app.

Imo theses are pretty lame compared to using a memory safe language, but I don't really see a reason to not enable them.
It will cause more crashes, but that in situations where we are doing something bad, and users will hopefully report bugs to us rather than them going unnoticed.

@EricSesterhennX41
Copy link
Contributor Author

Sorry yes, my morning brain confused NX and SP. Should I create a new PR?

@Jorropo
Copy link
Member

Jorropo commented Feb 5, 2026

No need, you can change the title by clicking the edit button to the right of the PR title. 🙂

@EricSesterhennX41
Copy link
Contributor Author

I think that is no longer possible due to the merge with the current upstream branch.

@Jorropo
Copy link
Member

Jorropo commented Feb 5, 2026

? shouldn't

Do you mean git push ?
Try git push --force

EricSesterhennX41 and others added 3 commits February 5, 2026 16:04
meshtasticd does have a stack canaries and is not built with fortify, which makes exploitation of memory corruption bugs easier than it has to be. This enables fortify and stack canaries.

This gives the following improvements on Debian Trixie:

$ checksec --file=./.pio/build/native/meshtasticd
RELRO           STACK CANARY      NX            PIE             RPATH      RUNPATH	Symbols		FORTIFY	Fortified	Fortifiable	FILE
Partial RELRO   No canary found   NX enabled    PIE enabled     No RPATH   No RUNPATH   13516 Symbols	  No	0		17		./.pio/build/native/meshtasticd

$ checksec --file=./.pio/build/native/meshtasticd
RELRO           STACK CANARY      NX            PIE             RPATH      RUNPATH	Symbols		FORTIFY	Fortified	Fortifiable	FILE
Partial RELRO   Canary found      NX enabled    PIE enabled     No RPATH   No RUNPATH   13519 Symbols	  Yes	12		20		./.pio/build/native/meshtasticd

Tested with --sim mode I do not get any crashes or similar.
@Jorropo Jorropo changed the title Enable FORTIFY and NX for native builds Enable FORTIFY and SP for native builds Feb 6, 2026
@thebentern thebentern merged commit 73adeee into meshtastic:develop Feb 9, 2026
77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request needs-review Needs human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants