Bug 2239146 - perl-Crypt-Argon2 crashes
Summary: perl-Crypt-Argon2 crashes
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: perl-Crypt-Argon2
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: ---
Assignee: Charles R. Anderson
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks: 2118421
TreeView+ depends on / blocked
 
Reported: 2023-09-15 13:42 UTC by Charles R. Anderson
Modified: 2023-09-18 12:25 UTC (History)
7 users (show)

Fixed In Version: perl-Crypt-Argon2-0.019-6.fc40
Doc Type: If docs needed, set a value
Doc Text:
Clone Of: 2118421
Environment:
Last Closed: 2023-09-17 15:59:07 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Charles R. Anderson 2023-09-15 13:42:14 UTC
+++ This bug was initially created as a clone of Bug #2118421 +++

--- Additional comment from Lester Hightower on 2023-09-14 20:58:06 UTC ---

Charles -

I had some time today to look into this more deeply. I installed a clean Fedora Server 38 VM, installed the packages that I needed to build File::KDBX, and got the exact same result that you reported here. Then I dug into t/kdbx4.t and t/kdf.t (using the tv command from Test::Verbose) and confirmed that both tests die in their "Argon2" test sections. I then used cpanm to install Crypt::Argon2 0.019 into my home directory (under ~/perl/) and confirmed that it (my locally built copy) works with File::KDBX but that the Crypt::Argon2 0.019 that is packaged in Fedora 38 causes a segmentation fault.

For your reference, I used this cpanm command, run as hightowe (not root), to install Crypt::Argon2 0.019 into ~/perl/ for myself: cpanm -f Crypt::Argon2
  ** Note that the -f (force) is required because otherwise cpanm will detect the packaged, system-wide Crypt::Argon2 0.019 and skip it.

My test VM is now in a state where I can demonstrate both conditions immediately, as shown here:

[hightowe@localhost File-KDBX-0.906]$ make test
[...snip...]
Test Summary Report
-------------------
t/kdbx4.t            (Wstat: 132 (Signal: ILL, dumped core) Tests: 0 Failed: 0)
  Non-zero wait status: 132
  Parse errors: No plan found in TAP output
t/kdf.t              (Wstat: 132 (Signal: ILL, dumped core) Tests: 1 Failed: 0)
  Non-zero wait status: 132
  Parse errors: No plan found in TAP output
Files=27, Tests=178,  8 wallclock secs ( 0.04 usr  0.05 sys +  3.19 cusr  0.92 csys =  4.20 CPU)
Result: FAIL
Failed 2/27 test programs. 0/178 subtests failed.
make: *** [Makefile:1103: test_dynamic] Error 255


[hightowe@localhost File-KDBX-0.906]$ PERL5LIB=/home/hightowe/perl5/lib/perl5/ make test 
[...snip...]
All tests successful.
Files=27, Tests=193,  8 wallclock secs ( 0.07 usr  0.03 sys +  3.72 cusr  0.63 csys =  4.45 CPU)
Result: PASS

The only difference in those two is which Crypt::Argon2 0.019 is being used, the Fedora packaged one in the first case and my locally built and installed one in the second case.

There appears to be a problem with the packaging of Crypt::Argon2 0.019 in Fedora.

--- Additional comment from Lester Hightower on 2023-09-14 21:02:54 UTC ---

And just a little more follow up on this, kpcli-4.0 works perfectly when File::KDBX is installed locally, alongside a good Crypt::Argon2 0.019:

# Installing File::KDBX into ~/perl5 using the Crypt::Argon2 from ~/perl5

$ PERL5LIB=/home/hightowe/perl5/lib/perl5/ cpanm File::KDBX
--> Working on File::KDBX
Fetching http://www.cpan.org/authors/id/C/CC/CCM/File-KDBX-0.906.tar.gz ... OK
Configuring File-KDBX-0.906 ... OK
Building and testing File-KDBX-0.906 ... OK
Successfully installed File-KDBX-0.906
1 distribution installed

# Running kpcli-4.0.pl with a preference for modules within ~/perl5

$ PERL5LIB=/home/hightowe/perl5/lib/perl5/ ./kpcli-4.0.pl

KeePass CLI (kpcli-4.0) v4.0 is ready for operation.
Type 'help' for a description of available commands.
Type 'help <command>' for details on individual commands.

kpcli-4.0:/> vers
kpcli: 4.0
Perl: v5.36.1
Operating system: linux ("Fedora Linux 38 (Server Edition)")
ReadLine being used: Term::ReadLine::Gnu

Pivotal Perl Modules for kpcli
 * File::KeePass: 2.03
 * File::KDBX: 0.906
 * Term::ShellUI: 0.92
 * Term::ReadKey: 2.38
 * Term::ReadLine: 1.17
 * Capture::Tiny: 0.48
 * File::KDBX::Constants: 0.906
 * File::KDBX::Key: 0.906
 * Sub::Install: 0.929
 * Term::ReadLine::Gnu: 1.45
 * URI: 5.17
 * Authen::OATH: not installed (optional)
 * Clipboard: not installed (optional)
 * Data::Password: not installed (optional)
 * Data::Password::passwdqc: not installed (optional)
 * Data::Password::zxcvbn: not installed (optional)
 * Math::Random::ISAAC: not installed (optional)

--- Additional comment from Charles McGarvey on 2023-09-15 03:37:09 UTC ---

I replicated the crash by simply running Crypt::Argon2's own tests. Still looking for a cause.

[chaz@fedora38 Crypt-Argon2-0.019]$ perl t/test.t 
# Subtest: argon2i(2, 64M, 1, password, somesalt)
Illegal instruction (core dumped)

[chaz@fedora38 Crypt-Argon2-0.019]$ coredumpctl info                          
           PID: 2613 (perl)
           UID: 1000 (chaz)
           GID: 1000 (chaz)
        Signal: 4 (ILL)
     Timestamp: Thu 2023-09-14 21:27:23 MDT (20s ago)
  Command Line: perl t/test.t
    Executable: /usr/bin/perl
 Control Group: /user.slice/user-1000.slice/session-1.scope
          Unit: session-1.scope
         Slice: user-1000.slice
       Session: 1
     Owner UID: 1000 (chaz)
       Boot ID: f1d8f18262b84eb2964891089291de91
    Machine ID: f1925e28d59a4b25badc43cd2f33a6a8
      Hostname: *redacted*
       Storage: /var/lib/systemd/coredump/core.perl.1000.f1d8f18262b84eb2964891089291de91.2613.1694748443000000.zst (p>
  Size on Disk: 1.3M
       Message: Process 2613 (perl) of user 1000 dumped core.
                
                Module libcrypt.so.2 from rpm libxcrypt-4.4.36-1.fc38.x86_64
                Stack trace of thread 2613:
                #0  0x00007f435b7e80ae blake2b_init_param (Argon2.so + 0x50ae)
                #1  0x00007f435b7e817d blake2b_init (Argon2.so + 0x517d)
                #2  0x00007f435b7e879a initial_hash (Argon2.so + 0x579a)
                #3  0x00007f435b7e8e76 initialize (Argon2.so + 0x5e76)
                #4  0x00007f435b7e98c9 argon2_ctx (Argon2.so + 0x68c9)
                #5  0x00007f435b7e9a5e argon2_hash (Argon2.so + 0x6a5e)
                #6  0x00007f435b7e9c4f S_argon2_pass (Argon2.so + 0x6c4f)
                #7  0x00007f435b7ea005 XS_Crypt__Argon2_argon2id_pass (Argon2.so + 0x7005)
                #8  0x00007f435bf265aa Perl_pp_entersub (libperl.so.5.36 + 0x1265aa)
                #9  0x00007f435bf17958 Perl_runops_standard (libperl.so.5.36 + 0x117958)
                #10 0x00007f435be8259d perl_run (libperl.so.5.36 + 0x8259d)
                #11 0x000055c64caa534a main (perl + 0x134a)
                #12 0x00007f435bc49b8a __libc_start_call_main (libc.so.6 + 0x27b8a)
                #13 0x00007f435bc49c4b __libc_start_main@@GLIBC_2.34 (libc.so.6 + 0x27c4b)
                #14 0x000055c64caa5385 _start (perl + 0x1385)
                ELF object binary architecture: AMD x86-64

--- Additional comment from Charles McGarvey on 2023-09-15 03:53:57 UTC ---

Here's a stack trace with debug info enabled:

#0  blake2b_init_param (S=S@entry=0x7fffffffdb20, P=P@entry=0x7fffffffdac0) at src/blake2/blake2b.c:81
#1  0x00007ffff75e817d in blake2b_init (S=S@entry=0x7fffffffdb20, outlen=outlen@entry=64) at src/blake2/blake2b.c:116
#2  0x00007ffff75e879a in initial_hash (type=Argon2_i, context=0x7fffffffdd80, 
    blockhash=0x7fffffffdc60 "\220\334\377\377\377\177") at src/core.c:547
#3  initial_hash (blockhash=blockhash@entry=0x7fffffffdc60 "\220\334\377\377\377\177", 
    context=context@entry=0x7fffffffdd80, type=Argon2_i) at src/core.c:538
#4  0x00007ffff75e8e76 in initialize (context=0x7fffffffdd80, instance=0x7fffffffdd00) at src/core.c:631
#5  initialize (instance=instance@entry=0x7fffffffdd00, context=context@entry=0x7fffffffdd80) at src/core.c:612
#6  0x00007ffff75e98c9 in argon2_ctx (type=(unknown: 0x20), context=0x7fffffffdd80) at src/argon2.c:82
#7  argon2_ctx (context=context@entry=0x7fffffffdd80, type=type@entry=Argon2_i) at src/argon2.c:39
#8  0x00007ffff75e9a5e in argon2_hash (t_cost=t_cost@entry=2, m_cost=m_cost@entry=65536, 
    parallelism=parallelism@entry=1, pwd=pwd@entry=0x555555c03ae0, pwdlen=<optimized out>, 
    salt=salt@entry=0x555555cd8960, saltlen=8, hash=0x0, hashlen=32, encoded=0x555555595290 "\300m\277\367\377\177", 
    encodedlen=86, type=Argon2_i, version=19) at src/argon2.c:151
#9  0x00007ffff75e9c4f in S_argon2_pass (my_perl=my_perl@entry=0x5555555592a0, type=type@entry=Argon2_i, 
    password=password@entry=0x55555558d670, salt=salt@entry=0x55555558d5f8, t_cost=2, m_factor=<optimized out>, 
    parallelism=1, output_length=32) at lib/Crypt/Argon2.xs:60
#10 0x00007ffff75ea005 in XS_Crypt__Argon2_argon2id_pass (my_perl=0x5555555592a0, cv=<optimized out>)
    at lib/Crypt/Argon2.xs:109
#11 0x00007ffff7d265aa in Perl_pp_entersub (my_perl=0x5555555592a0)
    at /usr/src/debug/perl-5.36.1-497.fc38.x86_64/pp_hot.c:5353
#12 0x00007ffff7d17958 in Perl_runops_standard (my_perl=0x5555555592a0)
    at /usr/src/debug/perl-5.36.1-497.fc38.x86_64/run.c:41
#13 0x00007ffff7c8259d in S_run_body (oldscope=<optimized out>, my_perl=<optimized out>)
    at /usr/src/debug/perl-5.36.1-497.fc38.x86_64/perl.c:2721
#14 perl_run (my_perl=0x5555555592a0) at /usr/src/debug/perl-5.36.1-497.fc38.x86_64/perl.c:2644
#15 0x000055555555534a in main (argc=<optimized out>, argv=<optimized out>, env=<optimized out>)
    at /usr/src/debug/perl-5.36.1-497.fc38.x86_64/perlmain.c:110

--- Additional comment from Charles R. Anderson on 2023-09-15 12:07:01 UTC ---

(In reply to Charles McGarvey from comment #13)
> I replicated the crash by simply running Crypt::Argon2's own tests. Still
> looking for a cause.
> 
> [chaz@fedora38 Crypt-Argon2-0.019]$ perl t/test.t 
> # Subtest: argon2i(2, 64M, 1, password, somesalt)
> Illegal instruction (core dumped)

Interesting, I cannot replicate by running Crypt::Argon2's own tests.  Note that I'm doing all builds and tests inside of a mock chroot:

<mock-chroot> sh-5.2# prove --blib --verbose
t/test.t ..
# Subtest: argon2i(2, 64M, 1, password, somesalt)
    ok 1 - 2:64M:1(password, somesalt) encodes as expected
    ok 2 - 2:64M:1(password, somesalt) matches as expected
    ok 3 - 2:64M:1(password, somesalt) verifies as expected
    1..3
ok 1 - argon2i(2, 64M, 1, password, somesalt)
# Subtest: argon2i(2, 256k, 1, password, somesalt)
    ok 1 - 2:256k:1(password, somesalt) encodes as expected
    ok 2 - 2:256k:1(password, somesalt) matches as expected
    ok 3 - 2:256k:1(password, somesalt) verifies as expected
    1..3
ok 2 - argon2i(2, 256k, 1, password, somesalt)
# Subtest: argon2i(2, 256k, 2, password, somesalt)
    ok 1 - 2:256k:2(password, somesalt) encodes as expected
    ok 2 - 2:256k:2(password, somesalt) matches as expected
    ok 3 - 2:256k:2(password, somesalt) verifies as expected
    1..3
ok 3 - argon2i(2, 256k, 2, password, somesalt)
# Subtest: argon2i(1, 64M, 1, password, somesalt)
    ok 1 - 1:64M:1(password, somesalt) encodes as expected
    ok 2 - 1:64M:1(password, somesalt) matches as expected
    ok 3 - 1:64M:1(password, somesalt) verifies as expected
    1..3
ok 4 - argon2i(1, 64M, 1, password, somesalt)
# Subtest: argon2i(4, 64M, 1, password, somesalt)
    ok 1 - 4:64M:1(password, somesalt) encodes as expected
    ok 2 - 4:64M:1(password, somesalt) matches as expected
    ok 3 - 4:64M:1(password, somesalt) verifies as expected
    1..3
ok 5 - argon2i(4, 64M, 1, password, somesalt)
# Subtest: argon2i(2, 64M, 1, differentpassword, somesalt)
    ok 1 - 2:64M:1(differentpassword, somesalt) encodes as expected
    ok 2 - 2:64M:1(differentpassword, somesalt) matches as expected
    ok 3 - 2:64M:1(differentpassword, somesalt) verifies as expected
    1..3
ok 6 - argon2i(2, 64M, 1, differentpassword, somesalt)
# Subtest: argon2i(2, 64M, 1, password, diffsalt)
    ok 1 - 2:64M:1(password, diffsalt) encodes as expected
    ok 2 - 2:64M:1(password, diffsalt) matches as expected
    ok 3 - 2:64M:1(password, diffsalt) verifies as expected
    1..3
ok 7 - argon2i(2, 64M, 1, password, diffsalt)
# Subtest: needs_rehash
    ok 1 - No rehash with same parameters
    ok 2 - Rehash with different argon2 variant
    ok 3 - Rehash with different time cost
    ok 4 - Rehash with different memory cost
    ok 5 - Rehash with different parallelism
    ok 6 - Rehash with different output length
    ok 7 - Rehash with different salt length
    1..7
ok 8 - needs_rehash   
1..8
ok
All tests successful.
Files=1, Tests=8,  1 wallclock secs ( 0.02 usr  0.00 sys +  0.47 cusr  0.21 csys =  0.70 CPU)
Result: PASS

--- Additional comment from Lester Hightower on 2023-09-15 12:14:01 UTC ---

Just to put a little finer point on things (and credit to Charles McGarvey for this perl one-line example), this simple perl one-liner segfaults using the Fedora Server 38 perl-Crypt-Argon2 package:

$ perl -MCrypt::Argon2=argon2i_raw -e'printf("%v02X\n", argon2i_raw("test", "somesalt", 2, "256k", 2, 32))'
Illegal instruction (core dumped)

...and it works perfect when run with my locally-built Crypt::Argon2:

$ PERL5LIB=/home/hightowe/perl5/lib/perl5/ perl -MCrypt::Argon2=argon2i_raw -e'printf("%v02X\n", argon2i_raw("test", "somesalt", 2, "256k", 2, 32))'
1D.F9.12.A7.CD.A4.D8.32.10.22.EA.CB.16.2E.2D.68.D8.8B.59.C0.E3.74.E3.4C.05.86.5E.86.80.29.6C.15

Like Charles, I don't see what is wrong with the perl-Crypt-Argon2 package, but I am convinced that it has a fatal problem, at least on Fedora Server 38.

--- Additional comment from Lester Hightower on 2023-09-15 12:18:15 UTC ---

(In reply to Charles R. Anderson from comment #15)
> (In reply to Charles McGarvey from comment #13)
> > I replicated the crash by simply running Crypt::Argon2's own tests. Still
> > looking for a cause.
> > 
> > [chaz@fedora38 Crypt-Argon2-0.019]$ perl t/test.t 
> > # Subtest: argon2i(2, 64M, 1, password, somesalt)
> > Illegal instruction (core dumped)
> 
> Interesting, I cannot replicate by running Crypt::Argon2's own tests.  Note
> that I'm doing all builds and tests inside of a mock chroot:
> 
> <mock-chroot> sh-5.2# prove --blib --verbose
> t/test.t ..
> # Subtest: argon2i(2, 64M, 1, password, somesalt)
>     ok 1 - 2:64M:1(password, somesalt) encodes as expected
>     ok 2 - 2:64M:1(password, somesalt) matches as expected
>     ok 3 - 2:64M:1(password, somesalt) verifies as expected
>     1..3
> ok 1 - argon2i(2, 64M, 1, password, somesalt)
> # Subtest: argon2i(2, 256k, 1, password, somesalt)
>     ok 1 - 2:256k:1(password, somesalt) encodes as expected
>     ok 2 - 2:256k:1(password, somesalt) matches as expected
>     ok 3 - 2:256k:1(password, somesalt) verifies as expected
>     1..3
> ok 2 - argon2i(2, 256k, 1, password, somesalt)
> # Subtest: argon2i(2, 256k, 2, password, somesalt)
>     ok 1 - 2:256k:2(password, somesalt) encodes as expected
>     ok 2 - 2:256k:2(password, somesalt) matches as expected
>     ok 3 - 2:256k:2(password, somesalt) verifies as expected
>     1..3
> ok 3 - argon2i(2, 256k, 2, password, somesalt)
> # Subtest: argon2i(1, 64M, 1, password, somesalt)
>     ok 1 - 1:64M:1(password, somesalt) encodes as expected
>     ok 2 - 1:64M:1(password, somesalt) matches as expected
>     ok 3 - 1:64M:1(password, somesalt) verifies as expected
>     1..3
> ok 4 - argon2i(1, 64M, 1, password, somesalt)
> # Subtest: argon2i(4, 64M, 1, password, somesalt)
>     ok 1 - 4:64M:1(password, somesalt) encodes as expected
>     ok 2 - 4:64M:1(password, somesalt) matches as expected
>     ok 3 - 4:64M:1(password, somesalt) verifies as expected
>     1..3
> ok 5 - argon2i(4, 64M, 1, password, somesalt)
> # Subtest: argon2i(2, 64M, 1, differentpassword, somesalt)
>     ok 1 - 2:64M:1(differentpassword, somesalt) encodes as expected
>     ok 2 - 2:64M:1(differentpassword, somesalt) matches as expected
>     ok 3 - 2:64M:1(differentpassword, somesalt) verifies as expected
>     1..3
> ok 6 - argon2i(2, 64M, 1, differentpassword, somesalt)
> # Subtest: argon2i(2, 64M, 1, password, diffsalt)
>     ok 1 - 2:64M:1(password, diffsalt) encodes as expected
>     ok 2 - 2:64M:1(password, diffsalt) matches as expected
>     ok 3 - 2:64M:1(password, diffsalt) verifies as expected
>     1..3
> ok 7 - argon2i(2, 64M, 1, password, diffsalt)
> # Subtest: needs_rehash
>     ok 1 - No rehash with same parameters
>     ok 2 - Rehash with different argon2 variant
>     ok 3 - Rehash with different time cost
>     ok 4 - Rehash with different memory cost
>     ok 5 - Rehash with different parallelism
>     ok 6 - Rehash with different output length
>     ok 7 - Rehash with different salt length
>     1..7
> ok 8 - needs_rehash   
> 1..8
> ok
> All tests successful.
> Files=1, Tests=8,  1 wallclock secs ( 0.02 usr  0.00 sys +  0.47 cusr  0.21
> csys =  0.70 CPU)
> Result: PASS

I believe (but am not 100% sure) that prove actually builds and tests the package that you are working with (in the directory that you are sitting in). Said another way, I believe that prove sets PERL5LIB to use the *local* version that it built, whereas I believe that what Charles McGarvey did was to simply run "perl t/test.t" to run a test script by hand and, in doing that, the system-wide Crypt::Argon2 was used and that's where he sees the failure.

--- Additional comment from Charles R. Anderson on 2023-09-15 12:42:28 UTC ---

(In reply to Lester Hightower from comment #17)
> I believe (but am not 100% sure) that prove actually builds and tests the
> package that you are working with (in the directory that you are sitting
> in). Said another way, I believe that prove sets PERL5LIB to use the *local*
> version that it built, whereas I believe that what Charles McGarvey did was
> to simply run "perl t/test.t" to run a test script by hand and, in doing
> that, the system-wide Crypt::Argon2 was used and that's where he sees the
> failure.

Yes, I realize that now.  Something is wrong with the Crypt::Argon2 build that is in the released package.  I reproduced this:

perl-Crypt-Argon2-0.019-2.fc37.x86_64 from Fedora 37 updates --> crash
perl-Crypt-Argon2-0.019-2.fc37.x86_64 from rebuilt locally in Fedora 37 mock chroot --> works
perl-Crypt-Argon2-0.019-2.fc37.x86_64 from rebuilt in Fedora Koji scratch-build --> works

I'll bump and build an official perl-Crypt-Argon2-0.019-3.fc37.x86_64 update now.

--- Additional comment from Fedora Update System on 2023-09-15 13:00:23 UTC ---

FEDORA-2023-74977d8d92 has been submitted as an update to Fedora 40. https://bodhi.fedoraproject.org/updates/FEDORA-2023-74977d8d92

--- Additional comment from Fedora Update System on 2023-09-15 13:01:36 UTC ---

FEDORA-2023-74977d8d92 has been pushed to the Fedora 40 stable repository.
If problem still persists, please make note of it in this bug report.

--- Additional comment from Fedora Update System on 2023-09-15 13:31:49 UTC ---

FEDORA-2023-174b1a814e has been submitted as an update to Fedora 39. https://bodhi.fedoraproject.org/updates/FEDORA-2023-174b1a814e

--- Additional comment from Fedora Update System on 2023-09-15 13:32:16 UTC ---

FEDORA-2023-c694005278 has been submitted as an update to Fedora 38. https://bodhi.fedoraproject.org/updates/FEDORA-2023-c694005278

--- Additional comment from Fedora Update System on 2023-09-15 13:32:38 UTC ---

FEDORA-2023-c1045623bf has been submitted as an update to Fedora 37. https://bodhi.fedoraproject.org/updates/FEDORA-2023-c1045623bf

Comment 1 Charles R. Anderson 2023-09-15 13:58:50 UTC
Please download one or more of these builds and try them.  If they work for you, please add karma so the fixed package can be released and the File::KDBX package can be built:

Fedora 37: 
    https://bodhi.fedoraproject.org/updates/FEDORA-2023-c1045623bf
    https://koji.fedoraproject.org/koji/buildinfo?buildID=2289885

Fedora 38:
    https://bodhi.fedoraproject.org/updates/FEDORA-2023-c694005278
    https://koji.fedoraproject.org/koji/buildinfo?buildID=2289883

Fedora 39: 
    https://bodhi.fedoraproject.org/updates/FEDORA-2023-174b1a814e
    https://koji.fedoraproject.org/koji/buildinfo?buildID=2289884

Thanks.

Comment 2 Lester Hightower 2023-09-16 13:18:19 UTC
I downloaded and installed perl-Crypt-Argon2-0.019-5.fc38 from https://bodhi.fedoraproject.org/updates/FEDORA-2023-c694005278 into "Fedora Linux 38 (Server Edition)" and it supported a clean build of File::KDBX and kpcli-4.0 seemed to properly with it. However, when trying to perform a simple operation on a KDBX4 file with kpcli, it crashes with an "Illegal instruction (core dumped)" problem. And so, I suspect that perl-Crypt-Argon2-0.019-5.fc38 is an improvement, but that it did not fix the root problem on Fedora, whatever that is...

Here is how to replicate the problem that I see (and this works perfectly on other OSes):

[hightowe@localhost ~]$ kpcli-4.0.pl 

KeePass CLI (kpcli-4.0) v4.0 is ready for operation.
Type 'help' for a description of available commands.
Type 'help <command>' for details on individual commands.

kpcli-4.0:/>  newdb
Choose your file format:

 1. KDB   - The original KeePass format (*.kdb).
            Supported using File::KeePass
 2. KDBX3 - The first KeePass XML format (*.kdbx v3).
            Supported using File::KeePass
 3. KDBX4 - The second KeePass XML format (*.kdbx v4).
            Supported using File::KDBX
Choose: (1)/(2)/(3)/(c)ancel? 3
Done. Use the saveas command to write to disk.
kpcli-4.0:/Root> stats
File: N/A           
Type: KDBX v4.1
Key file: N/A
Module: File::KDBX

Cipher:               AES256
Rounds:               10
Iterations:           10
KDF Cipher:           Argon2d
Compression:          gzip
Number of groups:     1
Number of entries:    0
kpcli-4.0:/Root> saveas foo.kdbx
Provide the master password: *************************
Retype to verify: *************************
Illegal instruction (core dumped)
[hightowe@localhost ~]$ 

###################

When it works properly, the "saveas foo.kdbx" command will yield this result:

kpcli-4.0:/Root> saveas foo.kdbx
Provide the master password: *************************
Retype to verify: *************************
You are now operating on a KDBX v4.1 file: foo.kdbx
kpcli-4.0:/Root>

Comment 3 Lester Hightower 2023-09-16 13:26:23 UTC
Notably, this simple test still crashes as well:

[hightowe@localhost ~]$ perl -MCrypt::Argon2=argon2i_raw -e'printf("%v02X\n", argon2i_raw("test", "somesalt", 2, "256k", 2, 32))'
Illegal instruction (core dumped)


More complete info showing the installed version of perl-Crypt-Argon2:

[hightowe@localhost ~]$ dnf info perl-Crypt-Argon2 && perl -MCrypt::Argon2=argon2i_raw -e'printf("%v02X\n", argon2i_raw("test", "somesalt", 2, "256k", 2, 32))'
Last metadata expiration check: 0:02:58 ago on Sat 16 Sep 2023 09:22:47 AM EDT.
Installed Packages
Name         : perl-Crypt-Argon2
Version      : 0.019
Release      : 5.fc38
Architecture : x86_64
Size         : 73 k
Source       : perl-Crypt-Argon2-0.019-5.fc38.src.rpm
Repository   : @System
Summary      : Perl interface to the Argon2 key derivation functions
URL          : https://metacpan.org/release/Crypt-Argon2
License      : Apache-2.0
Description  : This module implements the Argon2 key derivation function, which is
             : suitable to convert any password into a cryptographic key. This is most
             : often used to for secure storage of passwords but can also be used to
             : derive a encryption key from a password. It offers variable time and memory
             : costs as well as output size.

Illegal instruction (core dumped)

Comment 4 Lester Hightower 2023-09-16 13:43:47 UTC
Installing again my own local copy of Crypt::Argon2 with cpanm, which compiles it on my local VM, works perfectly:

[hightowe@localhost ~]$ cpanm -f Crypt::Argon2
[...snip...]
Installing modules to /home/hightowe/perl5
[...snip...]
--> Working on Crypt::Argon2
Fetching http://www.cpan.org/authors/id/L/LE/LEONT/Crypt-Argon2-0.019.tar.gz ... OK
Configuring Crypt-Argon2-0.019 ... OK
Building and testing Crypt-Argon2-0.019 ... OK
Successfully reinstalled Crypt-Argon2-0.019
1 distribution installed
[hightowe@localhost ~]$ PERL5LIB=/home/hightowe/perl5/lib/perl5/ ./bin/kpcli-4.0.pl 

KeePass CLI (kpcli-4.0) v4.0 is ready for operation.
Type 'help' for a description of available commands.
Type 'help <command>' for details on individual commands.

kpcli-4.0:/> newdb
Choose your file format:

 1. KDB   - The original KeePass format (*.kdb).
            Supported using File::KeePass
 2. KDBX3 - The first KeePass XML format (*.kdbx v3).
            Supported using File::KeePass
 3. KDBX4 - The second KeePass XML format (*.kdbx v4).
            Supported using File::KDBX
Choose: (1)/(2)/(3)/(c)ancel? 3
Done. Use the saveas command to write to disk.
kpcli-4.0:/Root> saveas foo.kdbx
Provide the master password: *************************
Retype to verify: *************************
You are now operating on a KDBX v4.1 file: foo.kdbx
kpcli-4.0:/Root> 


This makes me strongly suspect that the problem somehow lies within the Fedora automated build process for Crypt::Argon2.

Comment 5 Charles R. Anderson 2023-09-17 01:46:24 UTC
(In reply to Lester Hightower from comment #3)
> Notably, this simple test still crashes as well:
> 
> [hightowe@localhost ~]$ perl -MCrypt::Argon2=argon2i_raw
> -e'printf("%v02X\n", argon2i_raw("test", "somesalt", 2, "256k", 2, 32))'
> Illegal instruction (core dumped)
>
> Installed Packages
> Name         : perl-Crypt-Argon2
> Version      : 0.019
> Release      : 5.fc38
> Architecture : x86_64
> Size         : 73 k
> Source       : perl-Crypt-Argon2-0.019-5.fc38.src.rpm

I cannot reproduce with the Fedora Koji-built Crypt::Argon2 for Fedora 37:

>rpm -qi perl-Crypt-Argon2
Name        : perl-Crypt-Argon2
Version     : 0.019
Release     : 5.fc37
Architecture: x86_64
Install Date: Fri 15 Sep 2023 09:34:10 AM EDT
Group       : Unspecified
Size        : 76572
License     : Apache-2.0
Signature   : (none)
Source RPM  : perl-Crypt-Argon2-0.019-5.fc37.src.rpm
Build Date  : Fri 15 Sep 2023 09:27:16 AM EDT
Build Host  : buildhw-x86-02.iad2.fedoraproject.org
Packager    : Fedora Project
Vendor      : Fedora Project
URL         : https://metacpan.org/release/Crypt-Argon2
Bug URL     : https://bugz.fedoraproject.org/perl-Crypt-Argon2
Summary     : Perl interface to the Argon2 key derivation functions
Description :
This module implements the Argon2 key derivation function, which is
suitable to convert any password into a cryptographic key. This is most
often used to for secure storage of passwords but can also be used to
derive a encryption key from a password. It offers variable time and memory
costs as well as output size.

>perl -MCrypt::Argon2=argon2i_raw -e'printf("%v02X\n", argon2i_raw("test", "somesalt", 2, "256k", 2, 32))'
1D.F9.12.A7.CD.A4.D8.32.10.22.EA.CB.16.2E.2D.68.D8.8B.59.C0.E3.74.E3.4C.05.86.5E.86.80.29.6C.15

Let me try with Fedora 38 next.

Comment 6 Lester Hightower 2023-09-17 12:28:27 UTC
Overnight, an idea occurred to me for what this issue may be. It occurred to me that the error that we are receiving is "Illegal instruction" and not something like a segmentation fault. And so, my idea is that the Fedora Koji-built Crypt::Argon2 is being done on a system with and utilizing more advanced CPU instructions that the VMs have that we are all testing in. I have no real proof of this, but I am highly suspicious that is the case.

CPU instruction availability decisions are made by gcc at compile time and including CPU instructions in the compiled library that is later not available in the runtime environment would cause this type of "Illegal instruction" problem. This effect would also explain why compiling Crypt::Argon2 by hand in our VMs always works perfectly since gcc compiles that using only the CPU instructions available in the VMs.

I ran these commands on my Linux Mint host and Fedora VM and compared the two, like this: 

$ cat /proc/cpuinfo |grep -E '^flags'|head -1 | cut -d: -f2|xargs -n 1 |sort > cpu_flags_vm.txt
$ cat /proc/cpuinfo |grep -E '^flags'|head -1 | cut -d: -f2|xargs -n 1 |sort > cpu_flags_host.txt
$ diff  cpu_flags_host.txt cpu_flags_vm.txt | grep -E '^< '

The output of that (not included here for brevity) shows 82 CPU flags that are available in my host that are not in my Fedora VM. I have little idea which of those missing flags may be causing this problem, but I suspect that one or more of them are the issue. My first guess would be avx_vnni, but that is just a guess: https://en.wikipedia.org/wiki/Advanced_Vector_Extensions#AVX-VNNI,_AVX-IFMA

If my suspicion is correct, then perhaps setting some GCC flags, for the Fedora Koji build of Crypt::Argon2, such as the ones mentioned in this stack overflow article would be a good idea: https://stackoverflow.com/questions/60815316/disabling-all-avx512-extensions

Comment 7 Lester Hightower 2023-09-17 12:33:07 UTC
Sorry for the rapid reply, but I think that I possibly found more evidence of my suspicion about this problem being correct.

In the Build.PL file that you can see here: https://github.com/Leont/crypt-argon2/blob/master/Build.PL

Note that this gcc flag is set:

	extra_compiler_flags => [ '-march=native' ],

That instructs gcc to use the CPU features that is "sees" in its native host environment at compile time, instead of using some far more safe defaults, and that quite possibly could be the root cause of this issue.

--
Lester

Comment 8 Lester Hightower 2023-09-17 12:52:20 UTC
Leon Timmermans, the author of Crypt::Argon2, was very quick with a reply and a suggestion when I opened a bug report asking for his input: https://github.com/Leont/crypt-argon2/issues/12

Just so it is recorded here in case the link above disappears, his reply and suggestion is this:

> I suspect you may want to apply the same patch as Debian does:
> https://salsa.debian.org/perl-team/modules/packages/libcrypt-argon2-perl/-/commit/ccaa3ba6a852f3de314ad54c2da4618892026ef3
>
> I really wish there was some environmental flag to detect if a dist is built
> for packaging or for local use, I don't have a good solution for that.
> 
> Or an automatic runtime switch between implementations.

The Debian patch simply removes the -march=native flag from being passed to gcc...

--
Lester

Comment 9 Charles R. Anderson 2023-09-17 15:47:23 UTC
(In reply to Lester Hightower from comment #8)
> Leon Timmermans, the author of Crypt::Argon2, was very quick with a reply
> and a suggestion when I opened a bug report asking for his input:
> https://github.com/Leont/crypt-argon2/issues/12
>
> > I suspect you may want to apply the same patch as Debian does:
> > https://salsa.debian.org/perl-team/modules/packages/libcrypt-argon2-perl/-/commit/ccaa3ba6a852f3de314ad54c2da4618892026ef3

> The Debian patch simply removes the -march=native flag from being passed to
> gcc...

Thanks for this!  I was going to ask if your CPU was different than mine.  I'm pushing updates with this patch now.

Comment 10 Fedora Update System 2023-09-17 15:57:20 UTC
FEDORA-2023-e238ae3f1e has been submitted as an update to Fedora 40. https://bodhi.fedoraproject.org/updates/FEDORA-2023-e238ae3f1e

Comment 11 Fedora Update System 2023-09-17 15:59:07 UTC
FEDORA-2023-e238ae3f1e has been pushed to the Fedora 40 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 13 Lester Hightower 2023-09-18 12:25:15 UTC
I downloaded and installed perl-Crypt-Argon2-0.019-6.fc38.x86_64.rpm and can confirm that it seems to have resolved all of the problems that we were seeing, including the failure cases within kpcli-4.0.pl that I reported on Comment #2 of this bug report. I think this one is fixed!


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