From patchwork Tue Mar 21 16:47:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roberto Sassu X-Patchwork-Id: 13182945 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 606A3C74A5B for ; Tue, 21 Mar 2023 16:48:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229917AbjCUQsH (ORCPT ); Tue, 21 Mar 2023 12:48:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229782AbjCUQsG (ORCPT ); Tue, 21 Mar 2023 12:48:06 -0400 Received: from frasgout12.his.huawei.com (frasgout12.his.huawei.com [14.137.139.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D10140EB for ; Tue, 21 Mar 2023 09:48:04 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.18.147.227]) by frasgout12.his.huawei.com (SkyGuard) with ESMTP id 4Pgy326MQRz9v7Hg for ; Wed, 22 Mar 2023 00:38:22 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwA3vAex3xlkF9a5AQ--.2588S2; Tue, 21 Mar 2023 17:47: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] Include the filesystem UUID in HMAC calculation Date: Tue, 21 Mar 2023 17:47:41 +0100 Message-Id: <20230321164741.680916-1-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1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imRUUUUUU== X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAgADBF1jj4bLDAAAs1 X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Roberto Sassu Modify calc_evm_hmac() to include, similarly to calc_evm_hash(), the filesystem UUID in the HMAC calculation. If the -u option is not specified in the evmctl command line, the UUID of the filesystem the input file resides on is taken for the calculation. If a string is specified as a value for the -u option, that string is taken as UUID (assuming that it is formatted correctly). If no value is specified for the -u option, the filesystem UUID is not included in the HMAC calculation. Not including the filesystem UUID in the digest/HMAC calculation is needed for the case where the kernel is compiled with CONFIG_EVM_ATTR_FSUUID=n, or the digest/HMAC is not for an EVM portable signature. Signed-off-by: Roberto Sassu --- src/evmctl.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/evmctl.c b/src/evmctl.c index 6d2bb67427d..304b70de40f 100644 --- a/src/evmctl.c +++ b/src/evmctl.c @@ -1199,6 +1199,7 @@ static int calc_evm_hmac(const char *file, const char *keyfile, unsigned char *s int keylen; unsigned char evmkey[MAX_KEY_SIZE]; char list[1024]; + char uuid[16]; ssize_t list_size; struct h_misc_64 hmac_misc; int hmac_size; @@ -1330,6 +1331,18 @@ static int calc_evm_hmac(const char *file, const char *keyfile, unsigned char *s log_err("EVP_DigestSignUpdate() failed\n"); goto out_ctx_cleanup; } + if (!(hmac_flags & HMAC_FLAG_NO_UUID)) { + err = get_uuid(&st, uuid); + if (err) + goto out_ctx_cleanup; + + err = EVP_DigestSignUpdate(pctx, (const unsigned char *)uuid, + sizeof(uuid)); + if (!err) { + log_err("EVP_DigestSignUpdate() failed\n"); + goto out_ctx_cleanup; + } + } err = EVP_DigestSignFinal(pctx, sig, &siglen); if (err != 1) log_err("EVP_DigestSignFinal() failed\n");