Commit 074bcd4
crypto: drbg - make reseeding from get_random_bytes() synchronous
get_random_bytes() usually hasn't full entropy available by the time DRBG
instances are first getting seeded from it during boot. Thus, the DRBG
implementation registers random_ready_callbacks which would in turn
schedule some work for reseeding the DRBGs once get_random_bytes() has
sufficient entropy available.
For reference, the relevant history around handling DRBG (re)seeding in
the context of a not yet fully seeded get_random_bytes() is:
commit 16b369a ("random: Blocking API for accessing
nonblocking_pool")
commit 4c78799 ("crypto: drbg - add async seeding operation")
commit 205a525 ("random: Add callback API for random pool
readiness")
commit 57225e6 ("crypto: drbg - Use callback API for random
readiness")
commit c271950 ("random: Remove kernel blocking API")
However, some time later, the initialization state of get_random_bytes()
has been made queryable via rng_is_initialized() introduced with commit
9a47249 ("random: Make crng state queryable"). This primitive now
allows for streamlining the DRBG reseeding from get_random_bytes() by
replacing that aforementioned asynchronous work scheduling from
random_ready_callbacks with some simpler, synchronous code in
drbg_generate() next to the related logic already present therein. Apart
from improving overall code readability, this change will also enable DRBG
users to rely on wait_for_random_bytes() for ensuring that the initial
seeding has completed, if desired.
The previous patches already laid the grounds by making drbg_seed() to
record at each DRBG instance whether it was being seeded at a time when
rng_is_initialized() still had been false as indicated by
->seeded == DRBG_SEED_STATE_PARTIAL.
All that remains to be done now is to make drbg_generate() check for this
condition, determine whether rng_is_initialized() has flipped to true in
the meanwhile and invoke a reseed from get_random_bytes() if so.
Make this move:
- rename the former drbg_async_seed() work handler, i.e. the one in charge
of reseeding a DRBG instance from get_random_bytes(), to
"drbg_seed_from_random()",
- change its signature as appropriate, i.e. make it take a struct
drbg_state rather than a work_struct and change its return type from
"void" to "int" in order to allow for passing error information from
e.g. its __drbg_seed() invocation onwards to callers,
- make drbg_generate() invoke this drbg_seed_from_random() once it
encounters a DRBG instance with ->seeded == DRBG_SEED_STATE_PARTIAL by
the time rng_is_initialized() has flipped to true and
- prune everything related to the former, random_ready_callback based
mechanism.
As drbg_seed_from_random() is now getting invoked from drbg_generate() with
the ->drbg_mutex being held, it must not attempt to recursively grab it
once again. Remove the corresponding mutex operations from what is now
drbg_seed_from_random(). Furthermore, as drbg_seed_from_random() can now
report errors directly to its caller, there's no need for it to temporarily
switch the DRBG's ->seeded state to DRBG_SEED_STATE_UNSEEDED so that a
failure of the subsequently invoked __drbg_seed() will get signaled to
drbg_generate(). Don't do it then.
Signed-off-by: Nicolai Stange <nstange@suse.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>1 parent 262d83a commit 074bcd4
2 files changed
Lines changed: 11 additions & 53 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1087 | 1087 | | |
1088 | 1088 | | |
1089 | 1089 | | |
1090 | | - | |
| 1090 | + | |
1091 | 1091 | | |
1092 | 1092 | | |
1093 | 1093 | | |
1094 | | - | |
1095 | | - | |
1096 | 1094 | | |
1097 | 1095 | | |
1098 | 1096 | | |
| |||
1103 | 1101 | | |
1104 | 1102 | | |
1105 | 1103 | | |
1106 | | - | |
1107 | | - | |
1108 | 1104 | | |
1109 | 1105 | | |
1110 | | - | |
1111 | | - | |
1112 | | - | |
1113 | | - | |
1114 | | - | |
1115 | | - | |
1116 | | - | |
1117 | | - | |
| 1106 | + | |
1118 | 1107 | | |
1119 | | - | |
1120 | | - | |
| 1108 | + | |
1121 | 1109 | | |
| 1110 | + | |
1122 | 1111 | | |
| 1112 | + | |
1123 | 1113 | | |
1124 | 1114 | | |
1125 | 1115 | | |
| |||
1422 | 1412 | | |
1423 | 1413 | | |
1424 | 1414 | | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
1425 | 1420 | | |
1426 | 1421 | | |
1427 | 1422 | | |
| |||
1514 | 1509 | | |
1515 | 1510 | | |
1516 | 1511 | | |
1517 | | - | |
1518 | | - | |
1519 | | - | |
1520 | | - | |
1521 | | - | |
1522 | | - | |
1523 | | - | |
1524 | | - | |
1525 | 1512 | | |
1526 | 1513 | | |
1527 | | - | |
1528 | | - | |
1529 | 1514 | | |
1530 | 1515 | | |
1531 | 1516 | | |
1532 | 1517 | | |
1533 | 1518 | | |
1534 | 1519 | | |
1535 | | - | |
1536 | | - | |
1537 | | - | |
1538 | | - | |
1539 | | - | |
1540 | | - | |
1541 | | - | |
1542 | | - | |
1543 | | - | |
1544 | | - | |
1545 | | - | |
1546 | | - | |
1547 | | - | |
1548 | | - | |
1549 | | - | |
1550 | | - | |
1551 | | - | |
1552 | | - | |
1553 | | - | |
1554 | | - | |
1555 | | - | |
| 1520 | + | |
1556 | 1521 | | |
1557 | 1522 | | |
1558 | 1523 | | |
| |||
1646 | 1611 | | |
1647 | 1612 | | |
1648 | 1613 | | |
1649 | | - | |
1650 | | - | |
1651 | | - | |
1652 | | - | |
1653 | | - | |
1654 | 1614 | | |
1655 | 1615 | | |
1656 | 1616 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
141 | 140 | | |
142 | 141 | | |
143 | 142 | | |
144 | 143 | | |
145 | | - | |
146 | 144 | | |
147 | 145 | | |
148 | 146 | | |
| |||
0 commit comments