4 ms·
Why doesn't the vDSO code just use MOV in its stack probe probe rather than an OR?
by cwzwarich 9y ago
Why doesn't the vDSO code just use MOV in its stack probe probe rather than an OR?
- rocqua 9y agoMy best guess would be to prevent the 'useless instruction' from being optimized out, but an or with 0 is still useless, and I don't see what optimizer lies between this GCC feature and the final binary. Maybe the segfault only occurs on a write?
- jicks 9y agoApparently, because it's shorter [0]. [0]: See https://lkml.org/lkml/2017/11/10/348 https://lkml.org/lkml/2017/11/10/348
- cwzwarich 9y agoWhy is it shorter? Both MOV and OR have one byte encodings, and with the OR you either have to use an immediate zero (which burns a byte) or materialize zero in some other way. As that email points out, the entire sequence would be shorter using a different addressing mode anyways. And a read-modify-write is definitely slower at runtime.
- simcop2387 9y agoI wonder if it's because it's safer in that it doesn't change anything there if you've gone over the stack limit and into the heap? I know that -fstack-protect was designed a long time ago, possible before guard pages and before 64bit addressing.
- amluto 9y agoBecause gcc's -fstack-check is garbage. Gentoo Hardened should not be using it.
- exikyut 9y agoFrom https://lkml.org/lkml/2017/11/10/310 https://lkml.org/lkml/2017/11/10/310, discussing the disassembly: > This code is so wrong I don't even no where to start. ... I suppose we could try to make the kernel fail to build at all on a broken configuration like this.
- stmw 9y agoVery good point. Key phrase is "an offset > 4096 is just bogus. That's big enough to skip right over the guard page" - if allocating more than a page-size-worth (4K in most cases), it should try to write to it before returning.
- marcan_42 9y agoIt isn't. -fstack-check consistently checks the stack at a 4K offset. It wasn't designed for Stack Clash protection, but in practice, it works as long as all the code was compiled with it (which on Gentoo Hardened, it would be, at least for typical C/C++ apps). The whole stack is still being probed (except perhaps the first page), it's just being probed ahead of actually being used. The caller was responsible for probing the space up to that 4K offset. It's counterintuitive, but in practice it works as an effective mitigation (and it exists already, so Gentoo might as well use it until real Stack Clash specific protection lands in GCC). Edit: to give an example: if a function uses 6K of stack space, then -fstack-check will probe pages from [SP+4K] to [SP+10K]. [SP] through [SP+4K] are assumed already probed by the call chain, and the [SP+4K] through [SP+6K] region is being probed explicitly. In the end, nothing gets skipped over.
- stmw 9y agoOh, I was imagining that referred to a situation where you have a stack (say 8K to keep it aligned), then a 4K guard page (which faults when you grow past it), and then someone probes past it, at 16K. Which may be mapped to all kinds of other things, no?
- 9y ago
- simooooo 9y agoThis guy is a class act. Smart AF