Ensure stack is aligned for kernel entries
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest0 of 7 patches 0 repliesNew
Patches in v1 No applies recorded yet
None of the 7 patches the cover letter announces are in this archive.
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 0/7] Ensure stack is aligned for kernel entries
Quoted 17 lines · Ard Biesheuvel
Quoted 16 lines · Julien Thierry
Hi,
Quoted 8 lines · Julien Thierry
Hi,
Having SCTLR_ELx.SA enabled requires the SP to be 16-bytes aligned before using it to access memory. When taking an exception, it is possible that the context during which the exception occured had SP mis-aligned. The entry code needs to make sure that the stack is aligned before using it to save the context.
So, as discussed in this thread:
https://www.spinics.net/lists/arm-kernel/msg688342.html
Quoted 8 lines
Quoted 4 lines
We might have the compiler provide the guarantee that SP is kept at multiples of 16-bytes throughout C functions. If this is accepted, it avoids the complexity of this series.
Yes, but we still want the build time
sizeof(pt_regs)check and perhaps other pieces of this series.
Good point.
Quoted 10 lines
Quoted 10 lines
There is just one case remaining, which is less important as it is mostly a debug concern. If we take an SP alignment fault from EL1 (due to bad implementation) we take recursive exceptions:
- Without
CONFIG_VMAP_STACK, kernel just freezes always taking SP alignment faults
- WithCONFIG_VMAP_STACKafter taking a number of exceptions, we overflow the stack and the kernel switches to the overflow stack where it finally manages to display a kernel panic message
Quoted 8 lines
Quoted 2 lines
So the question is, do we care about doing something for the above case?
So in the latter case, it is obvious from the debug output that the stack pointer was misaligned? I'd expect so, given that each recursively taken exception has the same cause, and so it would be clear what happened.
So, it is obvious that the error is a misaligned stack pointer as it is described in the ESR and as you said, we are always taking the same kind of exception.
However the ELR will get overwritten by the recursive exception and its last value will be the first instruction accessing memory through SP in the exception handler. Meaning we lost the address where the first misaligned stack access happened.
But then I don't know whether this case warrants adding complexity to the entry code just in case one day fiddles around with the SP and does not align it to 16-bytes before accessing memory (or does it while interrupts are enabled).
Quoted 3 lines
So I'm leaning towards just relying on that, given that
CONFIG_VMAP_STACKis the default, although it is unfortunate that KASAN still disables it.
Thanks,
Signature · 1 line
Julien Thierry