[SRU bionic] random: Make getrandom() ready earlier

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[SRU bionic] random: Make getrandom() ready earlier

Stefan Bader-2
From: Ben Hutchings <[hidden email]>

This effectively reverts commit 725e828 "random: fix crng_ready()
test" which was commit 43838a23a05f upstream.  Unfortunately some
users of getrandom() don't expect it to block for long, and they need
to be fixed before we can allow this change into stable.

This doesn't directly revert that commit, but only weakens the ready
condition used by getrandom() when the GRND_RANDOM flag is not set.
Calls to getrandom() that return before the RNG is fully seeded will
generate warnings, just like reads from /dev/urandom.

https://bugs.launchpad.net/bugs/1780062

(backported from ://salsa.debian.org/kernel-team/linux/raw/stretch/debian/patches/debian/random-make-getrandom-ready-earlier.patch)
[smb: open code waiting in getrandom directly]
Signed-off-by: Stefan Bader <[hidden email]>
---
This is based on the patch from Ben Hutchings in Debian. But since
wait_for_random_bytes, which is used in the 4.15 code is exported
and used by other things, I did instead do its own wait in getrandom().

-Stefan

 drivers/char/random.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index d5f1211..6021405 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1976,10 +1976,10 @@ SYSCALL_DEFINE3(getrandom, char __user *, buf, size_t, count,
  if (flags & GRND_RANDOM)
  return _random_read(flags & GRND_NONBLOCK, buf, count);
 
- if (!crng_ready()) {
+ if (crng_init == 0) {
  if (flags & GRND_NONBLOCK)
  return -EAGAIN;
- ret = wait_for_random_bytes();
+ ret = wait_event_interruptible(crng_init_wait, crng_init > 0);
  if (unlikely(ret))
  return ret;
  }
--
2.7.4


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

ACK: [SRU bionic] random: Make getrandom() ready earlier

Colin Ian King-2
On 04/07/18 15:15, Stefan Bader wrote:

> From: Ben Hutchings <[hidden email]>
>
> This effectively reverts commit 725e828 "random: fix crng_ready()
> test" which was commit 43838a23a05f upstream.  Unfortunately some
> users of getrandom() don't expect it to block for long, and they need
> to be fixed before we can allow this change into stable.
>
> This doesn't directly revert that commit, but only weakens the ready
> condition used by getrandom() when the GRND_RANDOM flag is not set.
> Calls to getrandom() that return before the RNG is fully seeded will
> generate warnings, just like reads from /dev/urandom.
>
> https://bugs.launchpad.net/bugs/1780062
>
> (backported from ://salsa.debian.org/kernel-team/linux/raw/stretch/debian/patches/debian/random-make-getrandom-ready-earlier.patch)
> [smb: open code waiting in getrandom directly]
> Signed-off-by: Stefan Bader <[hidden email]>
> ---
> This is based on the patch from Ben Hutchings in Debian. But since
> wait_for_random_bytes, which is used in the 4.15 code is exported
> and used by other things, I did instead do its own wait in getrandom().
>
> -Stefan
>
>  drivers/char/random.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/char/random.c b/drivers/char/random.c
> index d5f1211..6021405 100644
> --- a/drivers/char/random.c
> +++ b/drivers/char/random.c
> @@ -1976,10 +1976,10 @@ SYSCALL_DEFINE3(getrandom, char __user *, buf, size_t, count,
>   if (flags & GRND_RANDOM)
>   return _random_read(flags & GRND_NONBLOCK, buf, count);
>  
> - if (!crng_ready()) {
> + if (crng_init == 0) {
>   if (flags & GRND_NONBLOCK)
>   return -EAGAIN;
> - ret = wait_for_random_bytes();
> + ret = wait_event_interruptible(crng_init_wait, crng_init > 0);
>   if (unlikely(ret))
>   return ret;
>   }
>

Looks good to me; this is a good workaround for now; fixes the issue on
my X230 too, so I've tested this and it works.

The bug link needs fixing up when this is applied.

Thanks Stefan.

Acked-by: Colin Ian King <[hidden email]>

--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

ACK: [SRU bionic] random: Make getrandom() ready earlier

Khaled Elmously
In reply to this post by Stefan Bader-2


  Original Message  
From: Stefan Bader
Sent: Wednesday, July 4, 2018 10:16 AM
To: [hidden email]
Subject: [SRU bionic] random: Make getrandom() ready earlier

From: Ben Hutchings <[hidden email]>

This effectively reverts commit 725e828 "random: fix crng_ready()
test" which was commit 43838a23a05f upstream. Unfortunately some
users of getrandom() don't expect it to block for long, and they need
to be fixed before we can allow this change into stable.

This doesn't directly revert that commit, but only weakens the ready
condition used by getrandom() when the GRND_RANDOM flag is not set.
Calls to getrandom() that return before the RNG is fully seeded will
generate warnings, just like reads from /dev/urandom.

https://bugs.launchpad.net/bugs/1780062

(backported from ://salsa.debian.org/kernel-team/linux/raw/stretch/debian/patches/debian/random-make-getrandom-ready-earlier.patch)
[smb: open code waiting in getrandom directly]
Signed-off-by: Stefan Bader <[hidden email]>
---
This is based on the patch from Ben Hutchings in Debian. But since
wait_for_random_bytes, which is used in the 4.15 code is exported
and used by other things, I did instead do its own wait in getrandom().

-Stefan

drivers/char/random.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index d5f1211..6021405 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1976,10 +1976,10 @@ SYSCALL_DEFINE3(getrandom, char __user *, buf, size_t, count,
if (flags & GRND_RANDOM)
return _random_read(flags & GRND_NONBLOCK, buf, count);

- if (!crng_ready()) {
+ if (crng_init == 0) {
if (flags & GRND_NONBLOCK)
return -EAGAIN;
- ret = wait_for_random_bytes();
+ ret = wait_event_interruptible(crng_init_wait, crng_init > 0);
if (unlikely(ret))
return ret;
}
--
2.7.4

Acked-by: Khalid Elmously <[hidden email]>


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

ACK: [SRU bionic] random: Make getrandom() ready earlier

Marcelo Henrique Cerri
In reply to this post by Stefan Bader-2
Acked-by: Marcelo Henrique Cerri <[hidden email]>

--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team

signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: ACK: [SRU bionic] random: Make getrandom() ready earlier

Khaled Elmously
In reply to this post by Colin Ian King-2
On 2018-07-04 15:56:35 , Colin Ian King wrote:

> On 04/07/18 15:15, Stefan Bader wrote:
> > From: Ben Hutchings <[hidden email]>
> >
> > This effectively reverts commit 725e828 "random: fix crng_ready()
> > test" which was commit 43838a23a05f upstream.  Unfortunately some
> > users of getrandom() don't expect it to block for long, and they need
> > to be fixed before we can allow this change into stable.
> >
> > This doesn't directly revert that commit, but only weakens the ready
> > condition used by getrandom() when the GRND_RANDOM flag is not set.
> > Calls to getrandom() that return before the RNG is fully seeded will
> > generate warnings, just like reads from /dev/urandom.
> >
> > https://bugs.launchpad.net/bugs/1780062
> >
> > (backported from ://salsa.debian.org/kernel-team/linux/raw/stretch/debian/patches/debian/random-make-getrandom-ready-earlier.patch)
> > [smb: open code waiting in getrandom directly]
> > Signed-off-by: Stefan Bader <[hidden email]>
> > ---
> > This is based on the patch from Ben Hutchings in Debian. But since
> > wait_for_random_bytes, which is used in the 4.15 code is exported
> > and used by other things, I did instead do its own wait in getrandom().
> >
> > -Stefan
> >
> >  drivers/char/random.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/char/random.c b/drivers/char/random.c
> > index d5f1211..6021405 100644
> > --- a/drivers/char/random.c
> > +++ b/drivers/char/random.c
> > @@ -1976,10 +1976,10 @@ SYSCALL_DEFINE3(getrandom, char __user *, buf, size_t, count,
> >   if (flags & GRND_RANDOM)
> >   return _random_read(flags & GRND_NONBLOCK, buf, count);
> >  
> > - if (!crng_ready()) {
> > + if (crng_init == 0) {
> >   if (flags & GRND_NONBLOCK)
> >   return -EAGAIN;
> > - ret = wait_for_random_bytes();
> > + ret = wait_event_interruptible(crng_init_wait, crng_init > 0);
> >   if (unlikely(ret))
> >   return ret;
> >   }
> >
>
> Looks good to me; this is a good workaround for now; fixes the issue on
> my X230 too, so I've tested this and it works.
>
> The bug link needs fixing up when this is applied.

The buglink seems to work fine for me (just don't copy the closing
parenthesis)

>
> Thanks Stefan.
>
> Acked-by: Colin Ian King <[hidden email]>
>
> --
> kernel-team mailing list
> [hidden email]
> https://lists.ubuntu.com/mailman/listinfo/kernel-team

--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

Re: ACK: [SRU bionic] random: Make getrandom() ready earlier

Khaled Elmously
On 2018-07-04 11:12:36 , Khaled Elmously wrote:

> On 2018-07-04 15:56:35 , Colin Ian King wrote:
> > On 04/07/18 15:15, Stefan Bader wrote:
> > > From: Ben Hutchings <[hidden email]>
> > >
> > > This effectively reverts commit 725e828 "random: fix crng_ready()
> > > test" which was commit 43838a23a05f upstream.  Unfortunately some
> > > users of getrandom() don't expect it to block for long, and they need
> > > to be fixed before we can allow this change into stable.
> > >
> > > This doesn't directly revert that commit, but only weakens the ready
> > > condition used by getrandom() when the GRND_RANDOM flag is not set.
> > > Calls to getrandom() that return before the RNG is fully seeded will
> > > generate warnings, just like reads from /dev/urandom.
> > >
> > > https://bugs.launchpad.net/bugs/1780062
> > >
> > > (backported from ://salsa.debian.org/kernel-team/linux/raw/stretch/debian/patches/debian/random-make-getrandom-ready-earlier.patch)
> > > [smb: open code waiting in getrandom directly]
> > > Signed-off-by: Stefan Bader <[hidden email]>
> > > ---
> > > This is based on the patch from Ben Hutchings in Debian. But since
> > > wait_for_random_bytes, which is used in the 4.15 code is exported
> > > and used by other things, I did instead do its own wait in getrandom().
> > >
> > > -Stefan
> > >
> > >  drivers/char/random.c | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/char/random.c b/drivers/char/random.c
> > > index d5f1211..6021405 100644
> > > --- a/drivers/char/random.c
> > > +++ b/drivers/char/random.c
> > > @@ -1976,10 +1976,10 @@ SYSCALL_DEFINE3(getrandom, char __user *, buf, size_t, count,
> > >   if (flags & GRND_RANDOM)
> > >   return _random_read(flags & GRND_NONBLOCK, buf, count);
> > >  
> > > - if (!crng_ready()) {
> > > + if (crng_init == 0) {
> > >   if (flags & GRND_NONBLOCK)
> > >   return -EAGAIN;
> > > - ret = wait_for_random_bytes();
> > > + ret = wait_event_interruptible(crng_init_wait, crng_init > 0);
> > >   if (unlikely(ret))
> > >   return ret;
> > >   }
> > >
> >
> > Looks good to me; this is a good workaround for now; fixes the issue on
> > my X230 too, so I've tested this and it works.
> >
> > The bug link needs fixing up when this is applied.
>
> The buglink seems to work fine for me (just don't copy the closing
> parenthesis)
>

Sorry, I misspoke. I meant the "patch link" works fine for me (though
the bug link seems to work fine too)


> >
> > Thanks Stefan.
> >
> > Acked-by: Colin Ian King <[hidden email]>
> >
> > --
> > kernel-team mailing list
> > [hidden email]
> > https://lists.ubuntu.com/mailman/listinfo/kernel-team

--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

APPLIED: [SRU bionic] random: Make getrandom() ready earlier

Kleber Souza
In reply to this post by Stefan Bader-2
On 07/04/18 16:15, Stefan Bader wrote:

> From: Ben Hutchings <[hidden email]>
>
> This effectively reverts commit 725e828 "random: fix crng_ready()
> test" which was commit 43838a23a05f upstream.  Unfortunately some
> users of getrandom() don't expect it to block for long, and they need
> to be fixed before we can allow this change into stable.
>
> This doesn't directly revert that commit, but only weakens the ready
> condition used by getrandom() when the GRND_RANDOM flag is not set.
> Calls to getrandom() that return before the RNG is fully seeded will
> generate warnings, just like reads from /dev/urandom.
>
> https://bugs.launchpad.net/bugs/1780062
>
> (backported from ://salsa.debian.org/kernel-team/linux/raw/stretch/debian/patches/debian/random-make-getrandom-ready-earlier.patch)
> [smb: open code waiting in getrandom directly]
> Signed-off-by: Stefan Bader <[hidden email]>
> ---
> This is based on the patch from Ben Hutchings in Debian. But since
> wait_for_random_bytes, which is used in the 4.15 code is exported
> and used by other things, I did instead do its own wait in getrandom().
>
> -Stefan
>
>  drivers/char/random.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/char/random.c b/drivers/char/random.c
> index d5f1211..6021405 100644
> --- a/drivers/char/random.c
> +++ b/drivers/char/random.c
> @@ -1976,10 +1976,10 @@ SYSCALL_DEFINE3(getrandom, char __user *, buf, size_t, count,
>   if (flags & GRND_RANDOM)
>   return _random_read(flags & GRND_NONBLOCK, buf, count);
>  
> - if (!crng_ready()) {
> + if (crng_init == 0) {
>   if (flags & GRND_NONBLOCK)
>   return -EAGAIN;
> - ret = wait_for_random_bytes();
> + ret = wait_event_interruptible(crng_init_wait, crng_init > 0);
>   if (unlikely(ret))
>   return ret;
>   }
>

This patch has been applied to bionic/master-next branch.

Thanks,
Kleber

--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

APPLIED[C/Unstable]: [SRU bionic] random: Make getrandom() ready earlier

Seth Forshee
In reply to this post by Stefan Bader-2
On Wed, Jul 04, 2018 at 04:15:50PM +0200, Stefan Bader wrote:

> From: Ben Hutchings <[hidden email]>
>
> This effectively reverts commit 725e828 "random: fix crng_ready()
> test" which was commit 43838a23a05f upstream.  Unfortunately some
> users of getrandom() don't expect it to block for long, and they need
> to be fixed before we can allow this change into stable.
>
> This doesn't directly revert that commit, but only weakens the ready
> condition used by getrandom() when the GRND_RANDOM flag is not set.
> Calls to getrandom() that return before the RNG is fully seeded will
> generate warnings, just like reads from /dev/urandom.
>
> https://bugs.launchpad.net/bugs/1780062
>
> (backported from ://salsa.debian.org/kernel-team/linux/raw/stretch/debian/patches/debian/random-make-getrandom-ready-earlier.patch)
> [smb: open code waiting in getrandom directly]
> Signed-off-by: Stefan Bader <[hidden email]>

Applied to cosmic/master-next and unstable/master, thanks!

--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team