From d260ca66808033a854c6c2bb317d91f3cea588b6 Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Thu, 13 Oct 2022 15:43:48 +0200 Subject: [PATCH] Fix api-test with older kernel. --- tests/api-test.c | 25 ++++++++++++++++++----- tests/api_test.h | 20 +++++++++++++++++- tests/test_utils.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 6 deletions(-) diff --git a/tests/api-test.c b/tests/api-test.c index 8f9e65d0..1840e3fb 100644 --- a/tests/api-test.c +++ b/tests/api-test.c @@ -302,6 +302,9 @@ static int _setup(void) _system("modprobe dm-verity >/dev/null 2>&1", 0); _system("modprobe dm-integrity >/dev/null 2>&1", 0); + if (t_dm_check_versions()) + return 1; + _fips_mode = fips_mode(); if (_debug) printf("FIPS MODE: %d\n", _fips_mode); @@ -1856,6 +1859,11 @@ static void ResizeIntegrity(void) int ret; uint64_t r_size, whole_device_size = 0; + if (!t_dm_integrity_resize_support()) { + printf("WARNING: integrity device resize not supported, skipping test.\n"); + return; + } + OK_(crypt_init(&cd, DEVICE_2)); ret = crypt_format(cd,CRYPT_INTEGRITY,NULL,NULL,NULL,NULL,0,¶ms); if (ret < 0) { @@ -1935,6 +1943,11 @@ static void ResizeIntegrityWithKey(void) params.journal_crypt_key_size = journal_crypt_key_size; params.journal_crypt_key = journal_crypt_key; + if (!t_dm_integrity_resize_support()) { + printf("WARNING: integrity device resize not supported, skipping test.\n"); + return; + } + OK_(crypt_init(&cd, DEVICE_2)); ret = crypt_format(cd,CRYPT_INTEGRITY,NULL,NULL,NULL,NULL,0,¶ms); if (ret < 0) { @@ -2032,11 +2045,13 @@ static void IntegrityTest(void) OK_(strcmp(ip.integrity,params.integrity)); OK_(strcmp(CRYPT_INTEGRITY,crypt_get_type(cd))); - OK_(crypt_get_active_device(cd, CDEVICE_1, &cad)); - EQ_(cad.flags & CRYPT_ACTIVATE_RECALCULATE, 0); - OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, NULL, 0, CRYPT_ACTIVATE_REFRESH | CRYPT_ACTIVATE_RECALCULATE)); - OK_(crypt_get_active_device(cd, CDEVICE_1, &cad)); - EQ_(cad.flags & CRYPT_ACTIVATE_RECALCULATE, CRYPT_ACTIVATE_RECALCULATE); + if (t_dm_integrity_recalculate_support()) { + OK_(crypt_get_active_device(cd, CDEVICE_1, &cad)); + EQ_(cad.flags & CRYPT_ACTIVATE_RECALCULATE, 0); + OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, NULL, 0, CRYPT_ACTIVATE_REFRESH | CRYPT_ACTIVATE_RECALCULATE)); + OK_(crypt_get_active_device(cd, CDEVICE_1, &cad)); + EQ_(cad.flags & CRYPT_ACTIVATE_RECALCULATE, CRYPT_ACTIVATE_RECALCULATE); + } OK_(crypt_deactivate(cd, CDEVICE_1)); CRYPT_FREE(cd); diff --git a/tests/api_test.h b/tests/api_test.h index cfcab604..51843eab 100644 --- a/tests/api_test.h +++ b/tests/api_test.h @@ -38,6 +38,8 @@ int t_dm_check_versions(void); int t_dm_crypt_keyring_support(void); int t_dm_crypt_cpu_switch_support(void); int t_dm_crypt_discard_support(void); +int t_dm_integrity_resize_support(void); +int t_dm_integrity_recalculate_support(void); int t_set_readahead(const char *device, unsigned value); int fips_mode(void); @@ -122,7 +124,23 @@ void xlog(const char *msg, const char *tst, const char *func, int line, const ch #define T_DM_VERITY_FEC_SUPPORTED (1 << 10) /* Forward Error Correction (FEC) */ #define T_DM_KERNEL_KEYRING_SUPPORTED (1 << 11) /* dm-crypt allows loading kernel keyring keys */ #define T_DM_INTEGRITY_SUPPORTED (1 << 12) /* dm-integrity target supported */ -//FIXME add T_DM_SECTOR_SIZE once we have version +#define T_DM_SECTOR_SIZE_SUPPORTED (1 << 13) /* support for sector size setting in dm-crypt/dm-integrity */ +#define T_DM_CAPI_STRING_SUPPORTED (1 << 14) /* support for cryptoapi format cipher definition */ +#define T_DM_DEFERRED_SUPPORTED (1 << 15) /* deferred removal of device */ +#define T_DM_INTEGRITY_RECALC_SUPPORTED (1 << 16) /* dm-integrity automatic recalculation supported */ +#define T_DM_INTEGRITY_BITMAP_SUPPORTED (1 << 17) /* dm-integrity bitmap mode supported */ +#define T_DM_GET_TARGET_VERSION_SUPPORTED (1 << 18) /* dm DM_GET_TARGET version ioctl supported */ +#define T_DM_INTEGRITY_FIX_PADDING_SUPPORTED (1 << 19) /* supports the parameter fix_padding that fixes a bug that caused excessive padding */ +#define T_DM_BITLK_EBOIV_SUPPORTED (1 << 20) /* EBOIV for BITLK supported */ +#define T_DM_BITLK_ELEPHANT_SUPPORTED (1 << 21) /* Elephant diffuser for BITLK supported */ +#define T_DM_VERITY_SIGNATURE_SUPPORTED (1 << 22) /* Verity option root_hash_sig_key_desc supported */ +#define T_DM_INTEGRITY_DISCARDS_SUPPORTED (1 << 23) /* dm-integrity discards/TRIM option is supported */ +#define T_DM_INTEGRITY_RESIZE_SUPPORTED (1 << 23) /* dm-integrity resize of the integrity device supported (introduced in the same version as discards)*/ +#define T_DM_VERITY_PANIC_CORRUPTION_SUPPORTED (1 << 24) /* dm-verity panic on corruption */ +#define T_DM_CRYPT_NO_WORKQUEUE_SUPPORTED (1 << 25) /* dm-crypt suppot for bypassing workqueues */ +#define T_DM_INTEGRITY_FIX_HMAC_SUPPORTED (1 << 26) /* hmac covers also superblock */ +#define T_DM_INTEGRITY_RESET_RECALC_SUPPORTED (1 << 27) /* dm-integrity automatic recalculation supported */ +#define T_DM_VERITY_TASKLETS_SUPPORTED (1 << 28) /* dm-verity tasklets supported */ /* loop helpers */ int loop_device(const char *loop); diff --git a/tests/test_utils.c b/tests/test_utils.c index fb5f80be..599fe556 100644 --- a/tests/test_utils.c +++ b/tests/test_utils.c @@ -540,6 +540,20 @@ static void t_dm_set_crypt_compat(const char *dm_version, unsigned crypt_maj, if (t_dm_satisfies_version(1, 18, 1, crypt_maj, crypt_min, crypt_patch) && _keyring_check()) t_dm_crypt_flags |= T_DM_KERNEL_KEYRING_SUPPORTED; + + if (t_dm_satisfies_version(1, 17, 0, crypt_maj, crypt_min, crypt_patch)) { + t_dm_crypt_flags |= T_DM_SECTOR_SIZE_SUPPORTED; + t_dm_crypt_flags |= T_DM_CAPI_STRING_SUPPORTED; + } + + if (t_dm_satisfies_version(1, 19, 0, crypt_maj, crypt_min, crypt_patch)) + t_dm_crypt_flags |= T_DM_BITLK_EBOIV_SUPPORTED; + + if (t_dm_satisfies_version(1, 20, 0, crypt_maj, crypt_min, crypt_patch)) + t_dm_crypt_flags |= T_DM_BITLK_ELEPHANT_SUPPORTED; + + if (t_dm_satisfies_version(1, 22, 0, crypt_maj, crypt_min, crypt_patch)) + t_dm_crypt_flags |= T_DM_CRYPT_NO_WORKQUEUE_SUPPORTED; } static void t_dm_set_verity_compat(const char *dm_version __attribute__((unused)), @@ -561,6 +575,15 @@ static void t_dm_set_verity_compat(const char *dm_version __attribute__((unused) t_dm_crypt_flags |= T_DM_VERITY_ON_CORRUPTION_SUPPORTED; t_dm_crypt_flags |= T_DM_VERITY_FEC_SUPPORTED; } + + if (t_dm_satisfies_version(1, 5, 0, verity_maj, verity_min, verity_patch)) + t_dm_crypt_flags |= T_DM_VERITY_SIGNATURE_SUPPORTED; + + if (t_dm_satisfies_version(1, 7, 0, verity_maj, verity_min, verity_patch)) + t_dm_crypt_flags |= T_DM_VERITY_PANIC_CORRUPTION_SUPPORTED; + + if (t_dm_satisfies_version(1, 9, 0, verity_maj, verity_min, verity_patch)) + t_dm_crypt_flags |= T_DM_VERITY_TASKLETS_SUPPORTED; } static void t_dm_set_integrity_compat(const char *dm_version __attribute__((unused)), @@ -570,6 +593,24 @@ static void t_dm_set_integrity_compat(const char *dm_version __attribute__((unus { if (integrity_maj > 0) t_dm_crypt_flags |= T_DM_INTEGRITY_SUPPORTED; + + if (t_dm_satisfies_version(1, 2, 0, integrity_maj, integrity_min, integrity_patch)) + t_dm_crypt_flags |= T_DM_INTEGRITY_RECALC_SUPPORTED; + + if (t_dm_satisfies_version(1, 3, 0, integrity_maj, integrity_min, integrity_patch)) + t_dm_crypt_flags |= T_DM_INTEGRITY_BITMAP_SUPPORTED; + + if (t_dm_satisfies_version(1, 4, 0, integrity_maj, integrity_min, integrity_patch)) + t_dm_crypt_flags |= T_DM_INTEGRITY_FIX_PADDING_SUPPORTED; + + if (t_dm_satisfies_version(1, 6, 0, integrity_maj, integrity_min, integrity_patch)) + t_dm_crypt_flags |= T_DM_INTEGRITY_DISCARDS_SUPPORTED; + + if (t_dm_satisfies_version(1, 7, 0, integrity_maj, integrity_min, integrity_patch)) + t_dm_crypt_flags |= T_DM_INTEGRITY_FIX_HMAC_SUPPORTED; + + if (t_dm_satisfies_version(1, 8, 0, integrity_maj, integrity_min, integrity_patch)) + t_dm_crypt_flags |= T_DM_INTEGRITY_RESET_RECALC_SUPPORTED; } int t_dm_check_versions(void) @@ -634,6 +675,16 @@ int t_dm_crypt_discard_support(void) return t_dm_crypt_flags & T_DM_DISCARDS_SUPPORTED; } +int t_dm_integrity_resize_support(void) +{ + return t_dm_crypt_flags & T_DM_INTEGRITY_RESIZE_SUPPORTED; +} + +int t_dm_integrity_recalculate_support(void) +{ + return t_dm_crypt_flags & T_DM_INTEGRITY_RECALC_SUPPORTED; +} + /* loop helpers */ #define LOOP_DEV_MAJOR 7