tests/keys: skip KEYCTL_DH_COMPUTE when unavailable
PATCH 1/1 tests/keys: skip KEYCTL_DH_COMPUTE when unavailable
Since 32f07cc40c9b ("crypto: dh - disallow plain "dh" usage in FIPS mode") landed in linux 5.18, plain "dh" is disallowed in FIPS mode per SP800-56Arev3. As noted in the commit:
Quoted 6 lines
This change will effectively render the
keyctl(KEYCTL_DH_COMPUTE)syscall unusable in FIPS mode, but it has been brought up that this might even be a good thing ([1])."
keyctl(KEYCTL_DH_COMPUTE) returns ENOENT in FIPS mode.
So, this patch treat ENOENT and ENOSYS as non-fatal in keyctl.c (because the operation is unavailable, not denied by policy). SELinux denials (EACCES) still exit 9. Skip test_key_no_read_t in FIPS mode since KEYCTL_DH_COMPUTE is the only operation requiring key { read }.
--- tests/keys/keyctl.c | 15 ++++++++++----- tests/keys/request_keys.c | 15 ++++++++++----- tests/keys/test | 21 +++++++++++++++------ 3 files changed, 35 insertions(+), 16 deletions(-)
tests/keys/keyctl.c +10 -5
@@ -142,12 +142,17 @@ int main(int argc, char *argv[])/* Requires key { create read write } */ compute =keyctl (KEYCTL_DH_COMPUTE , ¶ms,NULL ,0 ,0 );if (compute <0 ) { -fprintf (stderr,"Failed KEYCTL_DH_COMPUTE: %s\n" , -strerror (errno)); -exit (9 ); - } -if (verbose) +if (errno ==ENOENT || errno ==ENOSYS ) { +if (verbose) +printf ("KEYCTL_DH_COMPUTE not available, skipping\n" ); + }else { +fprintf (stderr,"Failed KEYCTL_DH_COMPUTE: %s\n" , +strerror (errno)); +exit (9 ); + } + }else if (verbose) {printf ("KEYCTL_DH_COMPUTE key ID size: %d\n" , compute); + }/* Requires key { write link } */ link =keyctl (KEYCTL_LINK , base,KEY_SPEC_PROCESS_KEYRING );
tests/keys/request_keys.c +10 -5
@@ -127,12 +127,17 @@ int main(int argc, char **argv)/* Requires key { read write } */ compute =keyctl (KEYCTL_DH_COMPUTE , ¶ms,NULL ,0 ,0 );if (compute <0 ) { -fprintf (stderr,"Failed KEYCTL_DH_COMPUTE: %s\n" , -strerror (errno)); -exit (8 ); - } -if (verbose) +if (errno ==ENOENT || errno ==ENOSYS ) { +if (verbose) +printf ("\tKEYCTL_DH_COMPUTE not available, skipping\n" ); + }else { +fprintf (stderr,"Failed KEYCTL_DH_COMPUTE: %s\n" , +strerror (errno)); +exit (8 ); + } + }else if (verbose) {printf ("\tKEYCTL_DH_COMPUTE key ID size: %d\n" , compute); + }exit (0 ); }
tests/keys/test +15 -6
@@ -29,6 +29,9 @@ BEGIN { $test_link_53 = 1; } + # KEYCTL_DH_COMPUTE is disabled in FIPS mode + chomp( $fips = `cat /proc/sys/crypto/fips_enabled 2>/dev/null` ); + $skip_dh = ( $fips eq "1" ) ? 1 : 0; plan tests => $test_count; }
@@ -51,8 +54,11 @@ ok( $result >> 8 eq 6 ); $result = system "runcon -t test_key_no_view_t $basedir/keyctl $v 2>&1"; ok( $result >> 8 eq 8 ); -$result = system "runcon -t test_key_no_read_t $basedir/keyctl $v 2>&1"; -ok( $result >> 8 eq 9 ); +SKIP: { + skip( "KEYCTL_DH_COMPUTE unavailable in FIPS mode", 1 ) if $skip_dh; + $result = system "runcon -t test_key_no_read_t $basedir/keyctl $v 2>&1"; + ok( $result >> 8 eq 9 ); +} $result = system "runcon -t test_key_no_link_t $basedir/keyctl $v 2>&1"; if ($test_link_53) {
@@ -101,9 +107,12 @@ $result = system( ); ok( $result >> 8 eq 6 ); -$result = system( -"runcon -t test_keyring_service_t $basedir/keyring_service $v test_request_keys_no_read_t $basedir/request_keys 2>&1" -); -ok( $result >> 8 eq 8 ); +SKIP: { + skip( "KEYCTL_DH_COMPUTE unavailable in FIPS mode", 1 ) if $skip_dh; + $result = system( + "runcon -t test_keyring_service_t $basedir/keyring_service $v test_request_keys_no_read_t $basedir/request_keys 2>&1" + ); + ok( $result >> 8 eq 8 ); +} exit;
Signature · 1 line
2.56.0
Stephen Smalley
maintainerQuoted 33 lines · Pablo Alessandro Santos Hugen
Since
32f07cc40c9b("crypto: dh - disallow plain "dh" usage in FIPS mode") landed in linux 5.18, plain "dh" is disallowed in FIPS mode per SP800-56Arev3. As noted in the commit:Quoted 6 lines
This change will effectively render the
keyctl(KEYCTL_DH_COMPUTE)syscall unusable in FIPS mode, but it has been brought up that this might even be a good thing ([1])."
keyctl(KEYCTL_DH_COMPUTE)returns ENOENT in FIPS mode.So, this patch treat ENOENT and ENOSYS as non-fatal in
keyctl.c(because the operation is unavailable, not denied by policy). SELinux denials (EACCES) still exit 9. Skiptest_key_no_read_tin FIPS mode sinceKEYCTL_DH_COMPUTEis the only operation requiring key { read }.Fixes 2d7aad8a1f8c ("selinux-testsuite: Add keys tests")Signed-off-by Pablo Alessandro Santos Hugen <[email protected]>--- tests/keys/keyctl.c | 15 ++++++++++----- tests/keys/request_keys.c | 15 ++++++++++----- tests/keys/test | 21 +++++++++++++++------ 3 files changed, 35 insertions(+), 16 deletions(-)tests/keys/keyctl.c +0
-0
tests/keys/keyctl.c int main(int argc, char *argv[]) · line 145
Quoted 9 lines
tests/keys/keyctl.c +1
-5@@ -142,12 +142,17 @@ int main(int argc, char *argv[])/* Requires key { create read write } */ compute =keyctl (KEYCTL_DH_COMPUTE , ¶ms,NULL ,0 ,0 );if (compute <0 ) { -fprintf (stderr,"Failed KEYCTL_DH_COMPUTE: %s\n" , -strerror (errno)); -exit (9 ); - } -if (verbose) +if (errno ==ENOENT || errno ==ENOSYS ) {
KEYCTL_DH_COMPUTE never returns ENOSYS; with !CONFIG_KEY_DH_OPERATIONS the stub in security/keys/internal.h returns -EOPNOTSUPP, and the sys_keyctl default case is also -EOPNOTSUPP. If you want to cover kernels built with DH support, this should be EOPNOTSUPP instead (both files).
Quoted 5 lines
tests/keys/request_keys.c +0
-0
tests/keys/request_keys.c int main(int argc, char **argv) · line 130
Quoted 9 lines
tests/keys/request_keys.c +1
-5@@ -127,12 +127,17 @@ int main(int argc, char **argv)/* Requires key { read write } */ compute =keyctl (KEYCTL_DH_COMPUTE , ¶ms,NULL ,0 ,0 );if (compute <0 ) { -fprintf (stderr,"Failed KEYCTL_DH_COMPUTE: %s\n" , -strerror (errno)); -exit (8 ); - } -if (verbose) +if (errno ==ENOENT || errno ==ENOSYS ) {
Same comment as above.
Quoted 5 lines
tests/keys/test +0
-0
tests/keys/test ok( $result >> 8 eq 6 ); · line 61
Quoted 10 lines
tests/keys/test +5
-2@@ -51,8 +54,11 @@ ok( $result >> 8 eq 6 ); $result = system "runcon -t test_key_no_view_t $basedir/keyctl $v 2>&1"; ok( $result >> 8 eq 8 ); -$result = system "runcon -t test_key_no_read_t $basedir/keyctl $v 2>&1"; -ok( $result >> 8 eq 9 ); +SKIP: { + skip( "KEYCTL_DH_COMPUTE unavailable in FIPS mode", 1 ) if $skip_dh; + $result = system "runcon -t test_key_no_read_t $basedir/keyctl $v 2>&1"; + ok( $result >> 8 eq 9 ); +}
This SKIP block and the one below shouldn't be necessary. In __keyctl_dh_compute() the three dh_data_from_key() calls each do lookup_user_key(id, 0, KEY_NEED_READ) and run before crypto_alloc_kpp("dh"). key_task_permission() for KEY_NEED_READ ends with security_key_permission() as the final arbiter, so for test_key_no_read_t the SELinux denial fires there, lookup_user_key() returns -EACCES, and dh_data_from_key() squashes it to -ENOKEY. ENOKEY isn't ENOENT or ENOSYS, so with just the C-side change the no_read_t runs still exit 9 / 8 under FIPS exactly as they do today; the FIPS-mode ENOENT is never reached when read is denied.
tests/keys/test $result = system( · line 116
Quoted 11 lines
tests/keys/test +7
-4-$result = system( -"runcon -t test_keyring_service_t $basedir/keyring_service $v test_request_keys_no_read_t $basedir/request_keys 2>&1" -); -ok( $result >> 8 eq 8 ); +SKIP: { + skip( "KEYCTL_DH_COMPUTE unavailable in FIPS mode", 1 ) if $skip_dh; + $result = system( + "runcon -t test_keyring_service_t $basedir/keyring_service $v test_request_keys_no_read_t $basedir/request_keys 2>&1" + ); + ok( $result >> 8 eq 8 ); +}
See above comment.
Thanks for the review Stephen. Both fixed in v2.
I've validated the v2 patch against the RHEL kernel (which I also did in the v1), and it seems solid:
https://artifacts.osci.redhat.com/testing-farm/753a7e84-6b69-4c83-b39b-e7819005fbb6/
Best,
Pablo
PATCH v2 1/1 tests/keys: skip KEYCTL_DH_COMPUTE when unavailable
In reply to Pablo Alessandro Santos HugenSince 32f07cc40c9b ("crypto: dh - disallow plain "dh" usage in FIPS mode") landed in linux 5.18, plain "dh" is disallowed in FIPS mode per SP800-56Arev3. keyctl(KEYCTL_DH_COMPUTE) returns ENOENT in FIPS mode.
Treat ENOENT and EOPNOTSUPP as non-fatal in keyctl.c and request_keys.c (the operation is unavailable, not denied by policy). SELinux denials (EACCES) still exit 9/8.
---
Changes in v2 (Stephen Smalley):
- Replace ENOSYS with EOPNOTSUPP — KEYCTL_DH_COMPUTE never returns ENOSYS; the !CONFIG_KEY_DH_OPERATIONS stub returns EOPNOTSUPP
- Drop SKIP blocks in Perl test — SELinux denial fires before DH computation (EACCES -> ENOKEY), so no_read_t tests still pass under FIPS
tests/keys/keyctl.c | 15 ++++++++++----- tests/keys/request_keys.c | 15 ++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-)
tests/keys/keyctl.c +10 -5
@@ -142,12 +142,17 @@ int main(int argc, char *argv[])/* Requires key { create read write } */ compute =keyctl (KEYCTL_DH_COMPUTE , ¶ms,NULL ,0 ,0 );if (compute <0 ) { -fprintf (stderr,"Failed KEYCTL_DH_COMPUTE: %s\n" , -strerror (errno)); -exit (9 ); - } -if (verbose) +if (errno ==ENOENT || errno ==EOPNOTSUPP ) { +if (verbose) +printf ("KEYCTL_DH_COMPUTE not available, skipping\n" ); + }else { +fprintf (stderr,"Failed KEYCTL_DH_COMPUTE: %s\n" , +strerror (errno)); +exit (9 ); + } + }else if (verbose) {printf ("KEYCTL_DH_COMPUTE key ID size: %d\n" , compute); + }/* Requires key { write link } */ link =keyctl (KEYCTL_LINK , base,KEY_SPEC_PROCESS_KEYRING );
tests/keys/request_keys.c +10 -5
@@ -127,12 +127,17 @@ int main(int argc, char **argv)/* Requires key { read write } */ compute =keyctl (KEYCTL_DH_COMPUTE , ¶ms,NULL ,0 ,0 );if (compute <0 ) { -fprintf (stderr,"Failed KEYCTL_DH_COMPUTE: %s\n" , -strerror (errno)); -exit (8 ); - } -if (verbose) +if (errno ==ENOENT || errno ==EOPNOTSUPP ) { +if (verbose) +printf ("\tKEYCTL_DH_COMPUTE not available, skipping\n" ); + }else { +fprintf (stderr,"Failed KEYCTL_DH_COMPUTE: %s\n" , +strerror (errno)); +exit (8 ); + } + }else if (verbose) {printf ("\tKEYCTL_DH_COMPUTE key ID size: %d\n" , compute); + }exit (0 ); }
Signature · 1 line
2.56.0
Quoted 6 lines · Pablo Alessandro Santos Hugen
Since
32f07cc40c9b("crypto: dh - disallow plain "dh" usage in FIPS mode") landed in linux 5.18, plain "dh" is disallowed in FIPS mode per SP800-56Arev3.keyctl(KEYCTL_DH_COMPUTE)returns ENOENT in FIPS mode.
Quoted 6 lines
Treat ENOENT and EOPNOTSUPP as non-fatal in
keyctl.candrequest_keys.c(the operation is unavailable, not denied by policy). SELinux denials (EACCES) still exit 9/8.Fixes 2d7aad8a1f8c ("selinux-testsuite: Add keys tests")Signed-off-by Pablo Alessandro Santos Hugen <[email protected]>
Note that this will skip this testing on FIPS-enabled hosts so it won't be exercised if your testing infrastructure always enables FIPS; that's ok with me but noting for the record.