Page MenuHomeFreeBSD

armv8rng: Fix an inverted test in random_rndr_read_one()
ClosedPublic

Authored by markj on Tue, Dec 16, 7:56 PM.
Tags
None
Referenced Files
F140202606: D54259.diff
Sun, Dec 21, 9:51 AM
Unknown Object (File)
Sat, Dec 20, 11:13 AM
Unknown Object (File)
Sat, Dec 20, 2:19 AM
Unknown Object (File)
Thu, Dec 18, 2:08 AM
Unknown Object (File)
Thu, Dec 18, 1:59 AM
Unknown Object (File)
Thu, Dec 18, 12:20 AM
Subscribers

Details

Summary

If we get a random number, the NZCV is set to 0b0000. Then
"cset %w1, ne" will test whether Z == 0 and set %w1 to 1 if so.
More specifically, "cset %w1, ne" maps to "csinc %w1, wzr, wzr, eq",
which stores 0 in %w1 when NZCV == 0b0100 and 1 otherwise.

Thus, on a successful read we expect ret != 0, so the loop condition
needs to be fixed.

Fixes: 9eecef052155 ("Add an Armv8 rndr random number provider")
Reported by: Kevin Day <kevin@your.org>

Test Plan

I have no hardware to test this with.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 69316
Build 66199: arc lint + arc unit

Event Timeline

markj requested review of this revision.Tue, Dec 16, 7:56 PM

So the current code tries 10 times to hit a failure, and will use the last value if all 10 reads succeeded, given the condition after the loop is correct? Importantly, there's no security issue here, because we didn't actually report a successful read when it failed?

So the current code tries 10 times to hit a failure, and will use the last value if all 10 reads succeeded, given the condition after the loop is correct? Importantly, there's no security issue here, because we didn't actually report a successful read when it failed?

Yes, I think that's right. At worst we are not getting entropy because reading the register 10 times back-to-back causes a failure. Our default CSPRNG by design draws entropy from many different sources, so this isn't catastrophic.

This revision is now accepted and ready to land.Thu, Dec 18, 12:59 PM