From patchwork Thu Apr 19 19:54:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 10351497 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1D1BF6053F for ; Thu, 19 Apr 2018 19:55:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F43C284C9 for ; Thu, 19 Apr 2018 19:55:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03DC328515; Thu, 19 Apr 2018 19:55:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95C7628503 for ; Thu, 19 Apr 2018 19:55:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753495AbeDSTz3 (ORCPT ); Thu, 19 Apr 2018 15:55:29 -0400 Received: from mx2.suse.de ([195.135.220.15]:38430 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752558AbeDSTz3 (ORCPT ); Thu, 19 Apr 2018 15:55:29 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 13E7EAEB2; Thu, 19 Apr 2018 19:55:28 +0000 (UTC) From: Petr Vorel To: ltp@lists.linux.it Cc: Petr Vorel , Mimi Zohar , linux-integrity@vger.kernel.org Subject: [RFC PATCH v3 05/10] ima/ima_boot_aggregate: Increase MAX_EVENT_SIZE to 1MB Date: Thu, 19 Apr 2018 21:54:58 +0200 Message-Id: <20180419195503.7194-6-pvorel@suse.cz> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180419195503.7194-1-pvorel@suse.cz> References: <20180419195503.7194-1-pvorel@suse.cz> Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is needed as according IMA developers there are BIOS events larger than 4k [1]. Actual size for TPM 1.2 is undefined, TPM 2.0 specifies: "For software parsing the event log, the parser can choose an arbitrary maximum size, but this specification recommends a maximum value for the TCG_PCR_EVENT2.eventSize field of 1MB." [2]. So lets follow the specification and allocate 1MB. [1] http://lists.linux.it/pipermail/ltp/2018-January/006970.html [2] http://lists.linux.it/pipermail/ltp/2018-January/007002.html Suggested-by: George Wilson Signed-off-by: Petr Vorel --- .../security/integrity/ima/src/ima_boot_aggregate.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/testcases/kernel/security/integrity/ima/src/ima_boot_aggregate.c b/testcases/kernel/security/integrity/ima/src/ima_boot_aggregate.c index f7ae77cb1..862cc07ba 100644 --- a/testcases/kernel/security/integrity/ima/src/ima_boot_aggregate.c +++ b/testcases/kernel/security/integrity/ima/src/ima_boot_aggregate.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "config.h" #include "test.h" @@ -30,7 +31,7 @@ char *TCID = "ima_boot_aggregate"; #if HAVE_LIBCRYPTO #include -#define MAX_EVENT_SIZE 500 +#define MAX_EVENT_SIZE (1024*1024) #define EVENT_HEADER_SIZE 32 #define MAX_EVENT_DATA_SIZE (MAX_EVENT_SIZE - EVENT_HEADER_SIZE) #define NUM_PCRS 8 /* PCR registers 0-7 in boot aggregate */ @@ -56,7 +57,7 @@ int main(int argc, char *argv[]) unsigned char digest[SHA_DIGEST_LENGTH]; u_int16_t len; } header; - unsigned char data[MAX_EVENT_DATA_SIZE]; + char *data; } event; struct { unsigned char digest[SHA_DIGEST_LENGTH]; @@ -80,6 +81,12 @@ int main(int argc, char *argv[]) for (i = 0; i < NUM_PCRS; i++) memset(&pcr[i].digest, 0, SHA_DIGEST_LENGTH); + event.data = (char *) malloc(MAX_EVENT_DATA_SIZE); + if (!event.data) { + printf("Cannot allocate memory\n"); + return 1; + } + /* Extend the pseudo PCRs with the event digest */ while (fread(&event, sizeof(event.header), 1, fp)) { if (debug) { @@ -90,13 +97,16 @@ int main(int argc, char *argv[]) SHA1_Update(&c, pcr[event.header.pcr].digest, 20); SHA1_Update(&c, event.header.digest, 20); SHA1_Final(pcr[event.header.pcr].digest, &c); +#if MAX_EVENT_DATA_SIZE < USHRT_MAX if (event.header.len > MAX_EVENT_DATA_SIZE) { - printf("Error event too long"); + printf("Error event too long\n"); break; } +#endif fread(event.data, event.header.len, 1, fp); } fclose(fp); + free(event.data); /* Extend the boot aggregate with the pseudo PCR digest values */ memset(&boot_aggregate, 0, SHA_DIGEST_LENGTH);