<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/drivers/char/random.c, branch v5.3</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=v5.3</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v5.3'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2019-05-26T04:11:49Z</updated>
<entry>
<title>random: fix soft lockup when trying to read from an uninitialized blocking pool</title>
<updated>2019-05-26T04:11:49Z</updated>
<author>
<name>Theodore Ts'o</name>
<email>tytso@mit.edu</email>
</author>
<published>2019-05-22T16:02:16Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=58be0106c5306b939b07b4b8bf00669a20593f4b'/>
<id>urn:sha1:58be0106c5306b939b07b4b8bf00669a20593f4b</id>
<content type='text'>
Fixes: eb9d1bf079bb: "random: only read from /dev/random after its pool has received 128 bits"
Reported-by: kernel test robot &lt;lkp@intel.com&gt;
Signed-off-by: Theodore Ts'o &lt;tytso@mit.edu&gt;
</content>
</entry>
<entry>
<title>random: add a spinlock_t to struct batched_entropy</title>
<updated>2019-04-20T04:09:56Z</updated>
<author>
<name>Sebastian Andrzej Siewior</name>
<email>bigeasy@linutronix.de</email>
</author>
<published>2019-04-20T04:09:51Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=b7d5dc21072cda7124d13eae2aefb7343ef94197'/>
<id>urn:sha1:b7d5dc21072cda7124d13eae2aefb7343ef94197</id>
<content type='text'>
The per-CPU variable batched_entropy_uXX is protected by get_cpu_var().
This is just a preempt_disable() which ensures that the variable is only
from the local CPU. It does not protect against users on the same CPU
from another context. It is possible that a preemptible context reads
slot 0 and then an interrupt occurs and the same value is read again.

The above scenario is confirmed by lockdep if we add a spinlock:
| ================================
| WARNING: inconsistent lock state
| 5.1.0-rc3+ #42 Not tainted
| --------------------------------
| inconsistent {SOFTIRQ-ON-W} -&gt; {IN-SOFTIRQ-W} usage.
| ksoftirqd/9/56 [HC0[0]:SC1[1]:HE0:SE0] takes:
| (____ptrval____) (batched_entropy_u32.lock){+.?.}, at: get_random_u32+0x3e/0xe0
| {SOFTIRQ-ON-W} state was registered at:
|   _raw_spin_lock+0x2a/0x40
|   get_random_u32+0x3e/0xe0
|   new_slab+0x15c/0x7b0
|   ___slab_alloc+0x492/0x620
|   __slab_alloc.isra.73+0x53/0xa0
|   kmem_cache_alloc_node+0xaf/0x2a0
|   copy_process.part.41+0x1e1/0x2370
|   _do_fork+0xdb/0x6d0
|   kernel_thread+0x20/0x30
|   kthreadd+0x1ba/0x220
|   ret_from_fork+0x3a/0x50
…
| other info that might help us debug this:
|  Possible unsafe locking scenario:
|
|        CPU0
|        ----
|   lock(batched_entropy_u32.lock);
|   &lt;Interrupt&gt;
|     lock(batched_entropy_u32.lock);
|
|  *** DEADLOCK ***
|
| stack backtrace:
| Call Trace:
…
|  kmem_cache_alloc_trace+0x20e/0x270
|  ipmi_alloc_recv_msg+0x16/0x40
…
|  __do_softirq+0xec/0x48d
|  run_ksoftirqd+0x37/0x60
|  smpboot_thread_fn+0x191/0x290
|  kthread+0xfe/0x130
|  ret_from_fork+0x3a/0x50

Add a spinlock_t to the batched_entropy data structure and acquire the
lock while accessing it. Acquire the lock with disabled interrupts
because this function may be used from interrupt context.

Remove the batched_entropy_reset_lock lock. Now that we have a lock for
the data scructure, we can access it from a remote CPU.

Signed-off-by: Sebastian Andrzej Siewior &lt;bigeasy@linutronix.de&gt;
Signed-off-by: Theodore Ts'o &lt;tytso@mit.edu&gt;
</content>
</entry>
<entry>
<title>random: document get_random_int() family</title>
<updated>2019-04-20T03:48:25Z</updated>
<author>
<name>George Spelvin</name>
<email>lkml@sdf.org</email>
</author>
<published>2019-04-20T03:48:20Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=92e507d216139b356a375afbda2824e85235e748'/>
<id>urn:sha1:92e507d216139b356a375afbda2824e85235e748</id>
<content type='text'>
Explain what these functions are for and when they offer
an advantage over get_random_bytes().

(We still need documentation on rng_is_initialized(), the
random_ready_callback system, and early boot in general.)

Signed-off-by: George Spelvin &lt;lkml@sdf.org&gt;
Signed-off-by: Theodore Ts'o &lt;tytso@mit.edu&gt;
</content>
</entry>
<entry>
<title>random: fix CRNG initialization when random.trust_cpu=1</title>
<updated>2019-04-20T03:35:16Z</updated>
<author>
<name>Jon DeVree</name>
<email>nuxi@vault24.org</email>
</author>
<published>2019-04-20T03:35:16Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=fe6f1a6a8eedc1aa538fee0baa612b6a59639cf8'/>
<id>urn:sha1:fe6f1a6a8eedc1aa538fee0baa612b6a59639cf8</id>
<content type='text'>
When the system boots with random.trust_cpu=1 it doesn't initialize the
per-NUMA CRNGs because it skips the rest of the CRNG startup code. This
means that the code from 1e7f583af67b ("random: make /dev/urandom scalable
for silly userspace programs") is not used when random.trust_cpu=1.

crash&gt; dmesg | grep random:
[    0.000000] random: get_random_bytes called from start_kernel+0x94/0x530 with crng_init=0
[    0.314029] random: crng done (trusting CPU's manufacturer)
crash&gt; print crng_node_pool
$6 = (struct crng_state **) 0x0

After adding the missing call to numa_crng_init() the per-NUMA CRNGs are
initialized again:

crash&gt; dmesg | grep random:
[    0.000000] random: get_random_bytes called from start_kernel+0x94/0x530 with crng_init=0
[    0.314031] random: crng done (trusting CPU's manufacturer)
crash&gt; print crng_node_pool
$1 = (struct crng_state **) 0xffff9a915f4014a0

The call to invalidate_batched_entropy() was also missing. This is
important for architectures like PPC and S390 which only have the
arch_get_random_seed_* functions.

Fixes: 39a8883a2b98 ("random: add a config option to trust the CPU's hwrng")
Signed-off-by: Jon DeVree &lt;nuxi@vault24.org&gt;
Signed-off-by: Theodore Ts'o &lt;tytso@mit.edu&gt;
</content>
</entry>
<entry>
<title>random: move rand_initialize() earlier</title>
<updated>2019-04-20T03:27:05Z</updated>
<author>
<name>Kees Cook</name>
<email>keescook@chromium.org</email>
</author>
<published>2019-04-20T03:27:05Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=d55535232c3dbde9a523a9d10d68670f5fe5dec3'/>
<id>urn:sha1:d55535232c3dbde9a523a9d10d68670f5fe5dec3</id>
<content type='text'>
Right now rand_initialize() is run as an early_initcall(), but it only
depends on timekeeping_init() (for mixing ktime_get_real() into the
pools). However, the call to boot_init_stack_canary() for stack canary
initialization runs earlier, which triggers a warning at boot:

random: get_random_bytes called from start_kernel+0x357/0x548 with crng_init=0

Instead, this moves rand_initialize() to after timekeeping_init(), and moves
canary initialization here as well.

Note that this warning may still remain for machines that do not have
UEFI RNG support (which initializes the RNG pools during setup_arch()),
or for x86 machines without RDRAND (or booting without "random.trust=on"
or CONFIG_RANDOM_TRUST_CPU=y).

Signed-off-by: Kees Cook &lt;keescook@chromium.org&gt;
Signed-off-by: Theodore Ts'o &lt;tytso@mit.edu&gt;
</content>
</entry>
<entry>
<title>random: only read from /dev/random after its pool has received 128 bits</title>
<updated>2019-04-17T14:30:21Z</updated>
<author>
<name>Theodore Ts'o</name>
<email>tytso@mit.edu</email>
</author>
<published>2019-02-20T21:06:38Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=eb9d1bf079bb438d1a066d72337092935fc770f6'/>
<id>urn:sha1:eb9d1bf079bb438d1a066d72337092935fc770f6</id>
<content type='text'>
Immediately after boot, we allow reads from /dev/random before its
entropy pool has been fully initialized.  Fix this so that we don't
allow this until the blocking pool has received 128 bits.

We do this by repurposing the initialized flag in the entropy pool
struct, and use the initialized flag in the blocking pool to indicate
whether it is safe to pull from the blocking pool.

To do this, we needed to rework when we decide to push entropy from the
input pool to the blocking pool, since the initialized flag for the
input pool was used for this purpose.  To simplify things, we no
longer use the initialized flag for that purpose, nor do we use the
entropy_total field any more.

Signed-off-by: Theodore Ts'o &lt;tytso@mit.edu&gt;
</content>
</entry>
<entry>
<title>drivers/char/random.c: make primary_crng static</title>
<updated>2019-04-17T14:30:21Z</updated>
<author>
<name>Rasmus Villemoes</name>
<email>linux@rasmusvillemoes.dk</email>
</author>
<published>2018-11-02T11:04:47Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=764ed189c82090c1d85f0e30636156736d8f09a8'/>
<id>urn:sha1:764ed189c82090c1d85f0e30636156736d8f09a8</id>
<content type='text'>
Since the definition of struct crng_state is private to random.c, and
primary_crng is neither declared or used elsewhere, there's no reason
for that symbol to have external linkage.

Signed-off-by: Rasmus Villemoes &lt;linux@rasmusvillemoes.dk&gt;
Signed-off-by: Theodore Ts'o &lt;tytso@mit.edu&gt;
</content>
</entry>
<entry>
<title>drivers/char/random.c: remove unused stuct poolinfo::poolbits</title>
<updated>2019-04-17T14:30:21Z</updated>
<author>
<name>Rasmus Villemoes</name>
<email>linux@rasmusvillemoes.dk</email>
</author>
<published>2018-11-02T11:04:46Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=3bd0b5bf7dc3ea02070fcbcd682ecf628269e8ef'/>
<id>urn:sha1:3bd0b5bf7dc3ea02070fcbcd682ecf628269e8ef</id>
<content type='text'>
This field is never used, might as well remove it.

Signed-off-by: Rasmus Villemoes &lt;linux@rasmusvillemoes.dk&gt;
Signed-off-by: Theodore Ts'o &lt;tytso@mit.edu&gt;
</content>
</entry>
<entry>
<title>drivers/char/random.c: constify poolinfo_table</title>
<updated>2019-04-17T14:30:21Z</updated>
<author>
<name>Rasmus Villemoes</name>
<email>linux@rasmusvillemoes.dk</email>
</author>
<published>2018-11-02T11:04:45Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=26e0854ab3310bbeef1ed404a2c87132fc91f8e1'/>
<id>urn:sha1:26e0854ab3310bbeef1ed404a2c87132fc91f8e1</id>
<content type='text'>
Never modified, might as well be put in .rodata.

Signed-off-by: Rasmus Villemoes &lt;linux@rasmusvillemoes.dk&gt;
Signed-off-by: Theodore Ts'o &lt;tytso@mit.edu&gt;
</content>
</entry>
<entry>
<title>crypto: chacha20-generic - refactor to allow varying number of rounds</title>
<updated>2018-11-20T06:26:55Z</updated>
<author>
<name>Eric Biggers</name>
<email>ebiggers@google.com</email>
</author>
<published>2018-11-17T01:26:21Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=1ca1b917940c24ca3d1f490118c5474168622953'/>
<id>urn:sha1:1ca1b917940c24ca3d1f490118c5474168622953</id>
<content type='text'>
In preparation for adding XChaCha12 support, rename/refactor
chacha20-generic to support different numbers of rounds.  The
justification for needing XChaCha12 support is explained in more detail
in the patch "crypto: chacha - add XChaCha12 support".

The only difference between ChaCha{8,12,20} are the number of rounds
itself; all other parts of the algorithm are the same.  Therefore,
remove the "20" from all definitions, structures, functions, files, etc.
that will be shared by all ChaCha versions.

Also make -&gt;setkey() store the round count in the chacha_ctx (previously
chacha20_ctx).  The generic code then passes the round count through to
chacha_block().  There will be a -&gt;setkey() function for each explicitly
allowed round count; the encrypt/decrypt functions will be the same.  I
decided not to do it the opposite way (same -&gt;setkey() function for all
round counts, with different encrypt/decrypt functions) because that
would have required more boilerplate code in architecture-specific
implementations of ChaCha and XChaCha.

Reviewed-by: Ard Biesheuvel &lt;ard.biesheuvel@linaro.org&gt;
Acked-by: Martin Willi &lt;martin@strongswan.org&gt;
Signed-off-by: Eric Biggers &lt;ebiggers@google.com&gt;
Signed-off-by: Herbert Xu &lt;herbert@gondor.apana.org.au&gt;
</content>
</entry>
</feed>
