From patchwork Thu Jan 26 13:57:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roberto Sassu X-Patchwork-Id: 13117150 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DE49C54E94 for ; Thu, 26 Jan 2023 13:58:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230112AbjAZN6s (ORCPT ); Thu, 26 Jan 2023 08:58:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231281AbjAZN6p (ORCPT ); Thu, 26 Jan 2023 08:58:45 -0500 Received: from frasgout12.his.huawei.com (frasgout12.his.huawei.com [14.137.139.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD06E3E0B9 for ; Thu, 26 Jan 2023 05:58:41 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.228]) by frasgout12.his.huawei.com (SkyGuard) with ESMTP id 4P2htJ0Fg6z9v7bc for ; Thu, 26 Jan 2023 21:50:32 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwB39P_4htJj+ajLAA--.553S3; Thu, 26 Jan 2023 14:58:27 +0100 (CET) From: Roberto Sassu To: zohar@linux.ibm.com, dmitry.kasatkin@gmail.com Cc: linux-integrity@vger.kernel.org, vt@altlinux.org, pvorel@suse.cz, stefanb@linux.ibm.com, Roberto Sassu Subject: [PATCH ima-evm-utils v4 01/11] Fix error messages and vars in calc_evm_hmac() Date: Thu, 26 Jan 2023 14:57:57 +0100 Message-Id: <20230126135807.1848668-2-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230126135807.1848668-1-roberto.sassu@huaweicloud.com> References: <20230126135807.1848668-1-roberto.sassu@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: LxC2BwB39P_4htJj+ajLAA--.553S3 X-Coremail-Antispam: 1UD129KBjvJXoW7try7trWDCr18WryDJF1UKFg_yoW8urWfpa 9rWw15Wr18tFyjkrW7CF4ku3W5ArWxtr15J3yjga43ZasrJa4DtaySyF4F93y8JFWkAa48 Jr4Y9a4F9a1kAr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvGb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUGw A2048vs2IY020Ec7CjxVAFwI0_JFI_Gr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWUJVWUCwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8JVWxJwA2z4x0Y4vEx4A2jsIE14v26r4j6F4UM28EF7xvwVC2z280aVCY1x0267AKxVW8 Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr 0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY 17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcV C0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY 6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa 73UjIFyTuYvjxUzl1vUUUUU X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAgAJBF1jj4Qi8AAAso X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Roberto Sassu Make sure that the function name in the error message corresponds to the actual function called. Rename mdlen and hash respectively to siglen and sig. Also, initialize siglen to the size of sig (MAX_DIGEST_SIZE), as this is recommended in the documentation of EVP_DigestSignFinal(). Signed-off-by: Roberto Sassu Reviewed-by: Stefan Berger --- src/evmctl.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/evmctl.c b/src/evmctl.c index 0ac7930da6f2..91b531c9e01e 100644 --- a/src/evmctl.c +++ b/src/evmctl.c @@ -1184,9 +1184,9 @@ static int cmd_setxattr_ima(struct command *cmd) #define MAX_KEY_SIZE 128 -static int calc_evm_hmac(const char *file, const char *keyfile, unsigned char *hash) +static int calc_evm_hmac(const char *file, const char *keyfile, unsigned char *sig) { - size_t mdlen; + size_t siglen = MAX_DIGEST_SIZE; EVP_MD_CTX *pctx; EVP_PKEY *pkey = NULL; struct stat st; @@ -1260,7 +1260,7 @@ static int calc_evm_hmac(const char *file, const char *keyfile, unsigned char *h pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, evmkey, sizeof(evmkey)); if (!pkey) { - log_err("HMAC_Init() failed\n"); + log_err("EVP_PKEY_new_mac_key() failed\n"); goto out; } @@ -1326,12 +1326,12 @@ static int calc_evm_hmac(const char *file, const char *keyfile, unsigned char *h err = EVP_DigestSignUpdate(pctx, &hmac_misc, hmac_size); if (err != 1) { - log_err("HMAC_Update() failed\n"); + log_err("EVP_DigestSignUpdate() failed\n"); goto out_ctx_cleanup; } - err = EVP_DigestSignFinal(pctx, hash, &mdlen); + err = EVP_DigestSignFinal(pctx, sig, &siglen); if (err != 1) - log_err("HMAC_Final() failed\n"); + log_err("EVP_DigestSignFinal() failed\n"); out_ctx_cleanup: EVP_PKEY_free(pkey); #if OPENSSL_VERSION_NUMBER >= 0x10100000 @@ -1340,7 +1340,7 @@ out_ctx_cleanup: out: free(key); if (err == 1) - return mdlen; + return siglen; return err; } From patchwork Thu Jan 26 13:57:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roberto Sassu X-Patchwork-Id: 13117151 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73EEEC61D97 for ; Thu, 26 Jan 2023 13:58:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229646AbjAZN6w (ORCPT ); Thu, 26 Jan 2023 08:58:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230317AbjAZN6t (ORCPT ); Thu, 26 Jan 2023 08:58:49 -0500 Received: from frasgout11.his.huawei.com (frasgout11.his.huawei.com [14.137.139.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3332123101 for ; Thu, 26 Jan 2023 05:58:46 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.229]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4P2htT2PD6z9xFQP for ; Thu, 26 Jan 2023 21:50:41 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwB39P_4htJj+ajLAA--.553S4; Thu, 26 Jan 2023 14:58:32 +0100 (CET) From: Roberto Sassu To: zohar@linux.ibm.com, dmitry.kasatkin@gmail.com Cc: linux-integrity@vger.kernel.org, vt@altlinux.org, pvorel@suse.cz, stefanb@linux.ibm.com, Roberto Sassu Subject: [PATCH ima-evm-utils v4 02/11] Add kernel configuration for tests Date: Thu, 26 Jan 2023 14:57:58 +0100 Message-Id: <20230126135807.1848668-3-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230126135807.1848668-1-roberto.sassu@huaweicloud.com> References: <20230126135807.1848668-1-roberto.sassu@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: LxC2BwB39P_4htJj+ajLAA--.553S4 X-Coremail-Antispam: 1UD129KBjvJXoWxtFy5urW8KF15Jw17XF47urg_yoWfXF4Dpr n7JrWxJr4kJr17trW7ArWDGr98tr1DGFWjyr1UXr1UXrykJw4fJr4Ykr1UGr1UXF1UJr48 JF97Gr13Ar1UJ37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvGb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUXw A2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWUJVWUCwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8JVWxJwA2z4x0Y4vEx4A2jsIE14v26r4j6F4UM28EF7xvwVC2z280aVCY1x0267AKxVW8 Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr 0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY 17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcV C0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY 6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa 73UjIFyTuYvjxU2_MaUUUUU X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAgAJBF1jj4Qi8AABsp X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Roberto Sassu Add kernel-configs/base with changes to be applied to the default kernel configuration, generated with 'make defconfig'. Add kernel-configs/integrity, with integrity-specific configuration options. Splitting changes helps to identify more easily the desired group of options. In the future, options could be split even further. All changes in this directory will be applied with the merge_config.sh script from the kernel source code in a Github workflow step. Signed-off-by: Roberto Sassu Reviewed-by: Stefan Berger --- kernel-configs/base | 214 +++++++++++++++++++++++++++++++++++++++ kernel-configs/integrity | 29 ++++++ 2 files changed, 243 insertions(+) create mode 100644 kernel-configs/base create mode 100644 kernel-configs/integrity diff --git a/kernel-configs/base b/kernel-configs/base new file mode 100644 index 000000000000..28ae51026399 --- /dev/null +++ b/kernel-configs/base @@ -0,0 +1,214 @@ +CONFIG_LOCALVERSION="-dont-use" +CONFIG_WATCH_QUEUE=y +CONFIG_AUDIT=y +CONFIG_AUDITSYSCALL=y +CONFIG_HZ_PERIODIC=y +CONFIG_LOG_BUF_SHIFT=17 +CONFIG_USER_NS=y +CONFIG_PID_NS=y +CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y +CONFIG_KALLSYMS_ALL=y +CONFIG_SYSTEM_DATA_VERIFICATION=y +CONFIG_TRACEPOINTS=y +CONFIG_CON_CHAN="xterm" +CONFIG_SSL_CHAN="pty" +CONFIG_MODULE_SIG_FORMAT=y +CONFIG_MODULE_SIG=y +CONFIG_MODULE_SIG_FORCE=y +CONFIG_MODULE_SIG_ALL=y +CONFIG_MODULE_SIG_SHA1=y +CONFIG_MODULE_SIG_HASH="sha1" +CONFIG_MODULES_TREE_LOOKUP=y +CONFIG_BLK_DEBUG_FS=y +CONFIG_ASN1=y +CONFIG_UNINLINE_SPIN_UNLOCK=y +CONFIG_SLUB=y +CONFIG_COMPACTION=y +CONFIG_COMPACT_UNEVICTABLE_DEFAULT=1 +CONFIG_MIGRATION=y +CONFIG_BLK_DEV_LOOP=y +CONFIG_LEGACY_PTY_COUNT=256 +CONFIG_NULL_TTY=y +CONFIG_SERIAL_DEV_BUS=y +CONFIG_SERIAL_DEV_CTRL_TTYPORT=y +CONFIG_VALIDATE_FS_PARSER=y +CONFIG_EXT4_FS_POSIX_ACL=y +CONFIG_EXT4_FS_SECURITY=y +CONFIG_EXT4_DEBUG=y +CONFIG_REISERFS_FS_XATTR=y +CONFIG_REISERFS_FS_POSIX_ACL=y +CONFIG_REISERFS_FS_SECURITY=y +CONFIG_FS_POSIX_ACL=y +CONFIG_FS_VERITY=y +CONFIG_FS_VERITY_BUILTIN_SIGNATURES=y +CONFIG_TMPFS_POSIX_ACL=y +CONFIG_TMPFS_XATTR=y +CONFIG_CONFIGFS_FS=y +CONFIG_KEYS=y +CONFIG_ENCRYPTED_KEYS=y +CONFIG_SECURITY=y +CONFIG_SECURITYFS=y +CONFIG_SECURITY_NETWORK=y +CONFIG_SECURITY_PATH=y +CONFIG_LSM="lockdown,yama,loadpin,safesetid,integrity,bpf" +CONFIG_CRYPTO_AEAD2=y +CONFIG_CRYPTO_SKCIPHER=y +CONFIG_CRYPTO_SKCIPHER2=y +CONFIG_CRYPTO_RNG=y +CONFIG_CRYPTO_RNG2=y +CONFIG_CRYPTO_RNG_DEFAULT=y +CONFIG_CRYPTO_AKCIPHER2=y +CONFIG_CRYPTO_AKCIPHER=y +CONFIG_CRYPTO_KPP2=y +CONFIG_CRYPTO_ACOMP2=y +CONFIG_CRYPTO_MANAGER=y +CONFIG_CRYPTO_MANAGER2=y +CONFIG_CRYPTO_NULL2=y +CONFIG_CRYPTO_RSA=y +CONFIG_CRYPTO_ECC=y +CONFIG_CRYPTO_ECDSA=y +CONFIG_CRYPTO_AES=y +CONFIG_CRYPTO_CBC=y +CONFIG_CRYPTO_HMAC=y +CONFIG_CRYPTO_MD5=y +CONFIG_CRYPTO_SHA1=y +CONFIG_CRYPTO_SHA256=y +CONFIG_CRYPTO_SHA512=y +CONFIG_CRYPTO_WP512=y +CONFIG_CRYPTO_LZO=y +CONFIG_CRYPTO_ZSTD=y +CONFIG_CRYPTO_DRBG_MENU=y +CONFIG_CRYPTO_DRBG_HMAC=y +CONFIG_CRYPTO_DRBG=y +CONFIG_CRYPTO_JITTERENTROPY=y +CONFIG_CRYPTO_HASH_INFO=y +CONFIG_ASYMMETRIC_KEY_TYPE=y +CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=y +CONFIG_X509_CERTIFICATE_PARSER=y +CONFIG_PKCS8_PRIVATE_KEY_PARSER=y +CONFIG_PKCS7_MESSAGE_PARSER=y +CONFIG_PKCS7_TEST_KEY=y +CONFIG_SIGNED_PE_FILE_VERIFICATION=y +CONFIG_MODULE_SIG_KEY="certs/signing_key.pem" +CONFIG_MODULE_SIG_KEY_TYPE_RSA=y +CONFIG_SYSTEM_TRUSTED_KEYRING=y +CONFIG_SYSTEM_TRUSTED_KEYS="" +CONFIG_SYSTEM_EXTRA_CERTIFICATE=y +CONFIG_SYSTEM_EXTRA_CERTIFICATE_SIZE=4096 +CONFIG_SECONDARY_TRUSTED_KEYRING=y +CONFIG_SYSTEM_BLACKLIST_KEYRING=y +CONFIG_SYSTEM_BLACKLIST_HASH_LIST="" +CONFIG_SYSTEM_REVOCATION_LIST=y +CONFIG_SYSTEM_REVOCATION_KEYS="" +CONFIG_SYSTEM_BLACKLIST_AUTH_UPDATE=y +CONFIG_BINARY_PRINTF=y +CONFIG_CRYPTO_LIB_AES=y +CONFIG_CRYPTO_LIB_SHA256=y +CONFIG_CRC_CCITT=y +CONFIG_XXHASH=y +CONFIG_AUDIT_GENERIC=y +CONFIG_LZO_COMPRESS=y +CONFIG_LZO_DECOMPRESS=y +CONFIG_ZSTD_COMMON=y +CONFIG_ZSTD_COMPRESS=y +CONFIG_ZSTD_DECOMPRESS=y +CONFIG_ASSOCIATIVE_ARRAY=y +CONFIG_SGL_ALLOC=y +CONFIG_GLOB=y +CONFIG_CLZ_TAB=y +CONFIG_MPILIB=y +CONFIG_SIGNATURE=y +CONFIG_OID_REGISTRY=y +CONFIG_STACKDEPOT=y +CONFIG_STACKDEPOT_ALWAYS_INIT=y +CONFIG_PRINTK_TIME=y +CONFIG_PRINTK_CALLER=y +CONFIG_DYNAMIC_DEBUG=y +CONFIG_DYNAMIC_DEBUG_CORE=y +CONFIG_DEBUG_INFO_DWARF5=y +CONFIG_GDB_SCRIPTS=y +CONFIG_FRAME_WARN=2048 +CONFIG_READABLE_ASM=y +CONFIG_DEBUG_SECTION_MISMATCH=y +CONFIG_DEBUG_FS=y +CONFIG_DEBUG_FS_ALLOW_ALL=y +CONFIG_UBSAN=y +CONFIG_CC_HAS_UBSAN_BOUNDS=y +CONFIG_UBSAN_BOUNDS=y +CONFIG_UBSAN_ONLY_BOUNDS=y +CONFIG_UBSAN_SHIFT=y +CONFIG_UBSAN_DIV_ZERO=y +CONFIG_UBSAN_BOOL=y +CONFIG_UBSAN_ENUM=y +CONFIG_UBSAN_ALIGNMENT=y +CONFIG_PAGE_EXTENSION=y +CONFIG_DEBUG_PAGEALLOC=y +CONFIG_DEBUG_PAGEALLOC_ENABLE_DEFAULT=y +CONFIG_SLUB_DEBUG=y +CONFIG_SLUB_DEBUG_ON=y +CONFIG_PAGE_OWNER=y +CONFIG_PAGE_POISONING=y +CONFIG_DEBUG_OBJECTS=y +CONFIG_DEBUG_OBJECTS_FREE=y +CONFIG_DEBUG_OBJECTS_TIMERS=y +CONFIG_DEBUG_OBJECTS_WORK=y +CONFIG_DEBUG_OBJECTS_RCU_HEAD=y +CONFIG_DEBUG_OBJECTS_PERCPU_COUNTER=y +CONFIG_DEBUG_OBJECTS_ENABLE_DEFAULT=1 +CONFIG_DEBUG_KMEMLEAK=y +CONFIG_DEBUG_KMEMLEAK_MEM_POOL_SIZE=16000 +CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN=y +CONFIG_DEBUG_STACK_USAGE=y +CONFIG_SCHED_STACK_END_CHECK=y +CONFIG_DEBUG_SHIRQ=y +CONFIG_PANIC_ON_OOPS=y +CONFIG_PANIC_ON_OOPS_VALUE=1 +CONFIG_LOCKUP_DETECTOR=y +CONFIG_SOFTLOCKUP_DETECTOR=y +CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC=y +CONFIG_DETECT_HUNG_TASK=y +CONFIG_DEFAULT_HUNG_TASK_TIMEOUT=120 +CONFIG_BOOTPARAM_HUNG_TASK_PANIC=y +CONFIG_WQ_WATCHDOG=y +CONFIG_DEBUG_TIMEKEEPING=y +CONFIG_PROVE_LOCKING=y +CONFIG_PROVE_RAW_LOCK_NESTING=y +CONFIG_LOCK_STAT=y +CONFIG_DEBUG_RT_MUTEXES=y +CONFIG_DEBUG_SPINLOCK=y +CONFIG_DEBUG_MUTEXES=y +CONFIG_DEBUG_WW_MUTEX_SLOWPATH=y +CONFIG_DEBUG_RWSEMS=y +CONFIG_DEBUG_LOCK_ALLOC=y +CONFIG_LOCKDEP=y +CONFIG_LOCKDEP_BITS=15 +CONFIG_LOCKDEP_CHAINS_BITS=16 +CONFIG_LOCKDEP_STACK_TRACE_BITS=19 +CONFIG_LOCKDEP_STACK_TRACE_HASH_BITS=14 +CONFIG_LOCKDEP_CIRCULAR_QUEUE_BITS=12 +CONFIG_WW_MUTEX_SELFTEST=y +CONFIG_CSD_LOCK_WAIT_DEBUG=y +CONFIG_TRACE_IRQFLAGS=y +CONFIG_DEBUG_IRQFLAGS=y +CONFIG_DEBUG_LIST=y +CONFIG_DEBUG_PLIST=y +CONFIG_DEBUG_SG=y +CONFIG_DEBUG_NOTIFIERS=y +CONFIG_BUG_ON_DATA_CORRUPTION=y +CONFIG_PROVE_RCU=y +CONFIG_RCU_TRACE=y +CONFIG_NOP_TRACER=y +CONFIG_TRACE_CLOCK=y +CONFIG_RING_BUFFER=y +CONFIG_EVENT_TRACING=y +CONFIG_CONTEXT_SWITCH_TRACER=y +CONFIG_PREEMPTIRQ_TRACEPOINTS=y +CONFIG_TRACING=y +CONFIG_DRM=n +CONFIG_USB=n +CONFIG_SOUND=n +CONFIG_9P_FS=y +CONFIG_9P_FS_POSIX_ACL=y +CONFIG_9P_FS_SECURITY=y +CONFIG_ETHERNET=n +CONFIG_WLAN=n diff --git a/kernel-configs/integrity b/kernel-configs/integrity new file mode 100644 index 000000000000..a7e01e19466d --- /dev/null +++ b/kernel-configs/integrity @@ -0,0 +1,29 @@ +CONFIG_INTEGRITY=y +CONFIG_INTEGRITY_SIGNATURE=y +CONFIG_INTEGRITY_ASYMMETRIC_KEYS=y +CONFIG_INTEGRITY_TRUSTED_KEYRING=y +CONFIG_INTEGRITY_AUDIT=y +CONFIG_IMA=y +CONFIG_IMA_MEASURE_PCR_IDX=10 +CONFIG_IMA_NG_TEMPLATE=y +CONFIG_IMA_DEFAULT_TEMPLATE="ima-ng" +CONFIG_IMA_DEFAULT_HASH_SHA256=y +CONFIG_IMA_DEFAULT_HASH="sha256" +CONFIG_IMA_WRITE_POLICY=y +CONFIG_IMA_READ_POLICY=y +CONFIG_IMA_APPRAISE=y +CONFIG_IMA_ARCH_POLICY=y +CONFIG_IMA_APPRAISE_BUILD_POLICY=y +CONFIG_IMA_APPRAISE_BOOTPARAM=y +CONFIG_IMA_APPRAISE_MODSIG=y +CONFIG_IMA_TRUSTED_KEYRING=y +CONFIG_IMA_BLACKLIST_KEYRING=y +CONFIG_IMA_LOAD_X509=y +CONFIG_IMA_X509_PATH="/etc/keys/x509_ima.der" +CONFIG_IMA_MEASURE_ASYMMETRIC_KEYS=y +CONFIG_IMA_QUEUE_EARLY_BOOT_KEYS=y +CONFIG_EVM=y +CONFIG_EVM_ATTR_FSUUID=y +CONFIG_EVM_ADD_XATTRS=y +CONFIG_EVM_LOAD_X509=y +CONFIG_EVM_X509_PATH="/etc/keys/x509_evm.der" From patchwork Thu Jan 26 13:57:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roberto Sassu X-Patchwork-Id: 13117152 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5265C61D97 for ; Thu, 26 Jan 2023 13:59:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230516AbjAZN7E (ORCPT ); Thu, 26 Jan 2023 08:59:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231142AbjAZN7B (ORCPT ); Thu, 26 Jan 2023 08:59:01 -0500 Received: from frasgout12.his.huawei.com (frasgout12.his.huawei.com [14.137.139.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC1234483 for ; Thu, 26 Jan 2023 05:58:55 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.228]) by frasgout12.his.huawei.com (SkyGuard) with ESMTP id 4P2htZ1VsWz9v7bc for ; Thu, 26 Jan 2023 21:50:46 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwB39P_4htJj+ajLAA--.553S5; Thu, 26 Jan 2023 14:58:39 +0100 (CET) From: Roberto Sassu To: zohar@linux.ibm.com, dmitry.kasatkin@gmail.com Cc: linux-integrity@vger.kernel.org, vt@altlinux.org, pvorel@suse.cz, stefanb@linux.ibm.com, Roberto Sassu Subject: [PATCH ima-evm-utils v4 03/11] Compile the UML kernel and download it in Github Actions Date: Thu, 26 Jan 2023 14:57:59 +0100 Message-Id: <20230126135807.1848668-4-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230126135807.1848668-1-roberto.sassu@huaweicloud.com> References: <20230126135807.1848668-1-roberto.sassu@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: LxC2BwB39P_4htJj+ajLAA--.553S5 X-Coremail-Antispam: 1UD129KBjvJXoW3AF1fCrW5Xw13JF17Kr17KFg_yoWxJF4rpr Z0v345Kr4kJ3W7Aw4kAF18CayYga9ayry3u3s7G34rAF9xJa4vvFs2yry5ZF9FvrW7tFWS 9FW8WFyDKa18uaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvGb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWUJVWUCwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8JVWxJwA2z4x0Y4vEx4A2jsIE14v26r4j6F4UM28EF7xvwVC2z280aVCY1x0267AKxVW8 Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr 0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY 17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcV C0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY 6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa 73UjIFyTuYvjxUFYFCUUUUU X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAQAJBF1jj4ggcwAAsm X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Roberto Sassu Add a build job, prerequisite of the existing job, to compile the UML kernel and upload it and the signing key to a cache. Github configuration should have two variables: LINUX_URL, the full URL of the kernel repository; LINUX_BRANCH, the branch to check out as fallback if the kernel repository does not have the same branch name as the one being pushed for ima-evm-utils. See: https://docs.github.com/en/actions/learn-github-actions/variables for directions on how to define those variables. If the two variables are not defined, the default values are: LINUX_URL=https://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git LINUX_BRANCH=next-integrity If there is a cache hit (same kernel commit and same kernel configuration), next time the UML kernel will not be rebuilt. To use the cache, it is necessary to install zstd in the container. Add this dependency to ci/fedora.sh. The cache can be managed at the following URL: https://github.com//ima-evm-utils/actions/caches The page also offers the possibility to clean the cache, to force rebuilding the kernel. Add a new entry in the testing matrix, for the fedora-latest container image, to run the tests with the UML kernel. The entry differs from the others for the new environment variable TST_ENV, set to 'um', and TST_KERNEL set to '../linux', as the tests will be executed from the tests/ directory in ima-evm-utils. Add a new volume to the container, /dev/shm from the host, as it is required for running the UML kernel. Extend the existing job with steps to download the UML kernel and signing key from the cache. The new steps are executed only if the matrix entry has TST_ENV set. Finally, pass TST_ENV and TST_KERNEL to the tests. A test should also propagate these variables to the new environment, by passing them to the kernel command line. Signed-off-by: Roberto Sassu --- .github/workflows/ci.yml | 99 +++++++++++++++++++++++++++++++++++++++- ci/fedora.sh | 3 +- 2 files changed, 99 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d2afdfe15467..8b1eda813511 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,79 @@ name: "distros" on: [push, pull_request] jobs: + build: + runs-on: ubuntu-latest + outputs: + LINUX_SHA: ${{ steps.last-commit.outputs.LINUX_SHA }} + name: build + timeout-minutes: 100 + strategy: + fail-fast: false + + steps: + - uses: actions/checkout@v3 + + - name: Determine last kernel commit + id: last-commit + shell: bash + run: | + mkdir linux-integrity + pushd linux-integrity + git init + LINUX_URL=${{ vars.LINUX_URL }} + if [ -z "$LINUX_URL" ]; then + LINUX_URL=https://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git + fi + LINUX_BRANCH=${{ vars.LINUX_BRANCH }} + if [ -z "$LINUX_BRANCH" ]; then + LINUX_BRANCH=next-integrity + fi + git remote add origin $LINUX_URL + LINUX_SHA=$(git ls-remote origin $GITHUB_REF_NAME | awk '{print $1}') + [ -z "$LINUX_SHA" ] && LINUX_SHA=$(git ls-remote origin $LINUX_BRANCH | awk '{print $1}') + echo "LINUX_SHA=$LINUX_SHA" >> $GITHUB_OUTPUT + popd + + - name: Cache UML kernel + id: cache-linux + uses: actions/cache@v3 + with: + path: linux + key: linux-${{ steps.last-commit.outputs.LINUX_SHA }}-${{ hashFiles('**/kernel-configs/*') }} + + - name: Cache signing key + id: cache-key + uses: actions/cache@v3 + with: + path: signing_key.pem + key: signing_key.pem-${{ steps.last-commit.outputs.LINUX_SHA }}-${{ hashFiles('**/kernel-configs/*') }} + + - name: Compile UML kernel + if: steps.cache-linux.outputs.cache-hit != 'true' || steps.cache-key.outputs.cache-hit != 'true' + shell: bash + run: | + if [ "$DEVTOOLSET" = "yes" ]; then + source /opt/rh/devtoolset-10/enable + fi + if [ "$ARCH" = "i386" ]; then + CROSS_COMPILE_OPT="CROSS_COMPILE=i686-linux-gnu-" + fi + pushd linux-integrity + git pull --depth 1 origin ${{ steps.last-commit.outputs.LINUX_SHA }} + make ARCH=um defconfig + ./scripts/kconfig/merge_config.sh -m .config $(ls ../kernel-configs/*) + # Update manually, to specify ARCH=um + make ARCH=um olddefconfig + # Make everything built-in + make ARCH=um localyesconfig + make ARCH=um $CROSS_COMPILE_OPT -j$(nproc) + chmod +x linux + cp linux .. + cp certs/signing_key.pem .. + popd + job: + needs: build runs-on: ubuntu-latest strategy: @@ -75,6 +147,13 @@ jobs: CC: clang TSS: ibmtss + - container: "fedora:latest" + env: + CC: clang + TSS: ibmtss + TST_ENV: um + TST_KERNEL: ../linux + - container: "centos:7" env: CC: gcc @@ -98,7 +177,7 @@ jobs: container: image: ${{ matrix.container }} env: ${{ matrix.env }} - options: --privileged --device /dev/loop-control + options: --privileged --device /dev/loop-control -v /dev/shm:/dev/shm steps: - name: Show OS @@ -125,8 +204,24 @@ jobs: fi fi + - name: Retrieve UML kernel + if: ${{ matrix.env.TST_ENV }} + uses: actions/cache@v3 + continue-on-error: false + with: + path: linux + key: linux-${{ needs.build.outputs.LINUX_SHA }}-${{ hashFiles('**/kernel-configs/*') }} + + - name: Retrieve signing key + if: ${{ matrix.env.TST_ENV }} + continue-on-error: false + uses: actions/cache@v3 + with: + path: signing_key.pem + key: signing_key.pem-${{ needs.build.outputs.LINUX_SHA }}-${{ hashFiles('**/kernel-configs/*') }} + - name: Compiler version run: $CC --version - name: Compile - run: CC="$CC" VARIANT="$VARIANT" COMPILE_SSL="$COMPILE_SSL" ./build.sh + run: CC="$CC" VARIANT="$VARIANT" COMPILE_SSL="$COMPILE_SSL" TST_ENV="$TST_ENV" TST_KERNEL="$TST_KERNEL" ./build.sh diff --git a/ci/fedora.sh b/ci/fedora.sh index 2272bbc57fae..e60de7981c60 100755 --- a/ci/fedora.sh +++ b/ci/fedora.sh @@ -44,7 +44,8 @@ yum -y install \ util-linux \ vim-common \ wget \ - which + which \ + zstd yum -y install docbook5-style-xsl || true yum -y install swtpm || true From patchwork Thu Jan 26 13:58:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roberto Sassu X-Patchwork-Id: 13117153 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9D05C05027 for ; Thu, 26 Jan 2023 13:59:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230366AbjAZN7N (ORCPT ); Thu, 26 Jan 2023 08:59:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231550AbjAZN7E (ORCPT ); Thu, 26 Jan 2023 08:59:04 -0500 Received: from frasgout11.his.huawei.com (frasgout11.his.huawei.com [14.137.139.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 868BF59994 for ; Thu, 26 Jan 2023 05:58:58 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.227]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4P2htl3Cswz9xFQN for ; Thu, 26 Jan 2023 21:50:55 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwB39P_4htJj+ajLAA--.553S6; Thu, 26 Jan 2023 14:58:46 +0100 (CET) From: Roberto Sassu To: zohar@linux.ibm.com, dmitry.kasatkin@gmail.com Cc: linux-integrity@vger.kernel.org, vt@altlinux.org, pvorel@suse.cz, stefanb@linux.ibm.com, Roberto Sassu Subject: [PATCH ima-evm-utils v4 04/11] Pass cleanup function and its arguments to _report_exit_and_cleanup() Date: Thu, 26 Jan 2023 14:58:00 +0100 Message-Id: <20230126135807.1848668-5-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230126135807.1848668-1-roberto.sassu@huaweicloud.com> References: <20230126135807.1848668-1-roberto.sassu@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: LxC2BwB39P_4htJj+ajLAA--.553S6 X-Coremail-Antispam: 1UD129KBjvJXoWxuF45WFy8Ar45XFyfJw45Awb_yoW5Cr4kpa 1DWa4IkrZ5ta40qrW8Cwn2va4xt3y5Zw43Zr48CFWDuw4rXr1kKF4xKw12qFWUWrZavFWf Cay0qrn5Kr1DCrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvEb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWUJVWUCwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIE14v26r4j6F4UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7 v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF 1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIx AIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI 42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWI evJa73UjIFyTuYvjxUFgAwUUUUU X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAQAJBF1jj4ggcwABsn X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Roberto Sassu If an error occurs before any test is executed, _report_exit_and_cleanup() returns 77 ($SKIP) as exit code, which might not reflect the real exit code at the time the script terminated its execution. If the function registered in the shell trap() is a cleanup function calling _report_exit_and_cleanup() inside, the latter will not have access to the exit code at the time of the trap but instead to the exit code of the cleanup function. To solve this issue, pass the cleanup function and its arguments to _report_exit_and_cleanup(), so that the latter can first get the script exit code and then can execute the cleanup function. Finally, if no test was executed, return the exit code at the time of the trap() instead of 77. Signed-off-by: Roberto Sassu Reviewed-by: Stefan Berger --- tests/boot_aggregate.test | 2 +- tests/fsverity.test | 3 +-- tests/functions.sh | 10 ++++++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/boot_aggregate.test b/tests/boot_aggregate.test index d7115660385f..ca5faf9cd97d 100755 --- a/tests/boot_aggregate.test +++ b/tests/boot_aggregate.test @@ -12,7 +12,7 @@ # for verifying the calculated boot_aggregate is included in this # directory as well. -trap cleanup SIGINT SIGTERM EXIT +trap '_report_exit_and_cleanup cleanup' SIGINT SIGTERM EXIT # Base VERBOSE on the environment variable, if set. VERBOSE="${VERBOSE:-0}" diff --git a/tests/fsverity.test b/tests/fsverity.test index 549c42a32608..be9594010de5 100755 --- a/tests/fsverity.test +++ b/tests/fsverity.test @@ -47,7 +47,7 @@ FSVERITY="$(which fsverity)" _require dd mkfs blkid e2fsck tune2fs evmctl setfattr ./gen-keys.sh >/dev/null 2>&1 -trap cleanup SIGINT SIGTERM EXIT +trap '_report_exit_and_cleanup cleanup' SIGINT SIGTERM EXIT cleanup() { if [ -e $TST_MNT ]; then @@ -58,7 +58,6 @@ cleanup() { rm "$TST_IMG" fi fi - _report_exit_and_cleanup } # Loopback mount a file diff --git a/tests/functions.sh b/tests/functions.sh index 8f6f02dfcd95..d0a9e8e62ca5 100755 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -250,10 +250,14 @@ _enable_gost_engine() { # Show test stats and exit into automake test system # with proper exit code (same as ours). Do cleanups. _report_exit_and_cleanup() { + local exit_code=$? + if [ -n "${WORKDIR}" ]; then rm -rf "${WORKDIR}" fi + "$@" + if [ $testsfail -gt 0 ]; then echo "=================================" echo " Run with FAILEARLY=1 $0 $*" @@ -271,8 +275,10 @@ _report_exit_and_cleanup() { exit "$FAIL" elif [ $testspass -gt 0 ]; then exit "$OK" - else + elif [ $testsskip -gt 0 ]; then exit "$SKIP" + else + exit "$exit_code" fi } @@ -312,4 +318,4 @@ _softhsm_teardown() { rm -rf "${SOFTHSM_SETUP_CONFIGDIR}" unset SOFTHSM_SETUP_CONFIGDIR SOFTHSM2_CONF PKCS11_KEYURI \ EVMCTL_ENGINE OPENSSL_ENGINE OPENSSL_KEYFORM -} \ No newline at end of file +} From patchwork Thu Jan 26 13:58:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roberto Sassu X-Patchwork-Id: 13117155 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DCECC61D97 for ; Thu, 26 Jan 2023 13:59:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231597AbjAZN70 (ORCPT ); Thu, 26 Jan 2023 08:59:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231602AbjAZN7Q (ORCPT ); Thu, 26 Jan 2023 08:59:16 -0500 Received: from frasgout13.his.huawei.com (frasgout13.his.huawei.com [14.137.139.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C3C76D369 for ; Thu, 26 Jan 2023 05:59:07 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.229]) by frasgout13.his.huawei.com (SkyGuard) with ESMTP id 4P2hts736Jz9xFgL for ; Thu, 26 Jan 2023 21:51:01 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwB39P_4htJj+ajLAA--.553S7; Thu, 26 Jan 2023 14:58:50 +0100 (CET) From: Roberto Sassu To: zohar@linux.ibm.com, dmitry.kasatkin@gmail.com Cc: linux-integrity@vger.kernel.org, vt@altlinux.org, pvorel@suse.cz, stefanb@linux.ibm.com, Roberto Sassu Subject: [PATCH ima-evm-utils v4 05/11] Add support for creating a new testing environment in functions.sh Date: Thu, 26 Jan 2023 14:58:01 +0100 Message-Id: <20230126135807.1848668-6-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230126135807.1848668-1-roberto.sassu@huaweicloud.com> References: <20230126135807.1848668-1-roberto.sassu@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: LxC2BwB39P_4htJj+ajLAA--.553S7 X-Coremail-Antispam: 1UD129KBjvJXoWxCF4kWr1DWF4xWrW5ArWrKrg_yoWrAr48pw 1kWFyYyFZ2qFy7J39xWa1SqFyfJ3y8Zr1UZrZrJws0yw45GrWktF4SyFyaqw1Y9rZY9rWF y3yIqrs3urnrCr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvEb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWUCVW8JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIE14v26r4j6F4UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7 v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF 1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIx AIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI 42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWI evJa73UjIFyTuYvjxUFgAwUUUUU X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAQAJBF1jj4ggcwACsk X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Roberto Sassu Add the new functions _run_env(), _exit_env(), _init_env() and _cleanup_env() to run the tests inside a new environment specified with the TST_ENV environment variable. A typical structure of a script with tests is: trap '_report_exit_and_cleanup _cleanup_env cleanup' \ SIGINT SIGTERM SIGSEGV EXIT cleanup() { } _run_env "$TST_KERNEL" "$PWD/$(basename "$0")" "env_var1=$env_var1 ..." _exit_env "$TST_KERNEL" _init_env If TST_ENV is not set or empty, don't create a new testing environment and perform the cleanup in the current environment. Don't create a new testing environment also if the script is already executed in a new environment, to avoid loops. Instead, for cleanup, do it in the new environment and skip it in the host environment (if the cleanup function is passed to _cleanup_env()). Signal to the creator of the environment failures of tests or of the script itself run in the new environment (if the exit code is 1 ($FAIL) or 99 ($HARDFAIL)) with an unclean shutdown of the system. Add haveged and systemd as dependencies for the tests in ci/fedora.sh, respectively for initializing the random number generator and for shutting down the system in the new environment. Signed-off-by: Roberto Sassu Reviewed-by: Stefan Berger --- ci/fedora.sh | 4 +- tests/functions.sh | 91 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) diff --git a/ci/fedora.sh b/ci/fedora.sh index e60de7981c60..198034a34e3c 100755 --- a/ci/fedora.sh +++ b/ci/fedora.sh @@ -45,7 +45,9 @@ yum -y install \ vim-common \ wget \ which \ - zstd + zstd \ + haveged \ + systemd yum -y install docbook5-style-xsl || true yum -y install swtpm || true diff --git a/tests/functions.sh b/tests/functions.sh index d0a9e8e62ca5..03785db91ad6 100755 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -271,6 +271,25 @@ _report_exit_and_cleanup() { [ $testsfail -gt 0 ] && echo -n "$RED" || echo -n "$NORM" echo " FAIL: $testsfail" echo "$NORM" + # Signal failure to the testing environment creator with an unclean shutdown. + if [ -n "$TST_ENV" ] && [ $$ -eq 1 ]; then + if [ -z "$(command -v poweroff)" ]; then + echo "Warning: cannot properly shutdown system" + fi + + # If no test was executed and the script was successful, + # do a clean shutdown. + if [ $testsfail -eq 0 ] && [ $testspass -eq 0 ] && [ $testsskip -eq 0 ] && + [ $exit_code -ne "$FAIL" ] && [ $exit_code -ne "$HARDFAIL" ]; then + poweroff -f + fi + + # If tests were executed and no test failed, do a clean shutdown. + if { [ $testspass -gt 0 ] || [ $testsskip -gt 0 ]; } && + [ $testsfail -eq 0 ]; then + poweroff -f + fi + fi if [ $testsfail -gt 0 ]; then exit "$FAIL" elif [ $testspass -gt 0 ]; then @@ -319,3 +338,75 @@ _softhsm_teardown() { unset SOFTHSM_SETUP_CONFIGDIR SOFTHSM2_CONF PKCS11_KEYURI \ EVMCTL_ENGINE OPENSSL_ENGINE OPENSSL_KEYFORM } + +# Syntax: _run_env +_run_env() { + if [ -z "$TST_ENV" ]; then + return + fi + + if [ $$ -eq 1 ]; then + return + fi + + if [ "$TST_ENV" = "um" ]; then + expect_pass "$1" rootfstype=hostfs rw init="$2" quiet mem=2048M "$3" + else + echo $RED"Testing environment $TST_ENV not supported"$NORM + exit "$FAIL" + fi +} + +# Syntax: _exit_env +_exit_env() { + if [ -z "$TST_ENV" ]; then + return + fi + + if [ $$ -eq 1 ]; then + return + fi + + exit "$OK" +} + +# Syntax: _init_env +_init_env() { + if [ -z "$TST_ENV" ]; then + return + fi + + if [ $$ -ne 1 ]; then + return + fi + + mount -t tmpfs tmpfs /tmp + mount -t proc proc /proc + mount -t sysfs sysfs /sys + mount -t securityfs securityfs /sys/kernel/security + + if [ -n "$(command -v haveged 2> /dev/null)" ]; then + $(command -v haveged) -w 1024 &> /dev/null + fi + + pushd "$PWD" > /dev/null || exit "$FAIL" +} + +# Syntax: _cleanup_env +_cleanup_env() { + if [ -z "$TST_ENV" ]; then + $1 + return + fi + + if [ $$ -ne 1 ]; then + return + fi + + $1 + + umount /sys/kernel/security + umount /sys + umount /proc + umount /tmp +} From patchwork Thu Jan 26 13:58:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roberto Sassu X-Patchwork-Id: 13117154 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D94A0C61DA4 for ; Thu, 26 Jan 2023 13:59:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231540AbjAZN7Z (ORCPT ); Thu, 26 Jan 2023 08:59:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231596AbjAZN7Q (ORCPT ); Thu, 26 Jan 2023 08:59:16 -0500 Received: from frasgout11.his.huawei.com (frasgout11.his.huawei.com [14.137.139.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B46756D5C8 for ; Thu, 26 Jan 2023 05:59:07 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.227]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4P2htv6y3fz9xFQD for ; Thu, 26 Jan 2023 21:51:03 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwB39P_4htJj+ajLAA--.553S8; Thu, 26 Jan 2023 14:58:54 +0100 (CET) From: Roberto Sassu To: zohar@linux.ibm.com, dmitry.kasatkin@gmail.com Cc: linux-integrity@vger.kernel.org, vt@altlinux.org, pvorel@suse.cz, stefanb@linux.ibm.com, Roberto Sassu Subject: [PATCH ima-evm-utils v4 06/11] Introduce TST_LIST variable to select a test to execute Date: Thu, 26 Jan 2023 14:58:02 +0100 Message-Id: <20230126135807.1848668-7-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230126135807.1848668-1-roberto.sassu@huaweicloud.com> References: <20230126135807.1848668-1-roberto.sassu@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: LxC2BwB39P_4htJj+ajLAA--.553S8 X-Coremail-Antispam: 1UD129KBjvJXoW7uF4UCr13XrWxJFWDWrWrAFb_yoW8WrW3pa yfCryagFykuFy7C3sxGrn29a4rCw4rJr1UZr4kJ34Y93y5Jrs8tr4Sk393WFy3Kr90vFZ5 Za1Ivr4rW3Z5ArJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvEb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWUCVW8JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIE14v26r4j6F4UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7 v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF 1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIx AIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI 42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWI evJa73UjIFyTuYvjxUFgAwUUUUU X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAQAJBF1jj4ggcwADsl X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Roberto Sassu It might be desirable, due to restrictions in the testing environment, to execute tests individually. Introduce the TST_LIST variable, which can be set with the name of the test to execute. If the variable is set, expect_pass and expect_fail automatically skip the tests when the first argument of those functions does not match the value of TST_LIST. TST_LIST can be also used in new environments, to execute a subset of defined tests for each environment. It is sufficient to add the variable and its value to the kernel command line. Signed-off-by: Roberto Sassu Reviewed-by: Stefan Berger --- tests/functions.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/functions.sh b/tests/functions.sh index 03785db91ad6..2c4d20536316 100755 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -72,6 +72,12 @@ declare -i TNESTED=0 # just for sanity checking expect_pass() { local -i ret + if [ -n "$TST_LIST" ] && [ "${TST_LIST/$1/}" = "$TST_LIST" ]; then + [ "$VERBOSE" -gt 1 ] && echo "____ SKIP test: $*" + testsskip+=1 + return "$SKIP" + fi + if [ $TNESTED -gt 0 ]; then echo $RED"expect_pass should not be run nested"$NORM testsfail+=1 @@ -98,6 +104,12 @@ expect_pass() { expect_fail() { local ret + if [ -n "$TST_LIST" ] && [ "${TST_LIST/$1/}" = "$TST_LIST" ]; then + [ "$VERBOSE" -gt 1 ] && echo "____ SKIP test: $*" + testsskip+=1 + return "$SKIP" + fi + if [ $TNESTED -gt 0 ]; then echo $RED"expect_fail should not be run nested"$NORM testsfail+=1 From patchwork Thu Jan 26 13:58:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roberto Sassu X-Patchwork-Id: 13117156 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B155DC54E94 for ; Thu, 26 Jan 2023 13:59:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231142AbjAZN7d (ORCPT ); Thu, 26 Jan 2023 08:59:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231281AbjAZN73 (ORCPT ); Thu, 26 Jan 2023 08:59:29 -0500 Received: from frasgout13.his.huawei.com (frasgout13.his.huawei.com [14.137.139.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B65D86A705 for ; Thu, 26 Jan 2023 05:59:12 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.227]) by frasgout13.his.huawei.com (SkyGuard) with ESMTP id 4P2hv26ZX6z9v7J4 for ; Thu, 26 Jan 2023 21:51:10 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwB39P_4htJj+ajLAA--.553S9; Thu, 26 Jan 2023 14:58:59 +0100 (CET) From: Roberto Sassu To: zohar@linux.ibm.com, dmitry.kasatkin@gmail.com Cc: linux-integrity@vger.kernel.org, vt@altlinux.org, pvorel@suse.cz, stefanb@linux.ibm.com, Roberto Sassu Subject: [PATCH ima-evm-utils v4 07/11] Add tests for EVM portable signatures Date: Thu, 26 Jan 2023 14:58:03 +0100 Message-Id: <20230126135807.1848668-8-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230126135807.1848668-1-roberto.sassu@huaweicloud.com> References: <20230126135807.1848668-1-roberto.sassu@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: LxC2BwB39P_4htJj+ajLAA--.553S9 X-Coremail-Antispam: 1UD129KBjvAXoWDZr1DKF15Kr43Jr1kJry7Jrb_yoWrXw4rXo W8WrWaqw45Jw43Jr93ur18AFWDCrZ3CF17AFWYgwn0qF13tryxuw18Ga45Ar43urW8WrWU Kas7AryrZrWDJFn3n29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UjIYCTnIWjp_UUUYq7kC6x804xWl14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK 8VAvwI8IcIk0rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF 0E3s1l82xGYIkIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vE j48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxV AFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv6xkF7I0E 14v26r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrV C2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE 7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7x kEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E 67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8Jw CI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWU CwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCT nIWIevJa73UjIFyTuYvjxUFgAwUUUUU X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAQAJBF1jj4ggcwAEsi X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Roberto Sassu Verify that operations on files with EVM portable signatures succeed and that the new kernel patch set does not break the existing kernel integrity expectations. Build and install mount-idmapped for ci/fedora.sh, to additionally test idmapped mounts. To run the tests, pass the path of the kernel private key with the TST_KEY_PATH environment variable. If not provided, search first in the ima-evm-utils top directory, and then in /lib/modules/$(uname -r)/source/certs/signing_key.pem and /lib/modules/$(uname -r)/build/certs/signing_key.pem. Root privileges are required to mount the image, configure IMA/EVM and set xattrs. Set TST_ENV to 'um', to relaunch the script in a new environment after booting an UML kernel. The UML kernel path must be specified with the TST_KERNEL environment variable. Alternatively, set the TST_EVM_CHANGE_MODE variable to 1, to change the current EVM mode, if a test needs a different one. Otherwise, execute only the tests compatible with the current EVM mode. Also set the EVM_ALLOW_METADATA_WRITES flag in the EVM mode, before launching the script, to run the check_evm_revalidate() test. Execute: echo 4 > /sys/kernel/security/evm The last two environment variables above affect which tests will run the next time the script is executed. Without setting TST_ENV, changes to the current EVM mode will be irreversibly done in the host. Next time, unless the host is rebooted, only tests compatible with the last EVM mode set will run. The others will be skipped. By setting TST_ENV, this problem does not arise as, every time the environment is created, it will be clean with no flags set in the EVM mode. Signed-off-by: Roberto Sassu --- build.sh | 5 + ci/fedora.sh | 7 +- tests/Makefile.am | 2 +- tests/install-mount-idmapped.sh | 6 + tests/portable_signatures.test | 1122 +++++++++++++++++++++++++++++++ 5 files changed, 1140 insertions(+), 2 deletions(-) create mode 100755 tests/install-mount-idmapped.sh create mode 100755 tests/portable_signatures.test diff --git a/build.sh b/build.sh index 4e2f1bb7353b..0920599b2780 100755 --- a/build.sh +++ b/build.sh @@ -114,6 +114,11 @@ if [ $ret -eq 0 ]; then grep "skipped" tests/fsverity.log && \ grep "skipped" tests/fsverity.log | wc -l fi + if [ -f tests/portable_signatures.log ]; then + [ -n "$CI" ] && cat tests/portable_signatures.log || tail tests/portable_signatures.log + grep "skipped" tests/portable_signatures.log && \ + grep "skipped" tests/portable_signatures.log | wc -l + fi exit 0 fi diff --git a/ci/fedora.sh b/ci/fedora.sh index 198034a34e3c..3f75d2e1ddbd 100755 --- a/ci/fedora.sh +++ b/ci/fedora.sh @@ -47,7 +47,11 @@ yum -y install \ which \ zstd \ haveged \ - systemd + systemd \ + keyutils \ + e2fsprogs \ + acl \ + libcap yum -y install docbook5-style-xsl || true yum -y install swtpm || true @@ -59,3 +63,4 @@ fi yum -y install softhsm || true ./tests/install-fsverity.sh +./tests/install-mount-idmapped.sh diff --git a/tests/Makefile.am b/tests/Makefile.am index 305082483f36..421fac577b55 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,7 +2,7 @@ check_SCRIPTS = TESTS = $(check_SCRIPTS) check_SCRIPTS += ima_hash.test sign_verify.test boot_aggregate.test \ - fsverity.test + fsverity.test portable_signatures.test clean-local: -rm -f *.txt *.out *.sig *.sig2 diff --git a/tests/install-mount-idmapped.sh b/tests/install-mount-idmapped.sh new file mode 100755 index 000000000000..c954006dfedc --- /dev/null +++ b/tests/install-mount-idmapped.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +git clone https://github.com/brauner/mount-idmapped.git +cd mount-idmapped +gcc -o mount-idmapped mount-idmapped.c +cd .. diff --git a/tests/portable_signatures.test b/tests/portable_signatures.test new file mode 100755 index 000000000000..9f3339b81765 --- /dev/null +++ b/tests/portable_signatures.test @@ -0,0 +1,1122 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2022-2023 Roberto Sassu +# +# Check if operations on files with EVM portable signatures succeed. + +trap '_report_exit_and_cleanup _cleanup_env cleanup' SIGINT SIGTERM SIGSEGV EXIT + +# Base VERBOSE on the environment variable, if set. +VERBOSE="${VERBOSE:-0}" +TST_EVM_CHANGE_MODE="${TST_EVM_CHANGE_MODE:-0}" + +# From security/integrity/evm/evm.h in kernel source directory. +(( EVM_INIT_HMAC=0x0001 )) +(( EVM_INIT_X509=0x0002 )) +(( EVM_ALLOW_METADATA_WRITES=0x0004 )) +(( EVM_SETUP_COMPLETE=0x80000000 )) + +cd "$(dirname "$0")" || exit "$FAIL" +export PATH=$PWD/../src:$PWD/../mount-idmapped:$PATH +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH +. ./functions.sh +_require evmctl + +cleanup() { + if [ "$g_loop_mounted" = "1" ]; then + popd > /dev/null || exit "$FAIL" + + if [ -n "$g_mountpoint_idmapped" ]; then + umount "$g_mountpoint_idmapped" + fi + + umount "$g_mountpoint" + fi + + if [ -n "$g_dev" ]; then + losetup -d "$g_dev" + fi + + if [ -n "$g_image" ]; then + rm -f "$g_image" + fi + + if [ -n "$key_path_der" ]; then + rm -f "$key_path_der" + fi + + if [ -n "$g_mountpoint" ]; then + rm -Rf "$g_mountpoint" + fi + + if [ -n "$g_mountpoint_idmapped" ]; then + rm -Rf "$g_mountpoint_idmapped" + fi +} + +get_xattr() { + local format="hex" + + if [ "$1" = "security.selinux" ]; then + format="text" + fi + + getfattr -n "$1" -e $format -d "$2" 2> /dev/null | awk -F "=" '$1 == "'"$1"'" {if ("'$format'" == "hex") v=substr($2, 3); else { split($2, temp, "\""); v=temp[2] }; print v}' +} + +# Use the fsuuid= IMA policy keyword to select only files created/used by the +# tests below. Also use fowner= to differentiate between files created/used by +# individual tests. +IMA_UUID="28b23254-9467-44c0-b6ba-34b12e85a26d" +APPRAISE_DIGSIG_FOWNER=2000 +APPRAISE_DIGSIG_RULE="appraise fsuuid=$IMA_UUID fowner=$APPRAISE_DIGSIG_FOWNER appraise_type=imasig" +MEASURE_FOWNER=2001 +MEASURE_RULE="measure fsuuid=$IMA_UUID fowner=$MEASURE_FOWNER template=ima-sig" +APPRAISE_FOWNER=2002 +APPRAISE_RULE="appraise fsuuid=$IMA_UUID fowner=$APPRAISE_FOWNER" +METADATA_CHANGE_FOWNER=3001 +METADATA_CHANGE_FOWNER_2=3002 + +check_load_ima_rule() { + local rule_loaded + local result + local new_policy + + rule_loaded=$(grep "$1" /sys/kernel/security/ima/policy) + if [ -z "$rule_loaded" ]; then + new_policy=$(mktemp -p "$g_mountpoint") + echo "$1" > "$new_policy" + evmctl sign -o -a sha256 --imasig --key "$key_path" "$new_policy" &> /dev/null + echo "$new_policy" > /sys/kernel/security/ima/policy + result=$? + rm -f "$new_policy" + + if [ "$result" -ne 0 ]; then + echo "${RED}Failed to set IMA policy${NORM}" + return "$FAIL" + fi + fi + + return "$OK" +} + +# The purpose of this test is to verify that the patch 'ima: Allow imasig +# requirement to be satisfied by EVM portable signatures' didn't break the +# current behavior (IMA signatures still satisfy the imasig requirement). +check_ima_sig_appraisal() { + local result + + echo "Test: ${FUNCNAME[0]} (evm_value: $evm_value)" + + if [ $((evm_value & (EVM_INIT_X509 | EVM_INIT_HMAC))) -ne 0 ]; then + echo "${CYAN}EVM mode 0 required${NORM}" + return "$SKIP" + fi + + if ! echo "test" > test-file; then + echo "${RED}Cannot write test-file${NORM}" + return "$FAIL" + fi + + if ! evmctl ima_sign -a sha256 --key "$key_path" test-file &> /dev/null; then + echo "${RED}Cannot sign test-file${NORM}" + return "$FAIL" + fi + + if ! chown "$APPRAISE_DIGSIG_FOWNER" test-file; then + echo "${RED}Cannot change owner of test-file${NORM}" + return "$FAIL" + fi + + check_load_ima_rule "$APPRAISE_DIGSIG_RULE" + result=$? + if [ $result -ne "$OK" ]; then + return $result + fi + + # Check if appraisal works. + if ! cat test-file > /dev/null; then + echo "${RED}Cannot read test-file${NORM}" + return "$FAIL" + fi + + # Ensure that files with IMA signature cannot be updated (immutable). + if echo "test" 2> /dev/null >> test-file; then + echo "${RED}Write to test-file should not succeed (immutable file)${NORM}" + return "$FAIL" + fi + + return "$OK" +} + +cleanup_ima_sig_appraisal() { + rm -f test-file +} + +# Requires: +# - ima: Don't remove security.ima if file must not be appraised +# +# The purpose of this test is to verify that the patch 'ima: Introduce template +# field evmsig and write to field sig as fallback' still allows IMA signatures +# to be displayed in the measurement list. +check_ima_sig_ima_measurement_list() { + local result + local ima_sig_fs + local ima_sig_list + + echo "Test: ${FUNCNAME[0]} (evm_value: $evm_value)" + + if ! echo "test" > test-file; then + echo "${RED}Cannot write test-file${NORM}" + return "$FAIL" + fi + + if ! evmctl ima_sign -a sha256 --imasig --key "$key_path" test-file &> /dev/null; then + echo "${RED}Cannot sign test-file${NORM}" + return "$FAIL" + fi + + if ! chown "$MEASURE_FOWNER" test-file; then + echo "${RED}Cannot change owner of test-file${NORM}" + return "$FAIL" + fi + + check_load_ima_rule "$MEASURE_RULE" + result=$? + if [ $result -ne "$OK" ]; then + return $result + fi + + # Read the file to add it to the measurement list. + if ! cat test-file > /dev/null; then + echo "${RED}Cannot read test-file${NORM}" + return "$FAIL" + fi + + ima_sig_fs=$(get_xattr security.ima test-file) + if [ -z "$ima_sig_fs" ]; then + echo "${RED}security.ima not found${NORM}" + return "$FAIL" + fi + + # Search security.ima in the measurement list. + ima_sig_list=$(awk '$6 == "'"$ima_sig_fs"'"' < /sys/kernel/security/ima/ascii_runtime_measurements) + if [ -z "$ima_sig_list" ]; then + echo "${RED}security.ima mismatch (xattr != measurement list)${NORM}" + return "$FAIL" + fi + + return "$OK" +} + +cleanup_ima_sig_ima_measurement_list() { + rm -f test-file +} + +# Requires: +# - evm: Execute evm_inode_init_security() only when an HMAC key is loaded +# +# The purpose of this test is to verify that new files can be created when EVM +# is initialized only with a public key. +check_create_file() { + echo "Test: ${FUNCNAME[0]} (evm_value: $evm_value)" + + # To trigger the bug we need to enable public key verification without HMAC key loaded. + if [ $((evm_value & EVM_INIT_X509)) -ne "$EVM_INIT_X509" ]; then + echo "${CYAN}EVM mode $EVM_INIT_X509 required${NORM}" + return "$SKIP" + fi + + if [ $((evm_value & EVM_INIT_HMAC)) -eq "$EVM_INIT_HMAC" ]; then + echo "${CYAN}EVM mode $EVM_INIT_HMAC must be disabled${NORM}" + return "$SKIP" + fi + + if ! echo "test" > test-file; then + echo "${RED}Cannot write test-file${NORM}" + return "$FAIL" + fi + + return "$OK" +} + +cleanup_create_file() { + rm -f test-file +} + +# Requires: +# - evm: Introduce evm_hmac_disabled() to safely ignore verification errors +# - evm: Allow xattr/attr operations for portable signatures +# - evm: Execute evm_inode_init_security() only when an HMAC key is loaded +# +# The purpose of this test is to verify that EVM with the patches above allows +# metadata to copied one by one, even if the portable signature verification +# temporarily fails until the copy is completed. +check_cp_preserve_xattrs() { + echo "Test: ${FUNCNAME[0]} (evm_value: $evm_value)" + + if [ "$evm_value" -ne "$EVM_INIT_X509" ]; then + echo "${CYAN}EVM mode $EVM_INIT_X509 required${NORM}" + return "$SKIP" + fi + + if ! echo "test" > test-file; then + echo "${RED}Cannot write test-file${NORM}" + return "$FAIL" + fi + + if ! evmctl sign -o -a sha256 --imahash --key "$key_path" test-file &> /dev/null; then + echo "${RED}Cannot sign test-file${NORM}" + return "$FAIL" + fi + + # Check if cp is allowed to set metadata for the new file. + if ! cp -a test-file test-file.copy; then + echo "${RED}Cannot copy test-file with attrs/xattrs preserved${NORM}" + return "$FAIL" + fi + + return "$OK" +} + +cleanup_cp_preserve_xattrs() { + rm -f test-file test-file.copy +} + +# Requires: +# - evm: Introduce evm_hmac_disabled() to safely ignore verification errors +# - evm: Allow xattr/attr operations for portable signatures +# - evm: Execute evm_inode_init_security() only when an HMAC key is loaded +# - ima: Don't remove security.ima if file must not be appraised +# +# The purpose of this test is similar to that of the previous test, with the +# difference that tar is used instead of cp. One remark is that the owner is +# intentionally different (or it should be) from the current owner, to +# incrementally test the patches without 'evm: Allow setxattr() and setattr() +# for unmodified metadata'. +check_tar_extract_xattrs_different_owner() { + echo "Test: ${FUNCNAME[0]} (evm_value: $evm_value)" + + if [ "$evm_value" -ne "$EVM_INIT_X509" ]; then + echo "${CYAN}EVM mode $EVM_INIT_X509 required${NORM}" + return "$SKIP" + fi + + if ! mkdir in out; then + echo "${RED}Cannot create directories${NORM}" + return "$FAIL" + fi + + if ! echo "test" > in/test-file; then + echo "${RED}Cannot write test-file${NORM}" + return "$FAIL" + fi + + if ! chown 3000 in/test-file; then + echo "${RED}Cannot change owner of test-file${NORM}" + return "$FAIL" + fi + + if ! chmod 600 in/test-file; then + echo "${RED}Cannot change mode of test-file${NORM}" + return "$FAIL" + fi + + if ! evmctl sign -o -a sha256 --imahash --key "$key_path" in/test-file &> /dev/null; then + echo "${RED}Cannot sign test-file${NORM}" + return "$FAIL" + fi + + if ! tar --xattrs-include=* -cf test-archive.tar in/test-file; then + echo "${RED}Cannot create archive with xattrs${NORM}" + return "$FAIL" + fi + + # Check if tar is allowed to set metadata for the extracted file. + # Ensure that the owner from the archive is different from the + # owner of the extracted file to avoid that portable signature + # verification succeeds before restoring original metadata + # (a patch allows modification of immutable metadata if portable + # signature verification fails). + if ! tar --xattrs-include=* -xf test-archive.tar -C out; then + echo "${RED}Cannot extract archive with xattrs${NORM}" + return "$FAIL" + fi + + return "$OK" +} + +cleanup_tar_extract_xattrs_different_owner() { + rm -Rf in out test-archive.tar +} + +# Requires: +# - evm: Introduce evm_hmac_disabled() to safely ignore verification errors +# - evm: Allow xattr/attr operations for portable signatures +# - evm: Pass user namespace to set/remove xattr hooks +# - evm: Allow setxattr() and setattr() for unmodified metadata +# - evm: Execute evm_inode_init_security() only when an HMAC key is loaded +# - ima: Don't remove security.ima if file must not be appraised +# +# The purpose of this test is similar to that of the previous two tests. The +# difference is that tar is used instead of cp, and the extracted files have +# the same owner as the current one. Thus, this test requires 'evm: Allow +# setxattr() and setattr() for unmodified metadata'. +check_tar_extract_xattrs_same_owner() { + echo "Test: ${FUNCNAME[0]} (evm_value: $evm_value)" + + if [ "$evm_value" -ne "$EVM_INIT_X509" ]; then + echo "${CYAN}EVM mode $EVM_INIT_X509 required${NORM}" + return "$SKIP" + fi + + if ! mkdir in out; then + echo "${RED}Cannot create directories${NORM}" + return "$FAIL" + fi + + if ! echo "test" > in/test-file; then + echo "${RED}Cannot write test-file${NORM}" + return "$FAIL" + fi + + if ! evmctl sign -o -a sha256 --imahash --key "$key_path" in/test-file &> /dev/null; then + echo "${RED}Cannot sign test-file${NORM}" + return "$FAIL" + fi + + if ! tar --xattrs-include=* -cf test-archive.tar in/test-file; then + echo "${RED}Cannot create archive with xattrs${NORM}" + return "$FAIL" + fi + + # Check if tar is allowed to set metadata for the extracted file. + # This test is different from the previous one, as the owner + # from the archive is the same of the owner of the extracted + # file. tar will attempt anyway to restore the original owner but + # unlike the previous test, portable signature verification already + # succeeds at the time the owner is set (another patch allows + # metadata operations if those operations don't modify current + # values). + if ! tar --xattrs-include=* -xf test-archive.tar -C out; then + echo "${RED}Cannot extract archive with xattrs${NORM}" + return "$FAIL" + fi + + return "$OK" +} + +cleanup_tar_extract_xattrs_same_owner() { + rm -Rf in out test-archive.tar +} + +# Requires: +# - evm: Introduce evm_hmac_disabled() to safely ignore verification errors +# - evm: Allow xattr/attr operations for portable signatures +# - evm: Pass user namespace to set/remove xattr hooks +# - evm: Allow setxattr() and setattr() for unmodified metadata +# - ima: Don't remove security.ima if file must not be appraised +# - evm: Execute evm_inode_init_security() only when an HMAC key is loaded +# +# The purpose of this test is to further verify the patches above, by executing +# commands to set the same or different metadata. Setting the same metadata +# should be allowed, setting different metadata should be denied. +check_metadata_change() { + local ima_xattr + local label + local last_char + local msg + + echo "Test: ${FUNCNAME[0]} (evm_value: $evm_value)" + + if [ "$evm_value" -ne "$EVM_INIT_X509" ]; then + echo "${CYAN}EVM mode $EVM_INIT_X509 required${NORM}" + return "$SKIP" + fi + + if ! echo "test" > test-file; then + echo "${RED}Cannot write test-file${NORM}" + return "$FAIL" + fi + + if ! chown "$METADATA_CHANGE_FOWNER" test-file; then + echo "${RED}Cannot change owner of test-file${NORM}" + return "$FAIL" + fi + + if ! chgrp "$METADATA_CHANGE_FOWNER" test-file; then + echo "${RED}Cannot change group of test-file${NORM}" + return "$FAIL" + fi + + if ! chmod 2644 test-file; then + echo "${RED}Cannot change mode of test-file${NORM}" + return "$FAIL" + fi + + if ! evmctl sign -o -a sha256 --imahash --key "$key_path" test-file &> /dev/null; then + echo "${RED}Cannot sign test-file${NORM}" + return "$FAIL" + fi + + # If metadata modification is not allowed, EVM should deny any + # operation that modifies metadata. Check if setting the same + # value is allowed. + if ! chown "$METADATA_CHANGE_FOWNER" test-file; then + echo "${RED}Cannot set same owner for test-file${NORM}" + return "$FAIL" + fi + + # Setting a different value should not be allowed. + if chown "$METADATA_CHANGE_FOWNER_2" test-file 2> /dev/null; then + echo "${RED}Owner change for test-file should not be allowed (immutable metadata)${NORM}" + return "$FAIL" + fi + + # Repeat the test for the file mode. + if ! chmod 2644 test-file; then + echo "${RED}Cannot set same mode for test-file${NORM}" + return "$FAIL" + fi + + if chmod 2666 test-file 2> /dev/null; then + echo "${RED}Mode change for test-file should not be allowed (immutable metadata)${NORM}" + return "$FAIL" + fi + + if [ -n "$(command -v chcon 2> /dev/null)" ] && [ -n "$(command -v getenforce 2> /dev/null)" ] && [ "$(getenforce 2> /dev/null)" != "Disabled" ]; then + # Repeat the test for the SELinux label. + label=$(get_xattr security.selinux test-file) + + if [ -n "$label" ]; then + if ! chcon "$label" test-file; then + echo "${RED}Cannot set same security.selinux for test-file${NORM}" + return "$FAIL" + fi + fi + + if chcon unconfined_u:object_r:null_device_t:s0 test-file 2> /dev/null; then + echo "${RED}security.selinux change for test file should not be allowed (immutable metadata)${NORM}" + return "$FAIL" + fi + fi + + # Repeat the test for the IMA signature. + ima_xattr=$(get_xattr security.ima test-file) + if [ -z "$ima_xattr" ]; then + echo "${RED}security.ima not found${NORM}" + return "$FAIL" + fi + + if ! setfattr -n security.ima -v 0x"$ima_xattr" test-file; then + echo "${RED}Cannot set same security.ima for test-file${NORM}" + return "$FAIL" + fi + + last_char=${ima_xattr: -1} + ((last_char += 1)) + ((last_char %= 10)) + ima_xattr=${ima_xattr:0:-1}$last_char + + if setfattr -n security.ima -v 0x"$ima_xattr" test-file 2> /dev/null; then + echo "${RED}Change of security.ima for test-file should not be allowed (immutable metadata)${NORM}" + return "$FAIL" + fi + + # Repeat the test for ACLs. + if ! msg=$(exec 2>&1 && setfacl --set u::rw,g::r,o::r,m:r test-file); then + if [ "${msg%not supported}" != "$msg" ]; then + return "$OK" + fi + + echo "${RED}Cannot preserve system.posix_acl_access for test-file${NORM}" + return "$FAIL" + fi + + if setfacl --set u::rw,g::r,o::r,m:rw test-file 2> /dev/null; then + echo "${RED}Change of system.posix_acl_access for test-file should not be allowed (immutable metadata)${NORM}" + return "$FAIL" + fi + + if [ -n "$g_mountpoint_idmapped" ]; then + pushd "$g_mountpoint_idmapped" > /dev/null || exit "$FAIL" + + # Repeat the test for ACLs on an idmapped mount. + # + # This test relies on the fact that the caller of this script (root) is in + # the same owning group of test-file (in the idmapped mount the group is + # root, not $METADATA_CHANGE_FOWNER and, for this reason, the S_ISGID bit + # is not cleared. If EVM was not aware of the mapping, it would have + # determined that root is not in the owning group of test-file and given + # that also CAP_FSETID is cleared, the S_ISGID bit would have been cleared + # and thus the operation would fail (file metadata changed). + if ! capsh --drop='cap_fsetid' -- -c 'setfacl --set u::rw,g::r,o::r test-file'; then + echo "${RED}Cannot preserve system.posix_acl_access for test-file${NORM}" + popd || exit "$FAIL" + return "$FAIL" + fi + + popd > /dev/null || exit "$FAIL" + fi + + return "$OK" +} + +cleanup_metadata_change() { + rm -f test-file +} + +# Requires: +# - evm: Introduce evm_revalidate_status() +# - evm: Execute evm_inode_init_security() only when an HMAC key is loaded +# +# Note: +# This test can be run if EVM_ALLOW_METADATA_WRITES is set in advance +# before running this script. If it is not set before, this script sets +# EVM_SETUP_COMPLETE, disabling further EVM mode modifications until reboot. +# +# Without EVM_ALLOW_METADATA_WRITES, EVM_SETUP_COMPLETE is necessary to ignore +# the INTEGRITY_NOLABEL and INTEGRITY_NOXATTRS errors. +# +# The purpose of this test is to verify that IMA detected a metadata change +# when EVM_ALLOW_METADATA_WRITES is set (metadata operations are always +# allowed). After the first successful appraisal, the test intentionally changes +# metadata and verifies that IMA revoked access to the file. The test also +# verifies that IMA grants access again to the file after restoring the correct +# metadata. +check_evm_revalidate() { + local result + local ima_xattr + local ima_xattr_new + local evm_xattr + local evm_xattr_new + local label + local last_char + local msg + + echo "Test: ${FUNCNAME[0]} (evm_value: $evm_value)" + + if [ "$evm_value" -ne $((EVM_INIT_X509 | EVM_ALLOW_METADATA_WRITES)) ]; then + echo "${CYAN}EVM mode $((EVM_INIT_X509 | EVM_ALLOW_METADATA_WRITES)) required, execute echo 4 > /sys/kernel/security/evm before running this test${NORM}" + return "$SKIP" + fi + + if ! echo "test" > test-file; then + echo "${RED}Cannot write test-file${NORM}" + return "$FAIL" + fi + + if ! chmod 600 test-file; then + echo "${RED}Cannot change mode of test-file${NORM}" + return "$FAIL" + fi + + # We need to defer setting the correct owner, as there could be + # already an IMA policy rule preventing evmctl from reading the + # file to calculate the digest. + if ! evmctl sign -o -a sha256 --imahash --uid "$APPRAISE_FOWNER" --key "$key_path" test-file &> /dev/null; then + echo "${RED}Cannot sign test-file${NORM}" + return "$FAIL" + fi + + if ! chown "$APPRAISE_FOWNER" test-file; then + echo "${RED}Cannot change owner of test-file${NORM}" + return "$FAIL" + fi + + check_load_ima_rule "$APPRAISE_RULE" + result=$? + if [ $result -ne "$OK" ]; then + return $result + fi + + # Read the file so that IMA would not re-appraise it next time. + if ! cat test-file &> /dev/null; then + echo "${RED}Cannot read test-file${NORM}" + return "$FAIL" + fi + + # After enabling metadata modification, operations should succeed even + # if the file has a portable signature. However, the previously cached + # appraisal status should be invalidated. + if ! chmod 644 test-file; then + echo "${RED}Cannot change mode of test-file${NORM}" + return "$FAIL" + fi + + # Here check if IMA re-appraised the file. The read should fail + # since now file metadata is invalid. + if cat test-file &> /dev/null; then + echo "${RED}Read of test-file should not succeed (invalid mode)${NORM}" + return "$FAIL" + fi + + # Restore metadata back to the original value. + if ! chmod 600 test-file; then + echo "${RED}Cannot restore original mode of test-file${NORM}" + return "$FAIL" + fi + + # Ensure that now IMA appraisal succeeds. + if ! cat test-file > /dev/null; then + echo "${RED}Cannot read test-file after restoring correct mode${NORM}" + return "$FAIL" + fi + + if [ -n "$(command -v chcon 2> /dev/null)" ] && [ -n "$(command -v getenforce 2> /dev/null)" ] && [ "$(getenforce 2> /dev/null)" != "Disabled" ]; then + # Repeat the test for the SELinux label. + label=$(get_xattr security.selinux test-file) + + if ! chcon unconfined_u:object_r:null_device_t:s0 test-file; then + echo "${RED}Cannot change security.selinux of test-file${NORM}" + return "$FAIL" + fi + + if cat test-file &> /dev/null; then + echo "${RED}Read of test-file should not succeed (invalid security.selinux)${NORM}" + return "$FAIL" + fi + + if [ -n "$label" ]; then + if ! chcon "$label" test-file; then + echo "${RED}Cannot restore original security.selinux of test-file${NORM}" + return "$FAIL" + fi + else + attr -S -r selinux test-file + fi + + if ! cat test-file > /dev/null; then + echo "${RED}Cannot read test-file after restoring correct security.selinux${NORM}" + return "$FAIL" + fi + fi + + # Repeat the test for the IMA signature. + ima_xattr=$(get_xattr security.ima test-file) + if [ -z "$ima_xattr" ]; then + echo "${RED}security.ima not found${NORM}" + return "$FAIL" + fi + + last_char=${ima_xattr: -1} + ((last_char += 1)) + ((last_char %= 10)) + ima_xattr_new=${ima_xattr:0:-1}$last_char + + if ! setfattr -n security.ima -v 0x"$ima_xattr_new" test-file; then + echo "${RED}Cannot set security.ima of test-file${NORM}" + return "$FAIL" + fi + + if cat test-file &> /dev/null; then + echo "${RED}Read of test-file should not succeed (invalid security.ima)${NORM}" + return "$FAIL" + fi + + if ! setfattr -n security.ima -v 0x"$ima_xattr" test-file; then + echo "${RED}Cannot restore original security.ima of test-file${NORM}" + return "$FAIL" + fi + + if ! cat test-file > /dev/null; then + echo "${RED}Cannot read test-file after restoring correct security.ima${NORM}" + return "$FAIL" + fi + + # Repeat the test for the EVM signature. + evm_xattr=$(get_xattr security.evm test-file) + if [ -z "$evm_xattr" ]; then + echo "${RED}security.evm not found${NORM}" + return "$FAIL" + fi + + last_char=${evm_xattr: -1} + ((last_char += 1)) + ((last_char %= 10)) + evm_xattr_new=${evm_xattr:0:-1}$last_char + + if ! setfattr -n security.evm -v 0x"$evm_xattr_new" test-file; then + echo "${RED}Cannot set security.evm of test-file${NORM}" + return "$FAIL" + fi + + if cat test-file &> /dev/null; then + echo "${RED}Read of test-file should not succeed (invalid security.evm)${NORM}" + return "$FAIL" + fi + + if ! setfattr -n security.evm -v 0x"$evm_xattr" test-file; then + echo "${RED}Cannot restore original security.evm of test-file${NORM}" + return "$FAIL" + fi + + if ! cat test-file > /dev/null; then + echo "${RED}Cannot read test-file after restoring correct security.evm${NORM}" + return "$FAIL" + fi + + # Repeat the test for ACLs. + if ! setfacl -m u::rwx test-file 2> /dev/null; then + echo "${RED}Cannot change system.posix_acl_access${NORM}" + return "$FAIL" + fi + + if cat test-file &> /dev/null; then + echo "${RED}Read of test-file should not succeed (invalid system.posix_acl_access)${NORM}" + return "$FAIL" + fi + + if ! setfacl -m u::rw test-file; then + echo "${RED}Cannot restore original system.posix_acl_access for test-file${NORM}" + return "$FAIL" + fi + + if ! cat test-file > /dev/null; then + echo "${RED}Cannot read test-file after restoring correct system.posix_acl_access${NORM}" + return "$FAIL" + fi + + return "$OK" +} + +cleanup_evm_revalidate() { + rm -f test-file +} + +# Requires: +# - evm: Introduce evm_hmac_disabled() to safely ignore verification errors +# - evm: Introduce evm_revalidate_status() +# - ima: Allow imasig requirement to be satisfied by EVM portable signatures +# - evm: Execute evm_inode_init_security() only when an HMAC key is loaded +# +# The purpose of this test is to verify that IMA manages files with an EVM +# portable signature similarly to those with an IMA signature: content can be +# written to new files after adding the signature and files can be accessed +# when the imasig requirement is specified in the IMA policy. +check_evm_portable_sig_ima_appraisal() { + local result + local xattr_orig + local xattr + local mode + local owner + + echo "Test: ${FUNCNAME[0]} (evm_value: $evm_value)" + + if [ $((evm_value & EVM_INIT_X509)) -ne "$EVM_INIT_X509" ]; then + echo "${CYAN}EVM flag $EVM_INIT_X509 required${NORM}" + return "$SKIP" + fi + + if ! echo "test" > test-file; then + echo "${RED}Cannot write test-file${NORM}" + return "$FAIL" + fi + + if ! chmod 600 test-file; then + echo "${RED}Cannot change mode of test-file${NORM}" + return "$FAIL" + fi + + # We need to defer setting the correct owner, as there could be + # already an IMA policy rule preventing evmctl from reading the + # file to calculate the digest. + if ! evmctl sign -o -a sha256 --imahash --uid "$APPRAISE_DIGSIG_FOWNER" --key "$key_path" test-file &> /dev/null; then + echo "${RED}Cannot sign test-file${NORM}" + return "$FAIL" + fi + + if ! chown "$APPRAISE_DIGSIG_FOWNER" test-file; then + echo "${RED}Cannot change owner of test-file${NORM}" + return "$FAIL" + fi + + check_load_ima_rule "$APPRAISE_DIGSIG_RULE" + result=$? + if [ "$result" -ne "$OK" ]; then + return "$result" + fi + + # Ensure that a file with a portable signature satisfies the + # appraise_type=imasig requirement specified in the IMA policy. + if ! cat test-file > /dev/null; then + echo "${RED}Cannot read test-file${NORM}" + return "$FAIL" + fi + + # Even files with a portable signature should be considered as + # immutable by IMA. Write should fail. + if echo "test" 2> /dev/null >> test-file; then + echo "${RED}Write to test-file should not succeed (immutable metadata)${NORM}" + return "$FAIL" + fi + + if ! tar --xattrs-include=* -cf test-archive.tar test-file; then + echo "${RED}Cannot create archive with xattrs${NORM}" + return "$FAIL" + fi + + mkdir out + + # Appraisal of the new file, extracted by tar, should succeed + # not only if the new file has an IMA signature but also if + # it has a portable signature. + if ! tar --xattrs-include=* -xf test-archive.tar -C out; then + echo "${RED}Cannot extract archive with xattrs${NORM}" + return "$FAIL" + fi + + # Check if xattrs have been correctly set. + xattr_orig=$(get_xattr security.selinux test-file) + xattr=$(get_xattr security.selinux out/test-file) + if [ "$xattr" != "$xattr_orig" ]; then + echo "${RED}security.selinux mismatch between original and extracted file${NORM}" + return "$FAIL" + fi + + xattr_orig=$(get_xattr security.ima test-file) + xattr=$(get_xattr security.ima out/test-file) + if [ "$xattr" != "$xattr_orig" ]; then + echo "${RED}security.ima mismatch between original and extracted file${NORM}" + return "$FAIL" + fi + + xattr_orig=$(get_xattr security.evm test-file) + xattr=$(get_xattr security.evm out/test-file) + if [ "$xattr" != "$xattr_orig" ]; then + echo "${RED}security.evm mismatch between original and extracted file${NORM}" + return "$FAIL" + fi + + # Check if attrs have been correctly set. + owner=$(stat -c "%u" out/test-file) + if [ "$owner" != "$APPRAISE_DIGSIG_FOWNER" ]; then + echo "${RED}owner mismatch between original and extracted file${NORM}" + return "$FAIL" + fi + + mode=$(stat -c "%a" out/test-file) + if [ "$mode" != "600" ]; then + echo "${RED}mode mismatch between original and extracted file${NORM}" + return "$FAIL" + fi + + return "$OK" +} + +cleanup_evm_portable_sig_ima_appraisal() { + rm -f test-file test-archive.tar + rm -Rf out +} + +# Requires: +# - ima: Introduce template field evmsig and write to field sig as fallback +# - evm: Execute evm_inode_init_security() only when an HMAC key is loaded +# - ima: Don't remove security.ima if file must not be appraised +# +# The purpose of this test is to verify that the EVM portable signature is +# displayed in the measurement list. +check_evm_portable_sig_ima_measurement_list() { + local result + local evm_sig_fs + local evm_sig_list + + echo "Test: ${FUNCNAME[0]} (evm_value: $evm_value)" + + if ! echo "test" > test-file; then + echo "${RED}Cannot write test-file${NORM}" + return "$FAIL" + fi + + if ! chown "$MEASURE_FOWNER" test-file; then + echo "${RED}Cannot change owner of test-file${NORM}" + return "$FAIL" + fi + + if ! evmctl sign -o -a sha256 --imahash --key "$key_path" test-file &> /dev/null; then + echo "${RED}Cannot sign test-file${NORM}" + return "$FAIL" + fi + + check_load_ima_rule "$MEASURE_RULE" + result=$? + if [ "$result" -ne "$OK" ]; then + return "$result" + fi + + # Invalidate previous measurement to add new entry + touch test-file + + # Read the file to add it to the measurement list. + if ! cat test-file > /dev/null; then + echo "${RED}Cannot read test-file${NORM}" + return "$FAIL" + fi + + evm_sig_fs=$(get_xattr security.evm test-file) + if [ -z "$evm_sig_fs" ]; then + echo "${RED}security.evm not found${NORM}" + return "$FAIL" + fi + + # Search security.evm in the measurement list. + evm_sig_list=$(awk '$6 == "'"$evm_sig_fs"'"' < /sys/kernel/security/ima/ascii_runtime_measurements) + if [ -z "$evm_sig_list" ]; then + echo "${RED}security.evm mismatch (xattr != measurement list)${NORM}" + return "$FAIL" + fi + + return "$OK" +} + +cleanup_evm_portable_sig_ima_measurement_list() { + rm -f test-file +} + +# Run in the new environment if TST_ENV is set. +_run_env "$TST_KERNEL" "$PWD/$(basename "$0")" "TST_ENV=$TST_ENV TST_KERNEL=$TST_KERNEL PATH=$PATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH VERBOSE=$VERBOSE TST_EVM_CHANGE_MODE=$TST_EVM_CHANGE_MODE TST_KEY_PATH=$TST_KEY_PATH" + +# Run in the new environment if TST_ENV is set (skipped test). +_run_env "$TST_KERNEL" "$PWD/$(basename "$0")" "TST_ENV=$TST_ENV TST_KERNEL=$TST_KERNEL PATH=$PATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH VERBOSE=$VERBOSE TST_EVM_CHANGE_MODE=$TST_EVM_CHANGE_MODE TST_KEY_PATH=$TST_KEY_PATH TST_LIST=check_evm_revalidate" + +# Exit from the creator of the new environment. +_exit_env "$TST_KERNEL" + +# Mount filesystems in the new environment. +_init_env + +g_mountpoint=$(mktemp -d) +g_image=$(mktemp) + +if [ -z "$g_mountpoint" ]; then + echo "${RED}Mountpoint directory not created${NORM}" + exit "$FAIL" +fi + +if [ "$(whoami)" != "root" ]; then + echo "${CYAN}This script must be executed as root${NORM}" + exit "$SKIP" +fi + +if [ -n "$TST_KEY_PATH" ]; then + if [ "${TST_KEY_PATH:0:1}" != "/" ]; then + echo "${RED}Absolute path required for the signing key${NORM}" + exit "$FAIL" + fi + + if [ ! -f "$TST_KEY_PATH" ]; then + echo "${RED}Kernel signing key not found in $TST_KEY_PATH${NORM}" + exit "$FAIL" + fi + + key_path="$TST_KEY_PATH" +elif [ -f "$PWD/../signing_key.pem" ]; then + key_path="$PWD/../signing_key.pem" +elif [ -f "/lib/modules/$(uname -r)/source/certs/signing_key.pem" ]; then + key_path="/lib/modules/$(uname -r)/source/certs/signing_key.pem" +elif [ -f "/lib/modules/$(uname -r)/build/certs/signing_key.pem" ]; then + key_path="/lib/modules/$(uname -r)/build/certs/signing_key.pem" +else + echo "${CYAN}Kernel signing key not found${NORM}" + exit "$SKIP" +fi + +key_path_der=$(mktemp) + +if [ ! -f "/sys/kernel/security/evm" ]; then + echo "${CYAN}EVM support in the kernel disabled${NORM}" + exit "$SKIP" +fi + +# Assume that the EVM mode can be changed in a new environment. +if [ -n "$TST_ENV" ]; then + TST_EVM_CHANGE_MODE=1 +fi + +evm_value=$(cat /sys/kernel/security/evm) + +openssl x509 -in "$key_path" -out "$key_path_der" -outform der +if ! keyctl padd asymmetric pubkey %keyring:.ima < "$key_path_der" &> /dev/null; then + echo "${RED}Public key cannot be added to the IMA keyring${NORM}" + exit "$FAIL" +fi + +if ! dd if=/dev/zero of="$g_image" bs=1M count=20 &> /dev/null; then + echo "${RED}Cannot create test image${NORM}" + exit "$FAIL" +fi + +g_dev=$(losetup -f "$g_image" --show) +if [ -z "$g_dev" ]; then + echo "${RED}Cannot create loop device${NORM}" + exit "$FAIL" +fi + +if ! mkfs.ext4 -U "$IMA_UUID" -b 4096 "$g_dev" &> /dev/null; then + echo "${RED}Cannot format $g_dev${NORM}" + exit "$FAIL" +fi + +if ! mount -o i_version "$g_dev" "$g_mountpoint"; then + echo "${RED}Cannot mount loop device${NORM}" + exit "$FAIL" +fi + +if [ -n "$(command -v mount-idmapped 2> /dev/null)" ]; then + echo "Found mount-idmapped at $(command -v mount-idmapped), testing idmapped mounts" + g_mountpoint_idmapped=$(mktemp -d) + if ! mount-idmapped --map-mount b:"$METADATA_CHANGE_FOWNER":0:1 "$g_mountpoint" "$g_mountpoint_idmapped"; then + echo "${RED}mount-idmapped failed${NORM}" + exit "$FAIL" + fi +fi + +g_loop_mounted=1 +pushd "$g_mountpoint" > /dev/null || exit "$FAIL" + +expect_pass check_ima_sig_appraisal +cleanup_ima_sig_appraisal +expect_pass check_ima_sig_ima_measurement_list +cleanup_ima_sig_ima_measurement_list + +if [ "$(echo -e "$(uname -r)\n5.12" | sort -V | head -n 1)" != "5.12" ]; then + exit "$OK" +fi + +if [ $((evm_value & EVM_INIT_X509)) -ne "$EVM_INIT_X509" ] && [ "$TST_EVM_CHANGE_MODE" -eq 1 ]; then + if ! keyctl padd asymmetric pubkey %keyring:.evm < "$key_path_der" &> /dev/null; then + echo "${RED}Public key cannot be added to the EVM keyring${NORM}" + exit "$FAIL" + fi + + echo "$EVM_INIT_X509" > /sys/kernel/security/evm 2> /dev/null +fi + +if [ "$(expr index "$TST_LIST" "check_evm_revalidate")" -gt 0 ] && [ "$TST_EVM_CHANGE_MODE" -eq 1 ]; then + echo "$EVM_ALLOW_METADATA_WRITES" > /sys/kernel/security/evm 2> /dev/null +fi + +# We cannot determine from securityfs if EVM_SETUP_COMPLETE is set, so we set it unless EVM_ALLOW_METADATA_WRITES is set. +if [ $((evm_value & EVM_ALLOW_METADATA_WRITES)) -ne "$EVM_ALLOW_METADATA_WRITES" ] && [ "$TST_EVM_CHANGE_MODE" -eq 1 ]; then + echo "$EVM_SETUP_COMPLETE" > /sys/kernel/security/evm 2> /dev/null +fi + +evm_value=$(cat /sys/kernel/security/evm) + +expect_pass check_create_file +cleanup_create_file +expect_pass check_cp_preserve_xattrs +cleanup_cp_preserve_xattrs +expect_pass check_tar_extract_xattrs_different_owner +cleanup_tar_extract_xattrs_different_owner +expect_pass check_tar_extract_xattrs_same_owner +cleanup_tar_extract_xattrs_same_owner +expect_pass check_metadata_change +cleanup_metadata_change +expect_pass check_evm_revalidate +cleanup_evm_revalidate +expect_pass check_evm_portable_sig_ima_appraisal +cleanup_evm_portable_sig_ima_appraisal +expect_pass check_evm_portable_sig_ima_measurement_list +cleanup_evm_portable_sig_ima_measurement_list From patchwork Thu Jan 26 13:58:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roberto Sassu X-Patchwork-Id: 13117157 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 555CFC61DA3 for ; Thu, 26 Jan 2023 13:59:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231150AbjAZN7h (ORCPT ); Thu, 26 Jan 2023 08:59:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230317AbjAZN7e (ORCPT ); Thu, 26 Jan 2023 08:59:34 -0500 Received: from frasgout13.his.huawei.com (frasgout13.his.huawei.com [14.137.139.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0E627AAC for ; Thu, 26 Jan 2023 05:59:16 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.227]) by frasgout13.his.huawei.com (SkyGuard) with ESMTP id 4P2hv71Ghcz9v7Qq for ; Thu, 26 Jan 2023 21:51:15 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwB39P_4htJj+ajLAA--.553S10; Thu, 26 Jan 2023 14:59:03 +0100 (CET) From: Roberto Sassu To: zohar@linux.ibm.com, dmitry.kasatkin@gmail.com Cc: linux-integrity@vger.kernel.org, vt@altlinux.org, pvorel@suse.cz, stefanb@linux.ibm.com, Roberto Sassu Subject: [PATCH ima-evm-utils v4 08/11] Adapt fsverity.test to be able to run in a new testing environment Date: Thu, 26 Jan 2023 14:58:04 +0100 Message-Id: <20230126135807.1848668-9-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230126135807.1848668-1-roberto.sassu@huaweicloud.com> References: <20230126135807.1848668-1-roberto.sassu@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: LxC2BwB39P_4htJj+ajLAA--.553S10 X-Coremail-Antispam: 1UD129KBjvJXoW7Ar1rAr13XrWfJFW3XFWfuFg_yoW8Xw47pF y5JFyYkFZ5tFyfGw4DWF42yFy0k3y8ZryUXrZ7ua43WF98ArWjyr40kw47WF9FyFZaqFs5 u3y0vr13Gw1qkrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU90b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWUCVW8JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAF wI0_Gr1j6F4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I 80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCj c4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4 AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE 17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1I6r4UMI IF0xvE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1x MIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIda VFxhVjvjDU0xZFpf9x07UZo7tUUUUU= X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAQAJBF1jj4ggcwAFsj X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Roberto Sassu Adapt fsverity.test by adding calls to the testing environment API in functions.sh. If TST_ENV is set, create a new environment and run the kernel specified with the TST_KERNEL environment variable. Otherwise, keep the current behavior. Signed-off-by: Roberto Sassu Reviewed-by: Stefan Berger --- tests/fsverity.test | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/fsverity.test b/tests/fsverity.test index be9594010de5..8261de4ea3c9 100755 --- a/tests/fsverity.test +++ b/tests/fsverity.test @@ -47,7 +47,7 @@ FSVERITY="$(which fsverity)" _require dd mkfs blkid e2fsck tune2fs evmctl setfattr ./gen-keys.sh >/dev/null 2>&1 -trap '_report_exit_and_cleanup cleanup' SIGINT SIGTERM EXIT +trap '_report_exit_and_cleanup _cleanup_env cleanup' SIGINT SIGTERM EXIT cleanup() { if [ -e $TST_MNT ]; then @@ -308,6 +308,15 @@ measure-ima() { return "$error" } +# Run in the new environment if TST_ENV is set. +_run_env "$TST_KERNEL" "$PWD/$(basename "$0")" "TST_ENV=$TST_ENV TST_KERNEL=$TST_KERNEL PATH=$PATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH VERBOSE=$VERBOSE" + +# Exit from the creator of the new environment. +_exit_env "$TST_KERNEL" + +# Mount filesystems in the new environment. +_init_env + # Dependency on being able to read and write the IMA policy file. # Requires both CONFIG_IMA_WRITE_POLICY, CONFIG_IMA_READ_POLICY be # enabled. From patchwork Thu Jan 26 13:58:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roberto Sassu X-Patchwork-Id: 13117159 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB030C61DA4 for ; Thu, 26 Jan 2023 14:00:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230399AbjAZOAI (ORCPT ); Thu, 26 Jan 2023 09:00:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231786AbjAZN7s (ORCPT ); Thu, 26 Jan 2023 08:59:48 -0500 Received: from frasgout12.his.huawei.com (frasgout12.his.huawei.com [14.137.139.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 880753C1B for ; Thu, 26 Jan 2023 05:59:29 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.228]) by frasgout12.his.huawei.com (SkyGuard) with ESMTP id 4P2hv41HStz9v7bc for ; Thu, 26 Jan 2023 21:51:12 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwB39P_4htJj+ajLAA--.553S11; Thu, 26 Jan 2023 14:59:07 +0100 (CET) From: Roberto Sassu To: zohar@linux.ibm.com, dmitry.kasatkin@gmail.com Cc: linux-integrity@vger.kernel.org, vt@altlinux.org, pvorel@suse.cz, stefanb@linux.ibm.com, Roberto Sassu Subject: [PATCH ima-evm-utils v4 09/11] Use in-place built fsverity binary instead of installing it Date: Thu, 26 Jan 2023 14:58:05 +0100 Message-Id: <20230126135807.1848668-10-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230126135807.1848668-1-roberto.sassu@huaweicloud.com> References: <20230126135807.1848668-1-roberto.sassu@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: LxC2BwB39P_4htJj+ajLAA--.553S11 X-Coremail-Antispam: 1UD129KBjvJXoW7tFy8XryfXr18uFyfWFyxGrg_yoW8Xw17p3 Wj93W0krn5XF1UCr48GFsFva4I9rWkWr15XrykXa4IvFWkAr4jqr1Svr4rWr1aqrWUXr4S yw4Ivrn5Ka1DArJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU90b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWUCVW8JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAF wI0_Gr1j6F4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I 80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCj c4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4 AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE 17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1I6r4UMI IF0xvE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1x MIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIda VFxhVjvjDU0xZFpf9x07UZo7tUUUUU= X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAgAJBF1jj4Qi9AAAss X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Roberto Sassu Instead of making changes to the system, use in-place built fsverity binary by adding ../fsverity-utils to the PATH variable, so that the binary can be found with the 'command -v' command. Don't delete the fsverity-utils directory, so that the built binary is available. Not deleting should not be a problem, as the script is meant to be executed in a CI environment, where cleanup is done by the CI infrastructure itself. Signed-off-by: Roberto Sassu Reviewed-by: Stefan Berger --- tests/fsverity.test | 2 +- tests/install-fsverity.sh | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/fsverity.test b/tests/fsverity.test index 8261de4ea3c9..01d5c3516631 100755 --- a/tests/fsverity.test +++ b/tests/fsverity.test @@ -30,7 +30,7 @@ # custom policy rules might take precedence. cd "$(dirname "$0")" || exit 1 -PATH=../src:$PATH +PATH=../src:../fsverity-utils:$PATH source ./functions.sh # Base VERBOSE on the environment variable, if set. diff --git a/tests/install-fsverity.sh b/tests/install-fsverity.sh index 418fc42f472b..8311bc023915 100755 --- a/tests/install-fsverity.sh +++ b/tests/install-fsverity.sh @@ -2,6 +2,5 @@ git clone https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/fsverity-utils.git cd fsverity-utils -CC=gcc make -j$(nproc) && sudo make install +CC=gcc make -j$(nproc) cd .. -rm -rf fsverity-utils From patchwork Thu Jan 26 13:58:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roberto Sassu X-Patchwork-Id: 13117160 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E13B6C54E94 for ; Thu, 26 Jan 2023 14:00:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231633AbjAZOAK (ORCPT ); Thu, 26 Jan 2023 09:00:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231971AbjAZN75 (ORCPT ); Thu, 26 Jan 2023 08:59:57 -0500 Received: from frasgout11.his.huawei.com (frasgout11.his.huawei.com [14.137.139.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDFBD6DFE8 for ; Thu, 26 Jan 2023 05:59:39 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.227]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4P2hvF3J9hz9xFQP for ; Thu, 26 Jan 2023 21:51:21 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwB39P_4htJj+ajLAA--.553S12; Thu, 26 Jan 2023 14:59:12 +0100 (CET) From: Roberto Sassu To: zohar@linux.ibm.com, dmitry.kasatkin@gmail.com Cc: linux-integrity@vger.kernel.org, vt@altlinux.org, pvorel@suse.cz, stefanb@linux.ibm.com, Roberto Sassu Subject: [PATCH ima-evm-utils v4 10/11] ci: haveged requires EPEL on CentOS stream:8 Date: Thu, 26 Jan 2023 14:58:06 +0100 Message-Id: <20230126135807.1848668-11-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230126135807.1848668-1-roberto.sassu@huaweicloud.com> References: <20230126135807.1848668-1-roberto.sassu@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: LxC2BwB39P_4htJj+ajLAA--.553S12 X-Coremail-Antispam: 1UD129KBjvdXoW7GFyfAF1xKFy7Wry3Ww15Jwb_yoWDGrgE93 yIgr43Ar45Ar13Xr1rCFZYqr4FgrW2gw4Ygw1UXFy3Z347Arn3Kan3uw4vyan5WrWDurZr JF1kJryFkr17WjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUb3xYFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r126s 0DM28IrcIa0xkI8VCY1x0267AKxVW5JVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4AK67xG Y2AK021l84ACjcxK6xIIjxv20xvE14v26r4j6ryUM28EF7xvwVC0I7IYx2IY6xkF7I0E14 v26F4j6r4UJwA2z4x0Y4vEx4A2jsIE14v26r4j6F4UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7 v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF 1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Gr0_Xr1lIx AIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4l IxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvf C2KfnxnUUI43ZEXa7IU13l1DUUUUU== X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAgAJBF1jj4Qi9AABst X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Mimi Zohar The travis "fedora:latest" matrix rule fails due to not finding "haveged". Install "haveged" after enabling EPEL. Fixes: 992f60d573bc ("Add support for creating a new testing environment in functions.sh") Reviewed-by: Stefan Berger Signed-off-by: Mimi Zohar Signed-off-by: Roberto Sassu --- ci/fedora.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ci/fedora.sh b/ci/fedora.sh index 3f75d2e1ddbd..1d17c6bfb89d 100755 --- a/ci/fedora.sh +++ b/ci/fedora.sh @@ -46,7 +46,6 @@ yum -y install \ wget \ which \ zstd \ - haveged \ systemd \ keyutils \ e2fsprogs \ @@ -62,5 +61,8 @@ if [ -f /etc/centos-release ]; then fi yum -y install softhsm || true +# haveged is available via EPEL on CentOS stream8. +yum -y install haveged || true + ./tests/install-fsverity.sh ./tests/install-mount-idmapped.sh From patchwork Thu Jan 26 13:58:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roberto Sassu X-Patchwork-Id: 13117158 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5230EC61DA2 for ; Thu, 26 Jan 2023 14:00:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231512AbjAZOAJ (ORCPT ); Thu, 26 Jan 2023 09:00:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232096AbjAZOAE (ORCPT ); Thu, 26 Jan 2023 09:00:04 -0500 Received: from frasgout11.his.huawei.com (frasgout11.his.huawei.com [14.137.139.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1542C6FD14 for ; Thu, 26 Jan 2023 05:59:45 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.227]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4P2hvK6Dc7z9xFQZ for ; Thu, 26 Jan 2023 21:51:25 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwB39P_4htJj+ajLAA--.553S13; Thu, 26 Jan 2023 14:59:16 +0100 (CET) From: Roberto Sassu To: zohar@linux.ibm.com, dmitry.kasatkin@gmail.com Cc: linux-integrity@vger.kernel.org, vt@altlinux.org, pvorel@suse.cz, stefanb@linux.ibm.com, Roberto Sassu Subject: [PATCH ima-evm-utils v4 11/11] Temporarily remove CONFIG_DEBUG_SG to test portable signatures Date: Thu, 26 Jan 2023 14:58:07 +0100 Message-Id: <20230126135807.1848668-12-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230126135807.1848668-1-roberto.sassu@huaweicloud.com> References: <20230126135807.1848668-1-roberto.sassu@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: LxC2BwB39P_4htJj+ajLAA--.553S13 X-Coremail-Antispam: 1UD129KBjvdXoW7Xr4fWw18ur1DXw18Xw45trb_yoW3Awb_Jr 4rCw1Iqr4UJr429F4xu3yfX34vya4kXryrWa1UKFy3WF47KrsFgFs5GF15Aws8Ww1UWrWj va1rAF9akr10qjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUb3xYFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r126s 0DM28IrcIa0xkI8VCY1x0267AKxVW5JVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4AK67xG Y2AK021l84ACjcxK6xIIjxv20xvE14v26r4j6ryUM28EF7xvwVC0I7IYx2IY6xkF7I0E14 v26F4j6r4UJwA2z4x0Y4vEx4A2jsIE14v26r4j6F4UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7 v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF 1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Gr0_Xr1lIx AIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4l IxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvf C2KfnxnUUI43ZEXa7IU13l1DUUUUU== X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAgAJBF1jj4Qi9AACsu X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Mimi Zohar Enabling CONFIG_DEBUG_SG requires two kernel fixes. For now don't enable CONFIG_DEBUG_SG. Fixes: 8f965b18d96f ("Add kernel configuration for tests") Signed-off-by: Mimi Zohar Signed-off-by: Roberto Sassu --- kernel-configs/base | 1 - 1 file changed, 1 deletion(-) diff --git a/kernel-configs/base b/kernel-configs/base index 28ae51026399..7acbd5b3b2a6 100644 --- a/kernel-configs/base +++ b/kernel-configs/base @@ -192,7 +192,6 @@ CONFIG_TRACE_IRQFLAGS=y CONFIG_DEBUG_IRQFLAGS=y CONFIG_DEBUG_LIST=y CONFIG_DEBUG_PLIST=y -CONFIG_DEBUG_SG=y CONFIG_DEBUG_NOTIFIERS=y CONFIG_BUG_ON_DATA_CORRUPTION=y CONFIG_PROVE_RCU=y