Skip to content

Enabling FIPS mode on plain Ubuntu 22.04 and using crypto leads to infinite hang in CSPRNG #46200

Closed
@addaleax

Description

Version

v18.13.0, v19.4.0, main

Platform

Ubuntu 22.04 without modifications; Linux desktop-ua 5.15.0-57-generic #63-Ubuntu SMP Thu Nov 24 13:43:17 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

crypto

What steps will reproduce the bug?

Dockerfile

$ cat fips-loop.js 
const crypto = require('crypto');
crypto.setFips(1);
crypto.randomBytes(20, console.log);
$ gdb --args ./node-v19.4.0-linux-x64/bin/node ./fips-loop.js
[…]
(gdb) r
[…]
^C
[…]
(gdb) thread apply all bt
[…]
#0  0x0000555b0aef4018 in _dopr ()
#1  0x0000555b0aef5112 in BIO_vsnprintf ()
#2  0x0000555b0af952dd in ERR_vset_error ()
#3  0x0000555b0af95433 in ERR_set_error ()
#4  0x0000555b0afbcacb in evp_generic_fetch ()
#5  0x0000555b0afc2192 in EVP_RAND_fetch ()
#6  0x0000555b0b026660 in rand_new_drbg ()
#7  0x0000555b0b0277d6 in RAND_get0_public ()
#8  0x0000555b0b027858 in RAND_bytes_ex ()
#9  0x0000555b09ac730f in node::crypto::CSPRNG (buffer=0x555b0f0b7960, length=20) at ../src/crypto/crypto_util.cc:66
#10 0x0000555b09ab9054 in node::crypto::RandomBytesTraits::DeriveBits (env=0x555b0f32db30, params=..., unused=0x555b0f34cca0) at ../src/crypto/crypto_random.cc:69
#11 0x0000555b09abd1c3 in node::crypto::DeriveBitsJob<node::crypto::RandomBytesTraits>::DoThreadPoolWork (this=0x555b0f34cb90) at ../src/crypto/crypto_util.h:500
#12 0x0000555b097dd98c in node::ThreadPoolWork::ScheduleWork()::{lambda(uv_work_s*)#1}::operator()(uv_work_s*) const (__closure=0x0, req=0x555b0f34cbd8) at ../src/threadpoolwork-inl.h:44
#13 0x0000555b097dda7d in node::ThreadPoolWork::ScheduleWork()::{lambda(uv_work_s*)#1}::_FUN(uv_work_s*) () at ../src/threadpoolwork-inl.h:47
#14 0x0000555b0ac81a58 in worker (arg=0x0) at ../deps/uv/src/threadpool.c:122
#15 0x00007fafcb516b43 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#16 0x00007fafcb5a8a00 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

How often does it reproduce? Is there a required condition?

Always. No.

What is the expected behavior?

Some type of error indicating that OpenSSL is not configured properly for FIPS mode on the machine, which I assume this is the root cause here.

(I am not expecting this to really work and give me random bytes.)

What do you see instead?

Infinite hang.

Additional information

I think this is a problem that other people have run into before, e.g. #38633 (review) cc @danbev @richardlau

In the debugger, it’s visible that RAND_poll and RAND_status keep returning 1 but RAND_bytes keeps returning 0 (code).

Metadata

Assignees

No one assigned

    Labels

    cryptoIssues and PRs related to the crypto subsystem.opensslIssues and PRs related to the OpenSSL dependency.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions