diff options
Diffstat (limited to 'lib/vsprintf.c')
-rw-r--r-- | lib/vsprintf.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 30c0cb8cc9bc..23920c5ff728 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -1669,19 +1669,22 @@ char *pointer_string(char *buf, char *end, const void *ptr, | |||
1669 | return number(buf, end, (unsigned long int)ptr, spec); | 1669 | return number(buf, end, (unsigned long int)ptr, spec); |
1670 | } | 1670 | } |
1671 | 1671 | ||
1672 | static bool have_filled_random_ptr_key __read_mostly; | 1672 | static DEFINE_STATIC_KEY_TRUE(not_filled_random_ptr_key); |
1673 | static siphash_key_t ptr_key __read_mostly; | 1673 | static siphash_key_t ptr_key __read_mostly; |
1674 | 1674 | ||
1675 | static void fill_random_ptr_key(struct random_ready_callback *unused) | 1675 | static void enable_ptr_key_workfn(struct work_struct *work) |
1676 | { | 1676 | { |
1677 | get_random_bytes(&ptr_key, sizeof(ptr_key)); | 1677 | get_random_bytes(&ptr_key, sizeof(ptr_key)); |
1678 | /* | 1678 | /* Needs to run from preemptible context */ |
1679 | * have_filled_random_ptr_key==true is dependent on get_random_bytes(). | 1679 | static_branch_disable(¬_filled_random_ptr_key); |
1680 | * ptr_to_id() needs to see have_filled_random_ptr_key==true | 1680 | } |
1681 | * after get_random_bytes() returns. | 1681 | |
1682 | */ | 1682 | static DECLARE_WORK(enable_ptr_key_work, enable_ptr_key_workfn); |
1683 | smp_mb(); | 1683 | |
1684 | WRITE_ONCE(have_filled_random_ptr_key, true); | 1684 | static void fill_random_ptr_key(struct random_ready_callback *unused) |
1685 | { | ||
1686 | /* This may be in an interrupt handler. */ | ||
1687 | queue_work(system_unbound_wq, &enable_ptr_key_work); | ||
1685 | } | 1688 | } |
1686 | 1689 | ||
1687 | static struct random_ready_callback random_ready = { | 1690 | static struct random_ready_callback random_ready = { |
@@ -1695,7 +1698,8 @@ static int __init initialize_ptr_random(void) | |||
1695 | if (!ret) { | 1698 | if (!ret) { |
1696 | return 0; | 1699 | return 0; |
1697 | } else if (ret == -EALREADY) { | 1700 | } else if (ret == -EALREADY) { |
1698 | fill_random_ptr_key(&random_ready); | 1701 | /* This is in preemptible context */ |
1702 | enable_ptr_key_workfn(&enable_ptr_key_work); | ||
1699 | return 0; | 1703 | return 0; |
1700 | } | 1704 | } |
1701 | 1705 | ||
@@ -1709,7 +1713,7 @@ static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec) | |||
1709 | unsigned long hashval; | 1713 | unsigned long hashval; |
1710 | const int default_width = 2 * sizeof(ptr); | 1714 | const int default_width = 2 * sizeof(ptr); |
1711 | 1715 | ||
1712 | if (unlikely(!have_filled_random_ptr_key)) { | 1716 | if (static_branch_unlikely(¬_filled_random_ptr_key)) { |
1713 | spec.field_width = default_width; | 1717 | spec.field_width = default_width; |
1714 | /* string length must be less than default_width */ | 1718 | /* string length must be less than default_width */ |
1715 | return string(buf, end, "(ptrval)", spec); | 1719 | return string(buf, end, "(ptrval)", spec); |