ANDROID: Setting up GS before calling __restore_processor_state.

Android Common Kernel compiled by clang with Shadow Call Stack will
use GS segment. However, __restore_processor_state is called when
system wakes up from S3 and at the moment GS is not restored yet.

This is a hack by copying a small code snippet(setting gs base) from
__restore_processor_state to restore_processor_state. It prepares GS
before __restore_processor_state is called. At the same time,
restore_processor_state is still small enough so that SCS is not on,
as SCS seems to be on only for large functions.

Bug: 166163480
Change-Id: I3bfe4ac61dee876da57de6578c9a7f01431a1743
Signed-off-by: Haitao Shan <hshan@google.com>
This commit is contained in:
Haitao Shan 2020-09-09 16:21:38 -07:00
parent ae73f6551a
commit 6767ebd98b

View File

@ -274,6 +274,19 @@ static void notrace __restore_processor_state(struct saved_context *ctxt)
/* Needed by apm.c */
void notrace restore_processor_state(void)
{
#ifdef __clang__
// The following code snippet is copied from __restore_processor_state.
// Its purpose is to prepare GS segment before the function is called.
// Since the function is compiled with SCS on, it will use GS at its
// entry.
// TODO: Hack to be removed later when compiler bug is fixed.
#ifdef CONFIG_X86_64
wrmsrl(MSR_GS_BASE, saved_context.kernelmode_gs_base);
#else
loadsegment(fs, __KERNEL_PERCPU);
loadsegment(gs, __KERNEL_STACK_CANARY);
#endif
#endif
__restore_processor_state(&saved_context);
}
#ifdef CONFIG_X86_32