Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable stack canaries for specific functions?

Tags:

c

gcc

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?

like image 434
Oliver Avatar asked Oct 21 '25 17:10

Oliver


1 Answers

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.

like image 72
Paul Sanders Avatar answered Oct 23 '25 06:10

Paul Sanders