lib: Add function to detect FIPS mode
PATCH 1/2 lib: Add function to detect FIPS mode
--- include/tst_fips.h | 17 +++++++++++++++++ include/tst_test.h | 1 + lib/tst_fips.c | 22 ++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 include/tst_fips.h create mode 100644 lib/tst_fips.c
include/tst_fips.h new file +17 -0
@@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2021 Petr Vorel <[email protected]> +*/ + +#ifndef TST_FIPS_H__ +#define TST_FIPS_H__ + +#define PATH_FIPS "/proc/sys/crypto/fips_enabled" + +/* +* Detect whether FIPS enabled +* @return 0: FIPS not enabled, 1: FIPS enabled +*/ +int tst_fips_enabled (void ); + +#endif /* TST_FIPS_H__ */
include/tst_test.h +1 -0
@@ -42,6 +42,7 @@#include "tst_assert.h" #include "tst_cgroup.h" #include "tst_lockdown.h" +#include "tst_fips.h" #include "tst_taint.h" /*
lib/tst_fips.c new file +22 -0
@@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2021 Petr Vorel <[email protected]> +*/ + +#define TST_NO_DEFAULT_MAIN + +#include "tst_test.h" +#include "tst_safe_macros.h" +#include "tst_fips.h" + +int tst_fips_enabled (void ) +{ +int fips =0 ; + +if (access (PATH_FIPS ,R_OK ) ==0 ) { +SAFE_FILE_SCANF (PATH_FIPS ,"%d" , &fips); + } + +tst_res (TINFO ,"FIPS: %s" , fips ?"on" :"off" ); +return fips; +}
Signature · 1 line
2.30.0
PATCH 2/2 keyctl05: TCONF on FIPS mode
asymmetric key test fails on FIPS with dmesg:
RSA: key size not allowed in FIPS mode
--- testcases/kernel/syscalls/keyctl/keyctl05.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/keyctl/keyctl05.c +8 -2
@@ -85,19 +85,25 @@ static void test_update_nonupdatable(const char *type,new_session_keyring (); +int is_asymmetric = !strcmp (type,"asymmetric" ); +TEST (add_key (type,"desc" , payload, plen,KEY_SPEC_SESSION_KEYRING ));if (TST_RET <0 ) { +if (TST_ERR ==EINVAL && is_asymmetric &&tst_fips_enabled ()) { +tst_res (TCONF ,"key size not allowed in FIPS mode" ); +return ; + }if (TST_ERR ==ENODEV ) {tst_res (TCONF ,"kernel doesn't support key type '%s'" , type);return ; } -if (TST_ERR ==EBADMSG && !strcmp (type,"asymmetric" )) { +if (TST_ERR ==EBADMSG && is_asymmetric) {tst_res (TCONF ,"kernel is missing x509 cert parser " "(CONFIG_X509_CERTIFICATE_PARSER)" );return ; } -if (TST_ERR ==ENOENT && !strcmp (type,"asymmetric" )) { +if (TST_ERR ==ENOENT && is_asymmetric) {tst_res (TCONF ,"kernel is missing crypto algorithms " "needed to parse x509 cert (CONFIG_CRYPTO_RSA " "and/or CONFIG_CRYPTO_SHA256)" );
Signature · 1 line
2.30.0
PATCH 2/2 keyctl05: TCONF on FIPS mode
Hi!
testcases/kernel/syscalls/keyctl/keyctl05.c static void test_update_nonupdatable(const char *type, · line 92
Quoted 5 lines
testcases/kernel/syscalls/keyctl/keyctl05.c +3
-0+int is_asymmetric = !strcmp (type,"asymmetric" ); +TEST (add_key (type,"desc" , payload, plen,KEY_SPEC_SESSION_KEYRING ));if (TST_RET <0 ) { +if (TST_ERR ==EINVAL && is_asymmetric &&tst_fips_enabled ()) {
^ I guess that we can save the value in test setup instead of re-reading it on every iteration.
Other than that it looks good to me.
Quoted 25 lines
testcases/kernel/syscalls/keyctl/keyctl05.c +5
-2+tst_res (TCONF ,"key size not allowed in FIPS mode" ); +return ; + }if (TST_ERR ==ENODEV ) {tst_res (TCONF ,"kernel doesn't support key type '%s'" , type);return ; } -if (TST_ERR ==EBADMSG && !strcmp (type,"asymmetric" )) { +if (TST_ERR ==EBADMSG && is_asymmetric) {tst_res (TCONF ,"kernel is missing x509 cert parser " "(CONFIG_X509_CERTIFICATE_PARSER)" );return ; } -if (TST_ERR ==ENOENT && !strcmp (type,"asymmetric" )) { +if (TST_ERR ==ENOENT && is_asymmetric) {tst_res (TCONF ,"kernel is missing crypto algorithms " "needed to parse x509 cert (CONFIG_CRYPTO_RSA " "and/or CONFIG_CRYPTO_SHA256)" );Signature · 5 lines
2.30.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 2/2 keyctl05: TCONF on FIPS mode
Hi Cyril,
Quoted 16 lines
Hi!
testcases/kernel/syscalls/keyctl/keyctl05.c static void test_update_nonupdatable(const char *type, · line 92
Quoted 5 lines
testcases/kernel/syscalls/keyctl/keyctl05.c +3
-0+int is_asymmetric = !strcmp (type,"asymmetric" ); +TEST (add_key (type,"desc" , payload, plen,KEY_SPEC_SESSION_KEYRING ));if (TST_RET <0 ) { +if (TST_ERR ==EINVAL && is_asymmetric &&tst_fips_enabled ()) {^ I guess that we can save the value in test setup instead of re-reading it on every iteration.
Quoted 1 line
Other than that it looks good to me.
Good point, thanks! Moved to variable set at setup and merged.
Quoted 1 line
Reviewed-by Cyril Hrubis <[email protected]>
Kind regards,
Petr
PATCH 1/2 lib: Add function to detect FIPS mode
In reply to Petr VorelHi!
include/tst_fips.h line 9
Quoted 4 lines
include/tst_fips.h new file +4
-0+#ifndef TST_FIPS_H__ +#define TST_FIPS_H__ + +#define PATH_FIPS "/proc/sys/crypto/fips_enabled"
I'm not sure that this belongs to the header, at least it's not prefixed with TST_.
Other than that Reviewed-by: Cyril Hrubis <[email protected]>
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/2 lib: Add function to detect FIPS mode
Hi,
Quoted 8 lines
Hi!
include/tst_fips.h line 9
Quoted 4 lines
include/tst_fips.h new file +4
-0+#ifndef TST_FIPS_H__ +#define TST_FIPS_H__ + +#define PATH_FIPS "/proc/sys/crypto/fips_enabled"I'm not sure that this belongs to the header, at least it's not prefixed with
TST_.
Good catch. As it's not needed I'll move it to C source, because it's not needed for other tests so far.
BTW the same problem is with PATH_LOCKDOWN from tst_lockdown.[ch]. It'd be better to move them to tst_lockdown.c as well.
Quoted 1 line
Other than that Reviewed-by: Cyril Hrubis <[email protected]>
Thanks!
Kind regards,
Petr