diff mbox series

openssl: Enable os option for with-rand-seed as well

Message ID 20190917184947.2244823-1-raj.khem@gmail.com
State Accepted
Commit 8b4edb8552b238680d8dcef565e830a8e28a223c
Headers show
Series openssl: Enable os option for with-rand-seed as well | expand

Commit Message

Khem Raj Sept. 17, 2019, 6:49 p.m. UTC
with openSSL 1.1.1d we start seeing errors like

Error Generating Key
139979727451584:error:2406C06E:random number generator:RAND_DRBG_instantiate:error retrieving entropy:../openssl-1.1.1d/crypto/rand/drbg_lib.c:342:

when using openssl from openssl-native on build hosts, this is due to
limiting the random seed to devrandom, to support older hosts, since the
option allows to have a comma separated list of methods to try, we can
try the default first and if that fails then fallback to devrandom, this
will ensure that it keeps working with build systems which dont support
getrandom()

Signed-off-by: Khem Raj <raj.khem@gmail.com>

Cc: Adrian Bunk <bunk@stusta.de>
Cc: Alexander Kanavin <alex.kanavin@gmail.com>
---
 meta/recipes-connectivity/openssl/openssl_1.1.1d.bb | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

-- 
2.23.0

-- 
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core

Comments

Adrian Bunk Sept. 18, 2019, 7:20 a.m. UTC | #1
On Tue, Sep 17, 2019 at 11:49:47AM -0700, Khem Raj wrote:
> with openSSL 1.1.1d we start seeing errors like

> 

> Error Generating Key

> 139979727451584:error:2406C06E:random number generator:RAND_DRBG_instantiate:error retrieving entropy:../openssl-1.1.1d/crypto/rand/drbg_lib.c:342:

> 

> when using openssl from openssl-native on build hosts, this is due to

> limiting the random seed to devrandom, to support older hosts, since the

> option allows to have a comma separated list of methods to try, we can

> try the default first and if that fails then fallback to devrandom, this

> will ensure that it keeps working with build systems which dont support

> getrandom()

>...


Thanks for fixing this problem!

cu
Adrian

-- 

       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed

-- 
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core
Martin Jansa Sept. 18, 2019, 2:25 p.m. UTC | #2
Thanks for fix, I was seeing these issues in couple components using
nodejs-native (example bellow) and can confirm that this is now fixed.

internal/crypto/random.js:118
  if (ex) throw ex;
          ^

Error: error:2406C06E:random number generator:RAND_DRBG_instantiate:error
retrieving entropy
    at handleError (internal/crypto/random.js:117:14)
    at Object.randomBytes (internal/crypto/random.js:52:19)
    at
TOPDIR/BUILD/work/x86_64-linux/node-gyp-native/0.12.2+gitAUTOINC+7e98c99ce7-r4/recipe-sysroot-native/usr/lib/node_modules/npm/lib/npm.js:424:32
    at Object.<anonymous>
(TOPDIR/BUILD/work/x86_64-linux/node-gyp-native/0.12.2+gitAUTOINC+7e98c99ce7-r4/recipe-sysroot-native/usr/lib/node_modules/npm/lib/npm.js:476:3)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)

On Tue, Sep 17, 2019 at 8:50 PM Khem Raj <raj.khem@gmail.com> wrote:

> with openSSL 1.1.1d we start seeing errors like

>

> Error Generating Key

> 139979727451584:error:2406C06E:random number

> generator:RAND_DRBG_instantiate:error retrieving

> entropy:../openssl-1.1.1d/crypto/rand/drbg_lib.c:342:

>

> when using openssl from openssl-native on build hosts, this is due to

> limiting the random seed to devrandom, to support older hosts, since the

> option allows to have a comma separated list of methods to try, we can

> try the default first and if that fails then fallback to devrandom, this

> will ensure that it keeps working with build systems which dont support

> getrandom()

>

> Signed-off-by: Khem Raj <raj.khem@gmail.com>

> Cc: Adrian Bunk <bunk@stusta.de>

> Cc: Alexander Kanavin <alex.kanavin@gmail.com>

> ---

>  meta/recipes-connectivity/openssl/openssl_1.1.1d.bb | 6 +++---

>  1 file changed, 3 insertions(+), 3 deletions(-)

>

> diff --git a/meta/recipes-connectivity/openssl/openssl_1.1.1d.bb

> b/meta/recipes-connectivity/openssl/openssl_1.1.1d.bb

> index 080d1a8bb7..072f727e0b 100644

> --- a/meta/recipes-connectivity/openssl/openssl_1.1.1d.bb

> +++ b/meta/recipes-connectivity/openssl/openssl_1.1.1d.bb

> @@ -43,10 +43,10 @@ do_configure[cleandirs] = "${B}"

>  EXTRA_OECONF_append_libc-musl = " no-async"

>  EXTRA_OECONF_append_libc-musl_powerpc64 = " no-asm"

>

> -# This prevents openssl from using getrandom() which is not available on

> older glibc versions

> +# adding devrandom prevents openssl from using getrandom() which is not

> available on older glibc versions

>  # (native versions can be built with newer glibc, but then relocated onto

> a system with older glibc)

> -EXTRA_OECONF_class-native = "--with-rand-seed=devrandom"

> -EXTRA_OECONF_class-nativesdk = "--with-rand-seed=devrandom"

> +EXTRA_OECONF_class-native = "--with-rand-seed=os,devrandom"

> +EXTRA_OECONF_class-nativesdk = "--with-rand-seed=os,devrandom"

>

>  # Relying on hardcoded built-in paths causes openssl-native to not be

> relocateable from sstate.

>  CFLAGS_append_class-native = " -DOPENSSLDIR=/not/builtin

> -DENGINESDIR=/not/builtin"

> --

> 2.23.0

>

> --

> _______________________________________________

> Openembedded-core mailing list

> Openembedded-core@lists.openembedded.org

> http://lists.openembedded.org/mailman/listinfo/openembedded-core

>
<div dir="ltr">Thanks for fix, I was seeing these issues in couple components using nodejs-native (example bellow) and can confirm that this is now fixed.<div><br></div><div>internal/crypto/random.js:118<br>  if (ex) throw ex;<br>          ^<br><br>Error: error:2406C06E:random number generator:RAND_DRBG_instantiate:error retrieving entropy<br>    at handleError (internal/crypto/random.js:117:14)<br>    at Object.randomBytes (internal/crypto/random.js:52:19)<br>    at TOPDIR/BUILD/work/x86_64-linux/node-gyp-native/0.12.2+gitAUTOINC+7e98c99ce7-r4/recipe-sysroot-native/usr/lib/node_modules/npm/lib/npm.js:424:32<br>    at Object.&lt;anonymous&gt; (TOPDIR/BUILD/work/x86_64-linux/node-gyp-native/0.12.2+gitAUTOINC+7e98c99ce7-r4/recipe-sysroot-native/usr/lib/node_modules/npm/lib/npm.js:476:3)<br>    at Module._compile (internal/modules/cjs/loader.js:778:30)<br>    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)<br>    at Module.load (internal/modules/cjs/loader.js:653:32)<br>    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)<br>    at Function.Module._load (internal/modules/cjs/loader.js:585:3)<br>    at Module.require (internal/modules/cjs/loader.js:692:17)<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Sep 17, 2019 at 8:50 PM Khem Raj &lt;<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">with openSSL 1.1.1d we start seeing errors like<br>
<br>
Error Generating Key<br>
139979727451584:error:2406C06E:random number generator:RAND_DRBG_instantiate:error retrieving entropy:../openssl-1.1.1d/crypto/rand/drbg_lib.c:342:<br>
<br>
when using openssl from openssl-native on build hosts, this is due to<br>
limiting the random seed to devrandom, to support older hosts, since the<br>
option allows to have a comma separated list of methods to try, we can<br>
try the default first and if that fails then fallback to devrandom, this<br>
will ensure that it keeps working with build systems which dont support<br>
getrandom()<br>
<br>
Signed-off-by: Khem Raj &lt;<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>&gt;<br>

Cc: Adrian Bunk &lt;<a href="mailto:bunk@stusta.de" target="_blank">bunk@stusta.de</a>&gt;<br>
Cc: Alexander Kanavin &lt;<a href="mailto:alex.kanavin@gmail.com" target="_blank">alex.kanavin@gmail.com</a>&gt;<br>
---<br>
 meta/recipes-connectivity/openssl/<a href="http://openssl_1.1.1d.bb" rel="noreferrer" target="_blank">openssl_1.1.1d.bb</a> | 6 +++---<br>
 1 file changed, 3 insertions(+), 3 deletions(-)<br>
<br>
diff --git a/meta/recipes-connectivity/openssl/<a href="http://openssl_1.1.1d.bb" rel="noreferrer" target="_blank">openssl_1.1.1d.bb</a> b/meta/recipes-connectivity/openssl/<a href="http://openssl_1.1.1d.bb" rel="noreferrer" target="_blank">openssl_1.1.1d.bb</a><br>
index 080d1a8bb7..072f727e0b 100644<br>
--- a/meta/recipes-connectivity/openssl/<a href="http://openssl_1.1.1d.bb" rel="noreferrer" target="_blank">openssl_1.1.1d.bb</a><br>
+++ b/meta/recipes-connectivity/openssl/<a href="http://openssl_1.1.1d.bb" rel="noreferrer" target="_blank">openssl_1.1.1d.bb</a><br>
@@ -43,10 +43,10 @@ do_configure[cleandirs] = &quot;${B}&quot;<br>
 EXTRA_OECONF_append_libc-musl = &quot; no-async&quot;<br>
 EXTRA_OECONF_append_libc-musl_powerpc64 = &quot; no-asm&quot;<br>
<br>
-# This prevents openssl from using getrandom() which is not available on older glibc versions<br>
+# adding devrandom prevents openssl from using getrandom() which is not available on older glibc versions<br>
 # (native versions can be built with newer glibc, but then relocated onto a system with older glibc)<br>
-EXTRA_OECONF_class-native = &quot;--with-rand-seed=devrandom&quot;<br>
-EXTRA_OECONF_class-nativesdk = &quot;--with-rand-seed=devrandom&quot;<br>
+EXTRA_OECONF_class-native = &quot;--with-rand-seed=os,devrandom&quot;<br>
+EXTRA_OECONF_class-nativesdk = &quot;--with-rand-seed=os,devrandom&quot;<br>
<br>
 # Relying on hardcoded built-in paths causes openssl-native to not be relocateable from sstate.<br>
 CFLAGS_append_class-native = &quot; -DOPENSSLDIR=/not/builtin -DENGINESDIR=/not/builtin&quot;<br>
-- <br>
2.23.0<br>
<br>
-- <br>
_______________________________________________<br>
Openembedded-core mailing list<br>
<a href="mailto:Openembedded-core@lists.openembedded.org" target="_blank">Openembedded-core@lists.openembedded.org</a><br>
<a href="http://lists.openembedded.org/mailman/listinfo/openembedded-core" rel="noreferrer" target="_blank">http://lists.openembedded.org/mailman/listinfo/openembedded-core</a><br>
</blockquote></div>
-- 
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core
Andrey Zhizhikin Sept. 20, 2019, 1:13 p.m. UTC | #3
Hello Raj,

On Tue, Sep 17, 2019 at 8:50 PM Khem Raj <raj.khem@gmail.com> wrote:
>

> with openSSL 1.1.1d we start seeing errors like

>

> Error Generating Key

> 139979727451584:error:2406C06E:random number generator:RAND_DRBG_instantiate:error retrieving entropy:../openssl-1.1.1d/crypto/rand/drbg_lib.c:342:

>

> when using openssl from openssl-native on build hosts, this is due to

> limiting the random seed to devrandom, to support older hosts, since the

> option allows to have a comma separated list of methods to try, we can

> try the default first and if that fails then fallback to devrandom, this

> will ensure that it keeps working with build systems which dont support

> getrandom()

>

> Signed-off-by: Khem Raj <raj.khem@gmail.com>

> Cc: Adrian Bunk <bunk@stusta.de>

> Cc: Alexander Kanavin <alex.kanavin@gmail.com>

> ---


Just as a test report for this patch:

I've tested this patch on the HW (i.MX8M Mini EVK) and unfortunately
my sshd given up with a message: PRNG is not seeded

Reverting commits (effectively rolling back to openssl 1.1.1c) made
sshd operable again.:
53b5654d6e openssl: Enable os option for with-rand-seed as well
2c6b9b918c openssl: Upgrade 1.1.1c -> 1.1.1d

I'm not sure whether this is related to the Kernel used in i.MX8M Mini
series or the openssl version used...

I'd try to use a different HW to verify this patch further (perhaps
Altera CV) to see if the sshd is broken there as well.

-- andrey
-- 
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core
Mikko Rapeli Sept. 20, 2019, 1:38 p.m. UTC | #4
On Fri, Sep 20, 2019 at 03:13:44PM +0200, Andrey Zhizhikin wrote:
> Hello Raj,

> 

> On Tue, Sep 17, 2019 at 8:50 PM Khem Raj <raj.khem@gmail.com> wrote:

> >

> > with openSSL 1.1.1d we start seeing errors like

> >

> > Error Generating Key

> > 139979727451584:error:2406C06E:random number generator:RAND_DRBG_instantiate:error retrieving entropy:../openssl-1.1.1d/crypto/rand/drbg_lib.c:342:

> >

> > when using openssl from openssl-native on build hosts, this is due to

> > limiting the random seed to devrandom, to support older hosts, since the

> > option allows to have a comma separated list of methods to try, we can

> > try the default first and if that fails then fallback to devrandom, this

> > will ensure that it keeps working with build systems which dont support

> > getrandom()

> >

> > Signed-off-by: Khem Raj <raj.khem@gmail.com>

> > Cc: Adrian Bunk <bunk@stusta.de>

> > Cc: Alexander Kanavin <alex.kanavin@gmail.com>

> > ---

> 

> Just as a test report for this patch:

> 

> I've tested this patch on the HW (i.MX8M Mini EVK) and unfortunately

> my sshd given up with a message: PRNG is not seeded

> 

> Reverting commits (effectively rolling back to openssl 1.1.1c) made

> sshd operable again.:

> 53b5654d6e openssl: Enable os option for with-rand-seed as well

> 2c6b9b918c openssl: Upgrade 1.1.1c -> 1.1.1d


Do you have rng-tools on the image? That helped me with the kernel random pool
initialization for sshd in iMX8 and openssl 1.1.1x.

I don't see how 53b5654d6e could change this behavior for target openssl.
2c6b9b918c could change the behavior and would be suprise. Maybe also
target recipe needs --with-rand-seed=os,devrandom on iMX8 or similar platforms.

-Mikko
-- 
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core
Adrian Bunk Sept. 20, 2019, 2:03 p.m. UTC | #5
On Fri, Sep 20, 2019 at 01:38:29PM +0000, Mikko.Rapeli@bmw.de wrote:
> On Fri, Sep 20, 2019 at 03:13:44PM +0200, Andrey Zhizhikin wrote:

> > Hello Raj,

> > 

> > On Tue, Sep 17, 2019 at 8:50 PM Khem Raj <raj.khem@gmail.com> wrote:

> > >

> > > with openSSL 1.1.1d we start seeing errors like

> > >

> > > Error Generating Key

> > > 139979727451584:error:2406C06E:random number generator:RAND_DRBG_instantiate:error retrieving entropy:../openssl-1.1.1d/crypto/rand/drbg_lib.c:342:

> > >

> > > when using openssl from openssl-native on build hosts, this is due to

> > > limiting the random seed to devrandom, to support older hosts, since the

> > > option allows to have a comma separated list of methods to try, we can

> > > try the default first and if that fails then fallback to devrandom, this

> > > will ensure that it keeps working with build systems which dont support

> > > getrandom()

> > >

> > > Signed-off-by: Khem Raj <raj.khem@gmail.com>

> > > Cc: Adrian Bunk <bunk@stusta.de>

> > > Cc: Alexander Kanavin <alex.kanavin@gmail.com>

> > > ---

> > 

> > Just as a test report for this patch:

> > 

> > I've tested this patch on the HW (i.MX8M Mini EVK) and unfortunately

> > my sshd given up with a message: PRNG is not seeded

> 

> > Reverting commits (effectively rolling back to openssl 1.1.1c) made

> > sshd operable again.:

> > 53b5654d6e openssl: Enable os option for with-rand-seed as well

> > 2c6b9b918c openssl: Upgrade 1.1.1c -> 1.1.1d

> 

> Do you have rng-tools on the image? That helped me with the kernel random pool

> initialization for sshd in iMX8 and openssl 1.1.1x.

> 

> I don't see how 53b5654d6e could change this behavior for target openssl.

> 2c6b9b918c could change the behavior and would be suprise.

>...


OpenSSL is full of surprises...

CHANGES says:
    Linux kernels 4.8 and later, don't have a reliable way to detect 
    that /dev/urandom has been properly seeded, so a failure is raised 
    for this case (i.e. the getentropy(2) call has already failed).

It seems to be correct to give an error here, and lack of rng-tools 
and/or kernel support for the iMX8 RNG is something that should be
fixed by the user.

OTOH, this kind of changes make it hard to justify upgrading openssl
in stable branches.

> -Mikko


cu
Adrian

-- 

       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed

-- 
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core
Andrey Zhizhikin Sept. 20, 2019, 2:04 p.m. UTC | #6
On Fri, Sep 20, 2019 at 3:38 PM <Mikko.Rapeli@bmw.de> wrote:
>

>

> Do you have rng-tools on the image? That helped me with the kernel random pool

> initialization for sshd in iMX8 and openssl 1.1.1x.


No, but I would definitely try it! Thanks a lot for the tip here!

>

> I don't see how 53b5654d6e could change this behavior for target openssl.

> 2c6b9b918c could change the behavior and would be suprise. Maybe also

> target recipe needs --with-rand-seed=os,devrandom on iMX8 or similar platforms.


This has puzzled me as well.. Actually, the 53b5654d6e is related to
2c6b9b918c in a way that it fixes the build issue with various
components. That was the reason I reverted both of them since they are
going in pair. Strangely enough, when reverting the openssl version to
1.1.1c - sshd starts to work normally.

I'm building now Arria10 to see if I can reproduce the issue there as well.

-- andrey
-- 
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core
Andrey Zhizhikin Sept. 23, 2019, 1:03 p.m. UTC | #7
> ...


Just as a follow-up on this issue, if someone else would stumbled upon the same:

I've built cyclone5 machine off the master and it was 100% operable.
Then I looked at the i.MX8M configuration and found out that openssl
recipe was overlaid for me with the option --with-rand-seed=devrandom,
which effectively cause this erratic behavior. Changing the compile
option to --with-rand-seed=os,devrandom made an SSHD fully operable
again, so indeed this is the right option to use for devices which are
not properly seeding /dev/urandom.

Mikko/Adrian, thank a lot for your advises here in the direction to look into!


-- andrey
-- 
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core
diff mbox series

Patch

diff --git a/meta/recipes-connectivity/openssl/openssl_1.1.1d.bb b/meta/recipes-connectivity/openssl/openssl_1.1.1d.bb
index 080d1a8bb7..072f727e0b 100644
--- a/meta/recipes-connectivity/openssl/openssl_1.1.1d.bb
+++ b/meta/recipes-connectivity/openssl/openssl_1.1.1d.bb
@@ -43,10 +43,10 @@  do_configure[cleandirs] = "${B}"
 EXTRA_OECONF_append_libc-musl = " no-async"
 EXTRA_OECONF_append_libc-musl_powerpc64 = " no-asm"
 
-# This prevents openssl from using getrandom() which is not available on older glibc versions
+# adding devrandom prevents openssl from using getrandom() which is not available on older glibc versions
 # (native versions can be built with newer glibc, but then relocated onto a system with older glibc)
-EXTRA_OECONF_class-native = "--with-rand-seed=devrandom"
-EXTRA_OECONF_class-nativesdk = "--with-rand-seed=devrandom"
+EXTRA_OECONF_class-native = "--with-rand-seed=os,devrandom"
+EXTRA_OECONF_class-nativesdk = "--with-rand-seed=os,devrandom"
 
 # Relying on hardcoded built-in paths causes openssl-native to not be relocateable from sstate.
 CFLAGS_append_class-native = " -DOPENSSLDIR=/not/builtin -DENGINESDIR=/not/builtin"