Thursday, June 2, 2022

[SOLVED] How to disable stack canaries for specific functions?

Issue

With gcc, is it possible to compile with -fstack-protector, but omit for a specific function.

For example, say i have two functions.

void a() {
  ...
}

void b() {
  ...
}

Can I tell the compiler to compile a program that will use a canary before the saved return address of a, but no canary for b?


Solution

You'd have to test if it works (inspect the generated code at Godbolt) but it looks like you can do, for example:

__attribute__ ((no_stack_protector)) void foo () { ... }

no_sanitize looks like an intriguing option, I wonder who uses that.



Answered By - Paul Sanders
Answer Checked By - Katrina (WPSolving Volunteer)