get_random_seed in attestation_rnd.c could fail depending on Arm Architecture Reference Manual
Closed this issue · 3 comments
During cold boot, function calls attestaion_init->attest_rnd_prng_init->get_random_seed->arch_collect_entropy
in order. The arch_collect_entropy
return false when RNDR sets NZCV to 0b0100 and it causes the whole attestation_init
process to fail.
static inline bool arch_collect_entropy(uint64_t *random)
{
unsigned long rc;
uint64_t val;
asm volatile(
" mrs %[val], " __XSTRING(RNDR) "\n"
" str %[val], %[random_ptr]\n"
" cset %[rc], ne\n" /* RNDR sets NZCV to 0b0100 on failure */
: [random_ptr] "=m" (*random),
[rc] "=r" (rc),
[val] "=r" (val)
:
: "cc"
);
return (rc == 1UL);
}
Related description can be found in the Arm Reference Manual in C6.1.4 under "Effect of random number generation instructions on Condition flags". However, I notice there is note just below it:
The definition of "reasonable period of time" is IMPLEMENTATION DEFINED. The expectation is that software might use this as an opportunity to reschedule or run a different routine, perhaps after a small number of retries have failed to return a valid value.
Does it mean the RNDR instruction may fail and software should retry it a few times after a failure?
Hi Yiwei,
Thanks for reporting the issue.
Yes SW should retry RNDR instruction if it fails,
we have similar logic in pauth_init_enable_el2, which can be replicated in get_random_seed.
I will be making the changes.
Thanks
Internal ref : https://jira.arm.com/browse/GENFW-8915
The gerrit ref is https://review.trustedfirmware.org/c/TF-RMM/tf-rmm/+/28035