Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

hwrng: core - Remove add_early_randomness

A potential deadlock was reported with the config file at

https://web.archive.org/web/20240522052129/https://0x0.st/XPN_.txt

In this particular configuration, the deadlock doesn't exist because
the warning triggered at a point before modules were even available.
However, the deadlock can be real because any module loaded would
invoke async_synchronize_full.

The issue is spurious for software crypto algorithms which aren't
themselves involved in async probing. However, it would be hard to
avoid for a PCI crypto driver using async probing.

In this particular call trace, the problem is easily avoided because
the only reason the module is being requested during probing is the
add_early_randomness call in the hwrng core. This feature is
vestigial since there is now a kernel thread dedicated to doing
exactly this.

So remove add_early_randomness as it is no longer needed.

Reported-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
Reported-by: Eric Biggers <ebiggers@kernel.org>
Fixes: 1b6d7f9eb150 ("tpm: add session encryption protection to tpm2_get_random()")
Link: https://lore.kernel.org/r/119dc5ed-f159-41be-9dda-1a056f29888d@notapiano/
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Tested-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

+4 -43
+4 -43
drivers/char/hw_random/core.c
··· 64 64 return RNG_BUFFER_SIZE; 65 65 } 66 66 67 - static void add_early_randomness(struct hwrng *rng) 68 - { 69 - int bytes_read; 70 - 71 - mutex_lock(&reading_mutex); 72 - bytes_read = rng_get_data(rng, rng_fillbuf, 32, 0); 73 - mutex_unlock(&reading_mutex); 74 - if (bytes_read > 0) { 75 - size_t entropy = bytes_read * 8 * rng->quality / 1024; 76 - add_hwgenerator_randomness(rng_fillbuf, bytes_read, entropy, false); 77 - } 78 - } 79 - 80 67 static inline void cleanup_rng(struct kref *kref) 81 68 { 82 69 struct hwrng *rng = container_of(kref, struct hwrng, ref); ··· 327 340 const char *buf, size_t len) 328 341 { 329 342 int err; 330 - struct hwrng *rng, *old_rng, *new_rng; 343 + struct hwrng *rng, *new_rng; 331 344 332 345 err = mutex_lock_interruptible(&rng_mutex); 333 346 if (err) 334 347 return -ERESTARTSYS; 335 348 336 - old_rng = current_rng; 337 349 if (sysfs_streq(buf, "")) { 338 350 err = enable_best_rng(); 339 351 } else { ··· 348 362 new_rng = get_current_rng_nolock(); 349 363 mutex_unlock(&rng_mutex); 350 364 351 - if (new_rng) { 352 - if (new_rng != old_rng) 353 - add_early_randomness(new_rng); 365 + if (new_rng) 354 366 put_rng(new_rng); 355 - } 356 367 357 368 return err ? : len; 358 369 } ··· 527 544 { 528 545 int err = -EINVAL; 529 546 struct hwrng *tmp; 530 - bool is_new_current = false; 531 547 532 548 if (!rng->name || (!rng->data_read && !rng->read)) 533 549 goto out; ··· 555 573 err = set_current_rng(rng); 556 574 if (err) 557 575 goto out_unlock; 558 - /* to use current_rng in add_early_randomness() we need 559 - * to take a ref 560 - */ 561 - is_new_current = true; 562 - kref_get(&rng->ref); 563 576 } 564 577 mutex_unlock(&rng_mutex); 565 - if (is_new_current || !rng->init) { 566 - /* 567 - * Use a new device's input to add some randomness to 568 - * the system. If this rng device isn't going to be 569 - * used right away, its init function hasn't been 570 - * called yet by set_current_rng(); so only use the 571 - * randomness from devices that don't need an init callback 572 - */ 573 - add_early_randomness(rng); 574 - } 575 - if (is_new_current) 576 - put_rng(rng); 577 578 return 0; 578 579 out_unlock: 579 580 mutex_unlock(&rng_mutex); ··· 567 602 568 603 void hwrng_unregister(struct hwrng *rng) 569 604 { 570 - struct hwrng *old_rng, *new_rng; 605 + struct hwrng *new_rng; 571 606 int err; 572 607 573 608 mutex_lock(&rng_mutex); 574 609 575 - old_rng = current_rng; 576 610 list_del(&rng->list); 577 611 complete_all(&rng->dying); 578 612 if (current_rng == rng) { ··· 590 626 } else 591 627 mutex_unlock(&rng_mutex); 592 628 593 - if (new_rng) { 594 - if (old_rng != new_rng) 595 - add_early_randomness(new_rng); 629 + if (new_rng) 596 630 put_rng(new_rng); 597 - } 598 631 599 632 wait_for_completion(&rng->cleanup_done); 600 633 }