RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1977214 - luks_format: Not compatible PBKDF2 options (using hash algorithm sha256)
Summary: luks_format: Not compatible PBKDF2 options (using hash algorithm sha256)
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Enterprise Linux 9
Classification: Red Hat
Component: libguestfs
Version: 9.0
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: beta
: ---
Assignee: Richard W.M. Jones
QA Contact: YongkuiGuo
URL:
Whiteboard:
: 1977228 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-06-29 08:22 UTC by YongkuiGuo
Modified: 2021-12-07 21:59 UTC (History)
7 users (show)

Fixed In Version: libguestfs-1.45.6-9.el9
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2021-12-07 21:55:02 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description YongkuiGuo 2021-06-29 08:22:08 UTC
Description of problem:
luks-format fails to format the device as a LUKS encrypted device on latest RHEL9.


Version-Release number of selected component (if applicable):
libguestfs-1.45.6-8.el9.x86_64
guestfs-tools-1.46.1-3.el9.1.x86_64
cryptsetup-2.3.6-2.el9.x86_64


How reproducible:
100%


Steps:

1. On rhel9 host with RHEL-9.0.0-20210626.0 compose
$ guestfish -N disk part-disk /dev/sda mbr : luks-format /dev/sda1 0
Enter key or passphrase ("key"):  --- set a passphrase
libguestfs: error: luks_format: Not compatible PBKDF2 options (using hash algorithm sha256)


Actual results:
As above

Expected results:
luks-format can be able to format a luks device as usual.

Additional info:
No this issue on RHEL8.5

Comment 1 Richard W.M. Jones 2021-06-29 09:53:43 UTC
The command we run is:

  command: cryptsetup '-d' '/tmp/cryptd2a020.key' 'open' '/dev/sda3' 'cryptsda3' '--type' 'luks'

which exits with code 1 and prints this on stderr:

  command: cryptsetup: stderr:
  Cannot open keyslot (using hash sha256).

This error comes from:

https://gitlab.com/cryptsetup/cryptsetup/-/blob/73cd60b1cc236968d4a60c4ad6772c66cbeb9e1b/lib/luks1/keymanage.c#L997

Is there anything we can do to collect more information?  eg.
Would cryptsetup luksDump of the device help?

Should I be worried that this error comes from the LUKS1 code?
As far as I know nothing should be using that.

Comment 2 Richard W.M. Jones 2021-06-29 10:04:20 UTC
Sorry, I'm confusing this bug with
https://bugzilla.redhat.com/show_bug.cgi?id=1977228 .  The
comment above applies to the other bug.  However although the
two error messages are slightly different, they do seem as if
they could be caused by the same underlying problem.

For *this* bug, I am able to reproduce it with libguestfs-1.45.6-8.el9
and not with 1.45.6-1.el9.

Nothing signficant changed between these versions so it's a bit
mysterious what could have caused this.

The command we are running is:

commandrvf: cryptsetup -q --key-slot 0 luksFormat /dev/sda1 /tmp/luksGQ07Jp
Not compatible PBKDF2 options (using hash algorithm sha256).

Is there any extra information we could collect here from
cryptsetup to help with diagnosing this?

Comment 3 Milan Broz 2021-06-29 10:12:38 UTC
(In reply to Richard W.M. Jones from comment #2)

> Is there any extra information we could collect here from
> cryptsetup to help with diagnosing this?

Yes, please run the command with --debug option and post the output here. thx!

Comment 4 Richard W.M. Jones 2021-06-29 10:51:41 UTC
$ virt-rescue --scratch 

><rescue> echo 123456 > /tmp/key
><rescue> cryptsetup --key-slot 0 luksFormat /dev/sda /tmp/key

WARNING!
========
This will overwrite data on /dev/sda irrevocably.

Are you sure? (Type 'yes' in capital letters): YES
Not compatible PBKDF2 options (using hash algorithm sha256).

><rescue> cryptsetup --debug --key-slot 0 luksFormat /dev/sda /tmp/key
# cryptsetup 2.3.6 processing "cryptsetup --debug --key-slot 0 luksFormat /dev/sda /tmp/key"
# Running command luksFormat.
# Locking memory.
# Installing SIGINT/SIGTERM handler.
# Unblocking interruption on signal.
# Allocating context for crypt device /dev/sda.
# Trying to open and read device /dev/sda with direct-io.
# Initialising device-mapper backend library.

WARNING!
========
This will overwrite data on /dev/sda irrevocably.

Are you sure? (Type 'yes' in capital letters): YES
# File descriptor passphrase entry requested.
# Crypto backend (OpenSSL 3.0.0-alpha16 6 May 2021) initialized in cryptsetup library version 2.3.6.
# Detected kernel Linux 5.12.0-1.el9.x86_64 x86_64.
# Only 1 active CPUs detected, PBKDF threads decreased from 4 to 1.
# Not enough physical memory detected, PBKDF max memory decreased from 1048576kB to 624726kB.
# PBKDF argon2i, time_ms 2000 (iterations 0), max_memory_kb 624726, parallel_threads 1.
# Formatting device /dev/sda as type LUKS2.
# Topology: IO (512/0), offset = 0; Required alignment is 1048576 bytes.
# Checking if cipher aes-xts-plain64 is usable.
# Using userspace crypto wrapper to access keyslot area.
# Formatting LUKS2 with JSON metadata area 12288 bytes and keyslots area 16744448 bytes.
# Creating new digest 0 (pbkdf2).
# Setting PBKDF2 type key digest 0.
# Running pbkdf2(sha256) benchmark.
Not compatible PBKDF2 options (using hash algorithm sha256).
# Releasing crypt device /dev/sda context.
# Releasing device-mapper backend.
# Closing read only fd for /dev/sda.
# Unlocking memory.
Command failed with code -1 (wrong or missing parameters).

Comment 5 Milan Broz 2021-06-29 11:00:10 UTC
Thanks, this is very strange - sha256 should be always available in OpenSSL.

There is a patch for OpenSSL3 support upstream (and that should be applied for RHEL9 - decision to skip Fedora and switch to OpenSSL3 alpha in RHEL9 was really not a clever decision).
https://gitlab.com/cryptsetup/cryptsetup/-/merge_requests/178

But it still does not explain this fail here... If you run "cryptsetup benchmark --pbkdf pbkdf2 --hash sha256" - does it works or it is N/A?
Does ti work for other hash? (sha1)

If you use --type luks1 - does it work?

All this seems to me like some OpenSSL incompatibility.

Comment 6 Richard W.M. Jones 2021-06-29 11:24:02 UTC
My immediate thoughts are:

 - What other packages apart from cryptsetup might affect this?
   Presumably openssl.  Also the kernel?
   (I have openssl-3.0.0-0.alpha16.4.el9.x86_64)

 - Could optional packages be involved (ie. Suggests/Recommends)?

 - Could an RPM %pre/%post script be required to run in order
   for sha256 to work?  Could it require a kernel module to be loaded?

 - Could it depend on the amount of memory?  The memory inside the
   appliance is restricted.

Here are the results you asked for:

$ virt-rescue --scratch

><rescue> cryptsetup benchmark --pbkdf pbkdf2 --hash sha256 
# Tests are approximate using memory only (no storage IO).
PBKDF2-sha256        N/A

(this command silently exited with code 1)

><rescue> cryptsetup benchmark --pbkdf pbkdf2 --hash sha1   
# Tests are approximate using memory only (no storage IO).
PBKDF2-sha1          N/A

(this command also silently exited with code 1)

><rescue> echo 123456 > /tmp/key
><rescue> cryptsetup --key-slot 0 luksFormat /dev/sda /tmp/key --type luks1

WARNING!
========
This will overwrite data on /dev/sda irrevocably.

Are you sure? (Type 'yes' in capital letters): YES
Not compatible PBKDF2 options (using hash algorithm sha256).

(also exited with code 1)

Comment 7 Milan Broz 2021-06-29 11:28:54 UTC
It is either OpenSSL or some change that affects benchmark (broken proces timing, seen this several time mainly for virtual machines).

If you use "--type luks1 ---pbkdf-force-iterations 1000" parameters for format, does it move forward? (This should skip benchmark completelly.)

Anyway, we need to install centos machine and reproduce this... this looks very strange to me.

Comment 8 Richard W.M. Jones 2021-06-29 11:34:16 UTC
A different error this time:

$ virt-rescue --scratch
><rescue> echo 123456 > /tmp/key 
><rescue> cryptsetup --debug --key-slot 0 luksFormat /dev/sda /tmp/key --type luks1 --pbkdf-force-iterations=1000 
# cryptsetup 2.3.6 processing "cryptsetup --debug --key-slot 0 luksFormat /dev/sda /tmp/key --type luks1 --pbkdf-force-iterations=1000"
# Running command luksFormat.
# Locking memory.
# Installing SIGINT/SIGTERM handler.
# Unblocking interruption on signal.
# Allocating context for crypt device /dev/sda.
# Trying to open and read device /dev/sda with direct-io.
# Initialising device-mapper backend library.

WARNING!
========
This will overwrite data on /dev/sda irrevocably.

Are you sure? (Type 'yes' in capital letters): YES
# File descriptor passphrase entry requested.
# Crypto backend (OpenSSL 3.0.0-alpha16 6 May 2021) initialized in cryptsetup library version 2.3.6.
# Detected kernel Linux 5.13.0-0.rc7.51.el9.x86_64 x86_64.
# PBKDF pbkdf2-sha256, time_ms 0 (iterations 1000).
# Formatting device /dev/sda as type LUKS1.
# Topology: IO (512/0), offset = 0; Required alignment is 1048576 bytes.
# Checking if cipher aes-xts-plain64 is usable.
# Using userspace crypto wrapper to access keyslot area.
# Generating LUKS header version 1 using hash sha256, aes, xts-plain64, MK 64 bytes
# Reusing PBKDF values (no benchmark flag is set).
Cannot create LUKS header: header digest failed (using hash sha256).
# Releasing crypt device /dev/sda context.
# Releasing device-mapper backend.
# Closing read only fd for /dev/sda.
# Unlocking memory.
Command failed with code -1 (wrong or missing parameters).


Without --type luks1 it fails differently again:

><rescue> cryptsetup --debug --key-slot 0 luksFormat /dev/sda /tmp/key --pbkdf-force-iterations=1000 
# cryptsetup 2.3.6 processing "cryptsetup --debug --key-slot 0 luksFormat /dev/sda /tmp/key --pbkdf-force-iterations=1000"
# Running command luksFormat.
# Locking memory.
# Installing SIGINT/SIGTERM handler.
# Unblocking interruption on signal.
# Allocating context for crypt device /dev/sda.
# Trying to open and read device /dev/sda with direct-io.
# Initialising device-mapper backend library.

WARNING!
========
This will overwrite data on /dev/sda irrevocably.

Are you sure? (Type 'yes' in capital letters): YES
# File descriptor passphrase entry requested.
# Crypto backend (OpenSSL 3.0.0-alpha16 6 May 2021) initialized in cryptsetup library version 2.3.6.
# Detected kernel Linux 5.13.0-0.rc7.51.el9.x86_64 x86_64.
# Only 1 active CPUs detected, PBKDF threads decreased from 4 to 1.
# Not enough physical memory detected, PBKDF max memory decreased from 1048576kB to 620238kB.
# PBKDF argon2i, time_ms 0 (iterations 1000), max_memory_kb 620238, parallel_threads 1.
# Formatting device /dev/sda as type LUKS2.
# Topology: IO (512/0), offset = 0; Required alignment is 1048576 bytes.
# Checking if cipher aes-xts-plain64 is usable.
# Using userspace crypto wrapper to access keyslot area.
# Formatting LUKS2 with JSON metadata area 12288 bytes and keyslots area 16744448 bytes.
# Creating new digest 0 (pbkdf2).
# Setting PBKDF2 type key digest 0.
# Releasing crypt device /dev/sda context.
# Releasing device-mapper backend.
# Closing read only fd for /dev/sda.
# Unlocking memory.
Command failed with code -1 (wrong or missing parameters).
><rescue> echo $?
1

Comment 9 Richard W.M. Jones 2021-06-29 11:41:26 UTC
The command works on the same host on baremetal, so it's
likely to be something to do with the minimized appliance
environment (or virtualization).

# nbdkit -U /tmp/sock memory 1G
# modprobe nbd
# nbd-client -unix /tmp/sock /dev/nbd0
Warning: the oldstyle protocol is no longer supported.
This method now uses the newstyle protocol with a default export
Negotiation: ..size = 1024MB
Connected /dev/nbd0

# cryptsetup --key-slot 0 luksFormat /dev/nbd0 /tmp/key 

WARNING!
========
This will overwrite data on /dev/nbd0 irrevocably.

Are you sure? (Type 'yes' in capital letters): YES

(short pause, then exit code 0)

Comment 10 Milan Broz 2021-06-29 13:32:00 UTC
So I tried to "cripple" openssl3 installation as musch as possible, and it still works with cryptsetup (with the same centos9 versions).
No idea what can be wrong there - it must be something really specific to the appliance installation.

Maybe try some openssl commandline test if it works outside libcryptsetup (at least "openssl help" should print supported algorithms and "openssl speed sha256" should run a benchmark),
bu you need to install openssl cli for that.

Comment 11 Richard W.M. Jones 2021-06-29 13:47:18 UTC
I think I see what it is.  We save the original configuration files
at build time (since they cannot be reconstructed from the host filesystem
by https://libguestfs.org/supermin.1.html).  This means that if a new
configuration file is added, then it won't be present inside the
appliance.

In this case openssl added a new configuration file (actually a symlink,
/etc/crypto-policies/back-ends/opensslcnf.config).  When this file
is missing openssl fails at start up quite badly:

$ sudo bash -c 'echo openssl > /usr/lib64/guestfs/supermin.d/zz-rwmj-openssl'
$ virt-rescue --scratch
><rescue> openssl help
FATAL: Startup failure (dev note: apps_startup()) for openssl
40B78BB6957F0000:error:80000002:system library:process_include:No such file or directory:crypto/conf/conf_def.c:803:calling stat(/etc/crypto-policies/back-ends/opensslcnf.config)
40B78BB6957F0000:error:07000075:configuration file routines:ssl_module_init:ssl command section empty:crypto/conf/conf_ssl.c:96:name=system_default, value=crypto_policy
40B78BB6957F0000:error:0700006D:configuration file routines:module_run:module initialization error:crypto/conf/conf_mod.c:242:module=ssl_conf, value=ssl_module retcode=-1      

So I'm going to rebuild libguestfs now which will pick up the new file
and see if that solves it.

Comment 12 Milan Broz 2021-06-29 13:51:41 UTC
(In reply to Richard W.M. Jones from comment #11)
> In this case openssl added a new configuration file (actually a symlink,
> /etc/crypto-policies/back-ends/opensslcnf.config).  When this file
> is missing openssl fails at start up quite badly:

yes, that's it. I tried to remove openssl config but forgot this one - it is from different package (crypto-policies).

Comment 13 Richard W.M. Jones 2021-06-29 14:17:11 UTC
My guess above turned out to be the right one:

>  - Could an RPM %pre/%post script be required [...]

crypto-policies generates these symlinks through a complicated
%post script:

https://gitlab.com/redhat/centos-stream/rpms/crypto-policies/-/blob/7c076748f30246f7f94d6af03de8e4c95f99841c/crypto-policies.spec#L107

supermin doesn't run %post scripts.  Actually nor do a bunch
of dnf-like tools (bazel being another one, used by kubernetes).
So while this is not necessarily a bug, it seems overcomplicated.

Even with dnf this script is not going to work reliably.  It depends on
the exact state of FIPS at RPM install time.  But there are a
couple of problems with that:

(1) The FIPS state might change after install, eg. if the user enables
or disables FIPS.

(2) It won't work for restricted install environments such as
installing into a chroot, or installing in a container with a different
kernel (such as one that does not support FIPS but then moving the
binary container to one which does).

Seems to me like it would be better to do this test at run time; or
have the config files be static; and also make openssl cope better
with the configuration file being missing.

Comment 14 Richard W.M. Jones 2021-06-29 14:44:16 UTC
I'm prepared to add this downstream patch to libguestfs which
will work around the issue:

https://github.com/libguestfs/libguestfs/commit/18c910479cb6465bcd3954c5d07f3ab6df5c944a

Comment 17 YongkuiGuo 2021-06-30 02:21:13 UTC
Verified with package:
libguestfs-1.45.6-9.el9.x86_64

Steps:

1.On rhel9 host with RHEL-9.0.0-20210626.0 compose
$ guestfish -N disk part-disk /dev/sda mbr : luks-format /dev/sda1 0
Enter key or passphrase ("key"):  --- set a passphrase

No error like this "luks_format: Not compatible PBKDF2 options (using hash algorithm sha256)".

2.
$ virt-rescue --scratch
><rescue> echo 123456 > /tmp/key
><rescue> cryptsetup --key-slot 0 luksFormat /dev/sda /tmp/key

WARNING!
========
This will overwrite data on /dev/sda irrevocably.

Are you sure? (Type 'yes' in capital letters): YES
><rescue> echo $?
0
><rescue>

Comment 18 Xiaodai Wang 2021-06-30 02:28:31 UTC
*** Bug 1977228 has been marked as a duplicate of this bug. ***


Note You need to log in before you can comment on or make changes to this bug.