linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] random: fix the RNDRESEEDCRNG ioctl
@ 2020-09-16  4:19 Eric Biggers
  2020-10-07  3:50 ` Eric Biggers
  2020-10-07  4:20 ` Jann Horn
  0 siblings, 2 replies; 7+ messages in thread
From: Eric Biggers @ 2020-09-16  4:19 UTC (permalink / raw)
  To: Theodore Ts'o; +Cc: linux-crypto, linux-kernel, Andy Lutomirski, Jann Horn

From: Eric Biggers <ebiggers@google.com>

The RNDRESEEDCRNG ioctl reseeds the primary_crng from itself, which
doesn't make sense.  Reseed it from the input_pool instead.

Fixes: d848e5f8e1eb ("random: add new ioctl RNDRESEEDCRNG")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 drivers/char/random.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index d20ba1b104ca3..a8b9e66f41435 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1973,7 +1973,7 @@ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
 			return -EPERM;
 		if (crng_init < 2)
 			return -ENODATA;
-		crng_reseed(&primary_crng, NULL);
+		crng_reseed(&primary_crng, &input_pool);
 		crng_global_init_time = jiffies - 1;
 		return 0;
 	default:
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] random: fix the RNDRESEEDCRNG ioctl
  2020-09-16  4:19 [PATCH] random: fix the RNDRESEEDCRNG ioctl Eric Biggers
@ 2020-10-07  3:50 ` Eric Biggers
  2020-10-26 16:33   ` Eric Biggers
  2020-10-07  4:20 ` Jann Horn
  1 sibling, 1 reply; 7+ messages in thread
From: Eric Biggers @ 2020-10-07  3:50 UTC (permalink / raw)
  To: Theodore Ts'o; +Cc: linux-crypto, linux-kernel, Andy Lutomirski, Jann Horn

On Tue, Sep 15, 2020 at 09:19:08PM -0700, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
> 
> The RNDRESEEDCRNG ioctl reseeds the primary_crng from itself, which
> doesn't make sense.  Reseed it from the input_pool instead.
> 
> Fixes: d848e5f8e1eb ("random: add new ioctl RNDRESEEDCRNG")
> Cc: stable@vger.kernel.org
> Signed-off-by: Eric Biggers <ebiggers@google.com>

Ping?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] random: fix the RNDRESEEDCRNG ioctl
  2020-09-16  4:19 [PATCH] random: fix the RNDRESEEDCRNG ioctl Eric Biggers
  2020-10-07  3:50 ` Eric Biggers
@ 2020-10-07  4:20 ` Jann Horn
  1 sibling, 0 replies; 7+ messages in thread
From: Jann Horn @ 2020-10-07  4:20 UTC (permalink / raw)
  To: Eric Biggers
  Cc: Theodore Ts'o, linux-crypto, kernel list, Andy Lutomirski

On Wed, Sep 16, 2020 at 6:19 AM Eric Biggers <ebiggers@kernel.org> wrote:
> The RNDRESEEDCRNG ioctl reseeds the primary_crng from itself, which
> doesn't make sense.  Reseed it from the input_pool instead.

Good catch. (And its purpose is to ensure that entropy from
random_write() is plumbed all the way through such that getrandom()
and friends are guaranteed to actually use that entropy on the next
invocation; and random_write() just puts data into the input pool.)

But actually, looking at the surrounding code, I think there's another
small problem?

> Fixes: d848e5f8e1eb ("random: add new ioctl RNDRESEEDCRNG")
> Cc: stable@vger.kernel.org
> Signed-off-by: Eric Biggers <ebiggers@google.com>

Reviewed-by: Jann Horn <jannh@google.com>

> ---
>  drivers/char/random.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/char/random.c b/drivers/char/random.c
> index d20ba1b104ca3..a8b9e66f41435 100644
> --- a/drivers/char/random.c
> +++ b/drivers/char/random.c
> @@ -1973,7 +1973,7 @@ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
>                         return -EPERM;
>                 if (crng_init < 2)
>                         return -ENODATA;
> -               crng_reseed(&primary_crng, NULL);
> +               crng_reseed(&primary_crng, &input_pool);

So now this will pull the data from the input_pool into the
primary_crng, so far so good...

>                 crng_global_init_time = jiffies - 1;

... and this will hopefully cause _extract_crng() to pull from the
primary_crng into crng_node_pool[numa_node_id()] afterwards. Unless
things are going too fast and therefore the jiffies haven't changed
since the last crng_reseed() on the crng_node_pool[numa_node_id()]...
a sequence number would probably be more robust than a timestamp.

And a plain write like this without holding any locks is also questionable.

The easiest way would probably be to make it an atomic_long_t, do
atomic_long_inc() instead of setting crng_global_init_time here, and
check atomic_long_read(...) against a copy stored in the crng_state on
_extract_crng()? And in crng_reseed(), grab the global sequence number
at the start, then do smp_rmb(), and then under the lock do the actual
reseeding and bump ->init_time? Or something like that?

>                 return 0;
>         default:

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] random: fix the RNDRESEEDCRNG ioctl
  2020-10-07  3:50 ` Eric Biggers
@ 2020-10-26 16:33   ` Eric Biggers
  2020-11-20 18:52     ` Eric Biggers
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Biggers @ 2020-10-26 16:33 UTC (permalink / raw)
  To: Theodore Ts'o; +Cc: linux-crypto, linux-kernel, Andy Lutomirski, Jann Horn

On Tue, Oct 06, 2020 at 08:50:21PM -0700, Eric Biggers wrote:
> On Tue, Sep 15, 2020 at 09:19:08PM -0700, Eric Biggers wrote:
> > From: Eric Biggers <ebiggers@google.com>
> > 
> > The RNDRESEEDCRNG ioctl reseeds the primary_crng from itself, which
> > doesn't make sense.  Reseed it from the input_pool instead.
> > 
> > Fixes: d848e5f8e1eb ("random: add new ioctl RNDRESEEDCRNG")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Eric Biggers <ebiggers@google.com>
> 
> Ping?

Ping.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] random: fix the RNDRESEEDCRNG ioctl
  2020-10-26 16:33   ` Eric Biggers
@ 2020-11-20 18:52     ` Eric Biggers
  2021-01-04 18:55       ` Eric Biggers
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Biggers @ 2020-11-20 18:52 UTC (permalink / raw)
  To: Theodore Ts'o; +Cc: linux-crypto, linux-kernel, Andy Lutomirski, Jann Horn

On Mon, Oct 26, 2020 at 09:33:43AM -0700, Eric Biggers wrote:
> On Tue, Oct 06, 2020 at 08:50:21PM -0700, Eric Biggers wrote:
> > On Tue, Sep 15, 2020 at 09:19:08PM -0700, Eric Biggers wrote:
> > > From: Eric Biggers <ebiggers@google.com>
> > > 
> > > The RNDRESEEDCRNG ioctl reseeds the primary_crng from itself, which
> > > doesn't make sense.  Reseed it from the input_pool instead.
> > > 
> > > Fixes: d848e5f8e1eb ("random: add new ioctl RNDRESEEDCRNG")
> > > Cc: stable@vger.kernel.org
> > > Signed-off-by: Eric Biggers <ebiggers@google.com>
> > 
> > Ping?
> 
> Ping.

Ping.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] random: fix the RNDRESEEDCRNG ioctl
  2020-11-20 18:52     ` Eric Biggers
@ 2021-01-04 18:55       ` Eric Biggers
  2021-01-12  0:04         ` Jann Horn
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Biggers @ 2021-01-04 18:55 UTC (permalink / raw)
  To: Theodore Ts'o; +Cc: linux-crypto, linux-kernel, Andy Lutomirski, Jann Horn

On Fri, Nov 20, 2020 at 10:52:14AM -0800, Eric Biggers wrote:
> On Mon, Oct 26, 2020 at 09:33:43AM -0700, Eric Biggers wrote:
> > On Tue, Oct 06, 2020 at 08:50:21PM -0700, Eric Biggers wrote:
> > > On Tue, Sep 15, 2020 at 09:19:08PM -0700, Eric Biggers wrote:
> > > > From: Eric Biggers <ebiggers@google.com>
> > > > 
> > > > The RNDRESEEDCRNG ioctl reseeds the primary_crng from itself, which
> > > > doesn't make sense.  Reseed it from the input_pool instead.
> > > > 
> > > > Fixes: d848e5f8e1eb ("random: add new ioctl RNDRESEEDCRNG")
> > > > Cc: stable@vger.kernel.org
> > > > Signed-off-by: Eric Biggers <ebiggers@google.com>
> > > 
> > > Ping?
> > 
> > Ping.
> 
> Ping.

Ping.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] random: fix the RNDRESEEDCRNG ioctl
  2021-01-04 18:55       ` Eric Biggers
@ 2021-01-12  0:04         ` Jann Horn
  0 siblings, 0 replies; 7+ messages in thread
From: Jann Horn @ 2021-01-12  0:04 UTC (permalink / raw)
  To: Eric Biggers
  Cc: Theodore Ts'o,
	open list:HARDWARE RANDOM NUMBER GENERATOR CORE, kernel list,
	Andy Lutomirski

On Mon, Jan 4, 2021 at 7:55 PM Eric Biggers <ebiggers@kernel.org> wrote:
> On Fri, Nov 20, 2020 at 10:52:14AM -0800, Eric Biggers wrote:
> > On Mon, Oct 26, 2020 at 09:33:43AM -0700, Eric Biggers wrote:
> > > On Tue, Oct 06, 2020 at 08:50:21PM -0700, Eric Biggers wrote:
> > > > On Tue, Sep 15, 2020 at 09:19:08PM -0700, Eric Biggers wrote:
> > > > > From: Eric Biggers <ebiggers@google.com>
> > > > >
> > > > > The RNDRESEEDCRNG ioctl reseeds the primary_crng from itself, which
> > > > > doesn't make sense.  Reseed it from the input_pool instead.
> > > > >
> > > > > Fixes: d848e5f8e1eb ("random: add new ioctl RNDRESEEDCRNG")
> > > > > Cc: stable@vger.kernel.org
> > > > > Signed-off-by: Eric Biggers <ebiggers@google.com>
> > > >
> > > > Ping?
> > >
> > > Ping.
> >
> > Ping.
>
> Ping.

You may want to resend to akpm with a note that the maintainer is unresponsive.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-01-12  0:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-16  4:19 [PATCH] random: fix the RNDRESEEDCRNG ioctl Eric Biggers
2020-10-07  3:50 ` Eric Biggers
2020-10-26 16:33   ` Eric Biggers
2020-11-20 18:52     ` Eric Biggers
2021-01-04 18:55       ` Eric Biggers
2021-01-12  0:04         ` Jann Horn
2020-10-07  4:20 ` Jann Horn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).