linuxkm: wolfcrypt/src/memory.c: in {save,restore}_vector_registers_x86(), allow for recursive calls (some crypto calls are recursive).

This commit is contained in:
Daniel Pouzzner
2021-10-18 23:34:35 -05:00
parent fc73c6dbea
commit ad4c200cd2

View File

@ -1241,16 +1241,18 @@ union fpregs_state **wolfcrypt_irq_fpu_states = NULL;
return BAD_STATE_E; return BAD_STATE_E;
} }
/* check for nested interrupts -- doesn't exist on x86, but make /* allow for recursive calls (some crypto calls are recursive) */
* sure, in case something changes. if (((unsigned char *)wolfcrypt_irq_fpu_states[processor_id])[PAGE_SIZE-1] != 0) {
*/ if (((unsigned char *)wolfcrypt_irq_fpu_states[processor_id])[PAGE_SIZE-1] == 255) {
if (((char *)wolfcrypt_irq_fpu_states[processor_id])[PAGE_SIZE-1] != 0) { preempt_enable();
preempt_enable(); pr_err("save_vector_registers_x86 recursion register overflow for "
pr_err("save_vector_registers_x86 called recursively for " "cpu id %d.\n", processor_id);
"cpu id %d.\n", processor_id); return BAD_STATE_E;
return BAD_STATE_E; } else {
++((char *)wolfcrypt_irq_fpu_states[processor_id])[PAGE_SIZE-1];
return 0;
}
} }
/* note, fpregs_lock() is not needed here, because /* note, fpregs_lock() is not needed here, because
* interrupts/preemptions are already disabled here. * interrupts/preemptions are already disabled here.
*/ */
@ -1292,12 +1294,14 @@ union fpregs_state **wolfcrypt_irq_fpu_states = NULL;
int processor_id = __smp_processor_id(); int processor_id = __smp_processor_id();
if ((wolfcrypt_irq_fpu_states == NULL) || if ((wolfcrypt_irq_fpu_states == NULL) ||
(wolfcrypt_irq_fpu_states[processor_id] == NULL) || (wolfcrypt_irq_fpu_states[processor_id] == NULL) ||
(((char *)wolfcrypt_irq_fpu_states[processor_id])[PAGE_SIZE-1] == 0)) (((unsigned char *)wolfcrypt_irq_fpu_states[processor_id])[PAGE_SIZE-1] == 0))
{ {
pr_err("restore_vector_registers_x86 called for cpu id %d " pr_err("restore_vector_registers_x86 called for cpu id %d "
"without saved context.\n", processor_id); "without saved context.\n", processor_id);
preempt_enable(); /* just in case */ preempt_enable(); /* just in case */
return; return;
} else if (--((unsigned char *)wolfcrypt_irq_fpu_states[processor_id])[PAGE_SIZE-1] > 0) {
return;
} else { } else {
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 14, 0) #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 14, 0)
copy_kernel_to_fpregs(wolfcrypt_irq_fpu_states[processor_id]); copy_kernel_to_fpregs(wolfcrypt_irq_fpu_states[processor_id]);