Skip to content

Commit 1c4facb

Browse files
tchardingtytso
authored andcommitted
vsprintf: Use hw RNG for ptr_key
Currently we must wait for enough entropy to become available before hashed pointers can be printed. We can remove this wait by using the hw RNG if available. Use hw RNG to get keying material. Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Suggested-by: Kees Cook <keescook@chromium.org> Signed-off-by: Tobin C. Harding <me@tobin.cc> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 753d433 commit 1c4facb

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/vsprintf.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1675,8 +1675,16 @@ static struct random_ready_callback random_ready = {
16751675

16761676
static int __init initialize_ptr_random(void)
16771677
{
1678-
int ret = add_random_ready_callback(&random_ready);
1678+
int key_size = sizeof(ptr_key);
1679+
int ret;
1680+
1681+
/* Use hw RNG if available. */
1682+
if (get_random_bytes_arch(&ptr_key, key_size) == key_size) {
1683+
static_branch_disable(&not_filled_random_ptr_key);
1684+
return 0;
1685+
}
16791686

1687+
ret = add_random_ready_callback(&random_ready);
16801688
if (!ret) {
16811689
return 0;
16821690
} else if (ret == -EALREADY) {

0 commit comments

Comments
 (0)