Skip to content
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

Consider using stack canaries via -fstack-protector* flags #86

Open
invd opened this issue Jun 26, 2021 · 2 comments
Open

Consider using stack canaries via -fstack-protector* flags #86

invd opened this issue Jun 26, 2021 · 2 comments

Comments

@invd
Copy link

invd commented Jun 26, 2021

From what I can see in the Nitrokey Pro source code, the firmware currently does not use or support the ARM GCC provided standard functionality to mitigate certain stack buffer overflows. Having suitable mitigations in place can be essential to prevent attackers from achieving code execution on the device.

I recommend adding -fstack-protector-all or -fstack-protector-strong flags as well as the relevant canary initialization in main() with random values from the TRNG random source.

A weaker form of this stack canary logic with a fixed and well-known canary value is used in the Nitrokey/nitrokey-storage-firmware@51e9ac3 . This approach can be circumvented in case the attacker has sufficient control over the buffer overflow values to re-use the expected values, so I recommend switching to randomized canaries there as well.

Please note that several ARM GCC versions have broken stack canary support, as I (re-)discovered and documented recently. To my knowledge, you are currently using the gcc-arm-none-eabi-8-2018-q4-major for your official builds based on the information in c8e20d4 . gcc-arm-none-eabi-8-2018-q4-major is not affected by this issue, but some later versions are, so I recommend taking this into consideration for the toolchain if you do include stack canaries at some point in the future.

@szszszsz
Copy link
Member

Hi!
Thank you for linking this very interesting read! We will take a look into applying the concluded fixes.
Confirming we are using not affected GCC version at the moment - 8.2.1, so only setting the flags, the canary value and testing remains.
I will create a similar ticket for the Nitrokey Storage.

@szszszsz
Copy link
Member

Update: currently merged with a static value set on the stack protector constant.
To be done:

  • get stack protector constant from the MCU's memory, updated in the previous power-cycle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants