From patchwork Wed Jul 15 21:39:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruno Meneguele X-Patchwork-Id: 11666311 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B9A7E618 for ; Wed, 15 Jul 2020 21:39:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9A1F3207DD for ; Wed, 15 Jul 2020 21:39:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TUdq+eo8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726370AbgGOVjV (ORCPT ); Wed, 15 Jul 2020 17:39:21 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:59344 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726736AbgGOVjU (ORCPT ); Wed, 15 Jul 2020 17:39:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594849159; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0L3R6uEM0PMypzTypDqa6brvazZbp5wwZJ9AdtjT1wU=; b=TUdq+eo8GfN2bdDYLJwtsPJXeAZPEvk0S+humzYIlZSgFMdSSBAkMvc4lYPi+7mu/1EUCN AerNhQ3yitltRjP6Xn9pgTPDyJgtaBsyIpHNJiOufi51xuz4x4WwKYezuwLe3WFkJmHVci HmCgS8OarKH0m4NToJ5nRUtQpTzT3Mw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-124-QPMPFebNN-2zT6xsDyDxAQ-1; Wed, 15 Jul 2020 17:39:17 -0400 X-MC-Unique: QPMPFebNN-2zT6xsDyDxAQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BE1FD800400; Wed, 15 Jul 2020 21:39:16 +0000 (UTC) Received: from localhost (ovpn-116-38.gru2.redhat.com [10.97.116.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9EE981757A; Wed, 15 Jul 2020 21:39:13 +0000 (UTC) From: Bruno Meneguele To: linux-integrity@vger.kernel.org Cc: Mimi Zohar , Petr Vorel , Vitaly Chikunov , Bruno Meneguele Subject: [PATCH 1/3] ima-evm-utils: fix empty label at end of function. Date: Wed, 15 Jul 2020 18:39:04 -0300 Message-Id: <20200715213906.194041-2-bmeneg@redhat.com> In-Reply-To: <20200715213906.194041-1-bmeneg@redhat.com> References: <20200715213906.194041-1-bmeneg@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Distros running older OpenSSL versions (<= 1.1) fail to build due to the empty label at the end of calc_bootaggr(). For these, that label is no-op. Signed-off-by: Bruno Meneguele --- src/evmctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/evmctl.c b/src/evmctl.c index 90a3eeb..d974ba6 100644 --- a/src/evmctl.c +++ b/src/evmctl.c @@ -2167,7 +2167,7 @@ out: #if OPENSSL_VERSION_NUMBER >= 0x10100000 EVP_MD_CTX_free(pctx); #endif - + return; } /* From patchwork Wed Jul 15 21:39:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruno Meneguele X-Patchwork-Id: 11666313 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 753A213B6 for ; Wed, 15 Jul 2020 21:39:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 56140207CB for ; Wed, 15 Jul 2020 21:39:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FTF8iuEP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726736AbgGOVjX (ORCPT ); Wed, 15 Jul 2020 17:39:23 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:37677 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726479AbgGOVjW (ORCPT ); Wed, 15 Jul 2020 17:39:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594849161; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9GrxYDQymSUTUExdcHo8UnPT4Tg+lIHrVDIxKR9A+1M=; b=FTF8iuEPh5sGLznbQriAjQ1lnYbwE8keMh4kZJii9jRanCQZPJRi9EQF0xR/2SUlPvahkc F2i8ieNE9KYsn/Zb9WUpv4OhZzyR7PIC/S+a3cQJIJ95hf/H2idNjv/k/kRDoGAIdvOfo/ vqvLKeaLrQS4KHgWBtXgoq3TLpUD4oA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-406-3fMB8tkbPyuZ21w1LEUmHQ-1; Wed, 15 Jul 2020 17:39:19 -0400 X-MC-Unique: 3fMB8tkbPyuZ21w1LEUmHQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9939E18FF662; Wed, 15 Jul 2020 21:39:18 +0000 (UTC) Received: from localhost (ovpn-116-38.gru2.redhat.com [10.97.116.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2EBC15FC38; Wed, 15 Jul 2020 21:39:17 +0000 (UTC) From: Bruno Meneguele To: linux-integrity@vger.kernel.org Cc: Mimi Zohar , Petr Vorel , Vitaly Chikunov , Bruno Meneguele Subject: [PATCH 2/3] ima-evm-utils: fix memory leak in case of error Date: Wed, 15 Jul 2020 18:39:05 -0300 Message-Id: <20200715213906.194041-3-bmeneg@redhat.com> In-Reply-To: <20200715213906.194041-1-bmeneg@redhat.com> References: <20200715213906.194041-1-bmeneg@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org OpenSSL context should be freed in case of versions >= 1.1 before leaving the function in case EVP_DigestUpdate() returns any error. Signed-off-by: Bruno Meneguele --- src/evmctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/evmctl.c b/src/evmctl.c index d974ba6..2f5bd52 100644 --- a/src/evmctl.c +++ b/src/evmctl.c @@ -2143,7 +2143,7 @@ static void calc_bootaggr(struct tpm_bank_info *bank) err = EVP_DigestUpdate(pctx, bank->pcr[i], bank->digest_size); if (!err) { log_err("EVP_DigestUpdate() failed\n"); - return; + goto out; } } @@ -2152,7 +2152,7 @@ static void calc_bootaggr(struct tpm_bank_info *bank) err = EVP_DigestUpdate(pctx, bank->pcr[i], bank->digest_size); if (!err) { log_err("EVP_DigestUpdate() failed\n"); - return; + goto out; } } } From patchwork Wed Jul 15 21:39:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruno Meneguele X-Patchwork-Id: 11666315 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 88F5613B6 for ; Wed, 15 Jul 2020 21:39:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67BFA20787 for ; Wed, 15 Jul 2020 21:39:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IDrw5a8H" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726356AbgGOVj1 (ORCPT ); Wed, 15 Jul 2020 17:39:27 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:29770 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726479AbgGOVj0 (ORCPT ); Wed, 15 Jul 2020 17:39:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594849165; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qYV4+3cWAQVPGT7D9RrqoWjj3dpFkmnc31u6srYm/pI=; b=IDrw5a8Hsks5Exjzj4nRzcXsIJrMgr7pQsK0qUjodTWlWZyhf6FtO1lVX7TbLhqelURvUo wn5j4oSQPirsF80JBagMKz6GdJxgQ/SPudWR3jpiBuCz7m1t2NwU5Wd0loCBucgNfdQlWi bioUb7y8Tr9aFQrsc/vkzc8OqwI14ug= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-88-XfEArMf8MfO3kx9rYGzxyw-1; Wed, 15 Jul 2020 17:39:24 -0400 X-MC-Unique: XfEArMf8MfO3kx9rYGzxyw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0B1C01083; Wed, 15 Jul 2020 21:39:23 +0000 (UTC) Received: from localhost (ovpn-116-38.gru2.redhat.com [10.97.116.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB8536FDD1; Wed, 15 Jul 2020 21:39:19 +0000 (UTC) From: Bruno Meneguele To: linux-integrity@vger.kernel.org Cc: Mimi Zohar , Petr Vorel , Vitaly Chikunov , Bruno Meneguele Subject: [PATCH 3/3] ima-evm-utils: fix overflow on printing boot_aggregate Date: Wed, 15 Jul 2020 18:39:06 -0300 Message-Id: <20200715213906.194041-4-bmeneg@redhat.com> In-Reply-To: <20200715213906.194041-1-bmeneg@redhat.com> References: <20200715213906.194041-1-bmeneg@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org There was no room for placing the '\0' at the end of boot_aggregate value, thus printf() was reading 1 byte beyond the array limit. Signed-off-by: Bruno Meneguele --- src/evmctl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/evmctl.c b/src/evmctl.c index 2f5bd52..2bd37c2 100644 --- a/src/evmctl.c +++ b/src/evmctl.c @@ -2252,7 +2252,8 @@ static int cmd_ima_bootaggr(struct command *cmd) bootaggr_len += strlen(tpm_banks[i].algo_name) + 1; bootaggr_len += (tpm_banks[i].digest_size * 2) + 1; } - bootaggr = malloc(bootaggr_len); + /* Make room for the leading \0 */ + bootaggr = malloc(bootaggr_len + 1); /* * Calculate and convert the per TPM 2.0 PCR bank algorithm @@ -2266,6 +2267,7 @@ static int cmd_ima_bootaggr(struct command *cmd) calc_bootaggr(&tpm_banks[i]); offset += append_bootaggr(bootaggr + offset, tpm_banks + i); } + bootaggr[bootaggr_len] = '\0'; printf("%s", bootaggr); free(bootaggr); return 0;