<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/80236>80236</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Stack protector should have a trapping mode
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
matheusmoreira
</td>
</tr>
</table>
<pre>
The current implementation of the stack smashing protection machinery references the `__stack_chk_fail` symbol, thereby requiring that this function be defined. This is not always desirable. There should also be an alternative code generation mode which uses `__builtin_trap` instead.
Rich Felker [wrote] in the GCC Bugzilla in 2020:
> This is less secure than it could be, since it depends on the ability to make function calls (and possibly operate on global data and make syscalls in the callee) in a process whose state is compromised.
>
> For example the GOT entries used by PLT could be clobbered or `%gs:0x10` (i386 syscall vector) could be clobbered by the same stack-based overflow that caused the stack protector event in the first place.
This feature would also make the stack smashing protection machinery much easier to integrate with in `-ffreestanding -nostdlib` programs. Various sanitizers already have support for trap instruction generation:
> `-fsanitize-trap[=opts]`
>
> The `-fsanitize-trap=` option instructs the compiler to report for sanitizers
> mentioned in comma-separated list of opts undefined behavior using
> `__builtin_trap` rather than a `libubsan` library routine.
>
> The advantage of this is that the `libubsan` library is not needed and is not
> linked in, so this is usable even in freestanding environments.
This feature would be the stack smashing protector equivalent.
References:
- [GCC Bug 93509 - Stack protector should offer trap-only handling][gcc.bug.93509]
- [GCC Stack smashing protection][gccint]
[wrote]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93509#c0
[gcc.bug.93509]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93509
[gccint]: https://gcc.gnu.org/onlinedocs/gccint/Stack-Smashing-Protection.html
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVsFy2zYQ_RrosiMNRVqydNDBjqNeOtNM4-nVswBXJGoQYLCgFOXrOwsyUuzYTQ-9yEOA-_D24e0zkdk2nminVvdq9TDDIbU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