diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-08-16 00:16:02 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-08-16 00:16:02 -0400 |
commit | 99a2c789ddeb703cf7b0a3d889ab1a25cf4cbbaf (patch) | |
tree | 3a653ba4bfb2db0c8fc52fbb5a2f0dc2e817e513 /lib/vsprintf.c | |
parent | fa3b39cdafbfd5d9b1d064f5cf63cf0314f1d070 (diff) | |
parent | 9a47249d444d344051c7c0e909fad0e88515a5c2 (diff) |
Merge tag 'random_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/random
Pull random updates from Ted Ts'o:
"Some changes to trust cpu-based hwrng (such as RDRAND) for
initializing hashed pointers and (optionally, controlled by a config
option) to initialize the CRNG to avoid boot hangs"
* tag 'random_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/random:
random: Make crng state queryable
random: remove preempt disabled region
random: add a config option to trust the CPU's hwrng
vsprintf: Add command line option debug_boot_weak_hash
vsprintf: Use hw RNG for ptr_key
random: Return nbytes filled from hw RNG
random: Fix whitespace pre random-bytes work
Diffstat (limited to 'lib/vsprintf.c')
-rw-r--r-- | lib/vsprintf.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index cda186230287..d5b3a3f95c01 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -1651,6 +1651,17 @@ char *device_node_string(char *buf, char *end, struct device_node *dn, | |||
1651 | return widen_string(buf, buf - buf_start, end, spec); | 1651 | return widen_string(buf, buf - buf_start, end, spec); |
1652 | } | 1652 | } |
1653 | 1653 | ||
1654 | /* Make pointers available for printing early in the boot sequence. */ | ||
1655 | static int debug_boot_weak_hash __ro_after_init; | ||
1656 | |||
1657 | static int __init debug_boot_weak_hash_enable(char *str) | ||
1658 | { | ||
1659 | debug_boot_weak_hash = 1; | ||
1660 | pr_info("debug_boot_weak_hash enabled\n"); | ||
1661 | return 0; | ||
1662 | } | ||
1663 | early_param("debug_boot_weak_hash", debug_boot_weak_hash_enable); | ||
1664 | |||
1654 | static DEFINE_STATIC_KEY_TRUE(not_filled_random_ptr_key); | 1665 | static DEFINE_STATIC_KEY_TRUE(not_filled_random_ptr_key); |
1655 | static siphash_key_t ptr_key __read_mostly; | 1666 | static siphash_key_t ptr_key __read_mostly; |
1656 | 1667 | ||
@@ -1675,8 +1686,16 @@ static struct random_ready_callback random_ready = { | |||
1675 | 1686 | ||
1676 | static int __init initialize_ptr_random(void) | 1687 | static int __init initialize_ptr_random(void) |
1677 | { | 1688 | { |
1678 | int ret = add_random_ready_callback(&random_ready); | 1689 | int key_size = sizeof(ptr_key); |
1690 | int ret; | ||
1679 | 1691 | ||
1692 | /* Use hw RNG if available. */ | ||
1693 | if (get_random_bytes_arch(&ptr_key, key_size) == key_size) { | ||
1694 | static_branch_disable(¬_filled_random_ptr_key); | ||
1695 | return 0; | ||
1696 | } | ||
1697 | |||
1698 | ret = add_random_ready_callback(&random_ready); | ||
1680 | if (!ret) { | 1699 | if (!ret) { |
1681 | return 0; | 1700 | return 0; |
1682 | } else if (ret == -EALREADY) { | 1701 | } else if (ret == -EALREADY) { |
@@ -1695,6 +1714,12 @@ static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec) | |||
1695 | const char *str = sizeof(ptr) == 8 ? "(____ptrval____)" : "(ptrval)"; | 1714 | const char *str = sizeof(ptr) == 8 ? "(____ptrval____)" : "(ptrval)"; |
1696 | unsigned long hashval; | 1715 | unsigned long hashval; |
1697 | 1716 | ||
1717 | /* When debugging early boot use non-cryptographically secure hash. */ | ||
1718 | if (unlikely(debug_boot_weak_hash)) { | ||
1719 | hashval = hash_long((unsigned long)ptr, 32); | ||
1720 | return pointer_string(buf, end, (const void *)hashval, spec); | ||
1721 | } | ||
1722 | |||
1698 | if (static_branch_unlikely(¬_filled_random_ptr_key)) { | 1723 | if (static_branch_unlikely(¬_filled_random_ptr_key)) { |
1699 | spec.field_width = 2 * sizeof(ptr); | 1724 | spec.field_width = 2 * sizeof(ptr); |
1700 | /* string length must be less than default_width */ | 1725 | /* string length must be less than default_width */ |