From patchwork Wed Sep 14 14:22:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mimi Zohar X-Patchwork-Id: 12976221 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 DAAE7C6FA82 for ; Wed, 14 Sep 2022 14:22:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229539AbiINOWl (ORCPT ); Wed, 14 Sep 2022 10:22:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229499AbiINOWj (ORCPT ); Wed, 14 Sep 2022 10:22:39 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 636A946638 for ; Wed, 14 Sep 2022 07:22:38 -0700 (PDT) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28EED9n2000799; Wed, 14 Sep 2022 14:22:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=8xSHguEJXQPshTPlOLP4rennnQLUA7tF9N5HidlCUTc=; b=RpavyJBuVf/dFoTgpJsbB/rL1IovEIz/jv41Iy5yDvSHcmczj8rT8PmREWG0c7jIEwPU Zpc/0qutwecOhPprqnqfqKAUdjPA5BgvUIsig/Af8URPLUK2eORh+RubeO+qluLon6Zm ru2BPLJiEw4XrJQhp1PDAVVWB+TgWiUIGVPLXTIAXVy9rTKm222kJiXx9Qi84LozkX5e xUOsybQy5228Q2gUTtV9VomU++gZ2v3kpYrP1H1ylreG8qtkNvyLUTMPKiu3qE1GZt60 ymWN14YiRlQVcXEZ7i6uPJIEr6lrQA0F876YvWRglD52oSJqomkwoe65SLJCNgc5mK2P kQ== Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3jkgh9gadu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Sep 2022 14:22:35 +0000 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28EEKATY031770; Wed, 14 Sep 2022 14:22:34 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma02fra.de.ibm.com with ESMTP id 3jjyk6rtvc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Sep 2022 14:22:33 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28EEMURa38535584 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 14 Sep 2022 14:22:30 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BAA685204F; Wed, 14 Sep 2022 14:22:30 +0000 (GMT) Received: from li-f45666cc-3089-11b2-a85c-c57d1a57929f.ibm.com.com (unknown [9.65.200.242]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 21E065204E; Wed, 14 Sep 2022 14:22:30 +0000 (GMT) From: Mimi Zohar To: linux-integrity@vger.kernel.org Cc: Mimi Zohar , Petr Vorel , Stefan Berger Subject: [PATCH ima-evm-utils 1/4] Don't ignore number of items read Date: Wed, 14 Sep 2022 10:22:22 -0400 Message-Id: <20220914142225.1381077-2-zohar@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220914142225.1381077-1-zohar@linux.ibm.com> References: <20220914142225.1381077-1-zohar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: IGIQ2RkhFU_oQSFVqYhPc6WyqjihSnkz X-Proofpoint-ORIG-GUID: IGIQ2RkhFU_oQSFVqYhPc6WyqjihSnkz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-14_06,2022-09-14_04,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 malwarescore=0 phishscore=0 lowpriorityscore=0 mlxscore=0 adultscore=0 mlxlogscore=941 impostorscore=0 clxscore=1015 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2208220000 definitions=main-2209140068 Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org fread() either returns the number of bytes read or the number of items of data read. Check that it returns the requested number of items read. Signed-off-by: Mimi Zohar Reviewed-by: Stefan Berger --- src/evmctl.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/evmctl.c b/src/evmctl.c index 2e21da67c444..bcf724c828f7 100644 --- a/src/evmctl.c +++ b/src/evmctl.c @@ -2161,7 +2161,7 @@ static int ima_measurement(const char *file) } memset(entry.name, 0x00, sizeof(entry.name)); - if (!fread(entry.name, entry.header.name_len, 1, fp)) { + if (fread(entry.name, entry.header.name_len, 1, fp) != 1) { log_err("Unable to read template name\n"); goto out; } @@ -2184,8 +2184,8 @@ static int ima_measurement(const char *file) /* The "ima" template data is not length prefixed. Skip it. */ if (!is_ima_template) { - if (!fread(&entry.template_len, - sizeof(entry.template_len), 1, fp)) { + if (fread(&entry.template_len, + sizeof(entry.template_len), 1, fp) != 1) { log_err("Unable to read template length\n"); goto out; } @@ -2205,7 +2205,8 @@ static int ima_measurement(const char *file) } if (!is_ima_template) { - if (!fread(entry.template, entry.template_len, 1, fp)) { + if (fread(entry.template, entry.template_len, + 1, fp) != 1) { log_errno("Unable to read template\n"); goto out; } @@ -2217,7 +2218,8 @@ static int ima_measurement(const char *file) * The "ima" template data format is digest, * filename length, filename. */ - if (!fread(entry.template, SHA_DIGEST_LENGTH, 1, fp)) { + if (fread(entry.template, SHA_DIGEST_LENGTH, + 1, fp) != 1) { log_errno("Unable to read file data hash\n"); goto out; } From patchwork Wed Sep 14 14:22:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mimi Zohar X-Patchwork-Id: 12976222 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 AB364C6FA8A for ; Wed, 14 Sep 2022 14:22:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229499AbiINOWl (ORCPT ); Wed, 14 Sep 2022 10:22:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229523AbiINOWk (ORCPT ); Wed, 14 Sep 2022 10:22:40 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 375454662E for ; Wed, 14 Sep 2022 07:22:40 -0700 (PDT) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28EDcKoY001958; Wed, 14 Sep 2022 14:22:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=LODsS5t7h/+tzVHK/nhlYnXa40qU63cMZFpFgldEKaI=; b=kC+3c6g6d3xtIp1vrSM86jfYzH/ucDjHsgd0TNPwKgv6JehjIkHaxh/NYluNN8u+0eX5 zhpGjM+Em0Jrel/G6cqZQZ0szxjOe57vKUfOiPkbbVdcN5pk5FaBBcaNE+aClX2afjgk 3+iT9HLsXPDM7/5G9us0zvf7My/RnEZQriZXyt1kYK2KOIFAzuu+/uzm2e8CTrMlbWAW fniHBwhYj5l57T3Ip1I3/+Aeegpq1UDGSjvSOALKNoSeAAoO5ibwsQQ+KxyQ6zsmMXcR X6ke+OPe8hjxAfmM35lPs9PIXl49pD86EiE7sVwDLawNFljXrOjESmOr6vsh+Rz8dpyQ 4w== Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jkfmpjnb8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Sep 2022 14:22:37 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28EEKdYe021418; Wed, 14 Sep 2022 14:22:34 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04ams.nl.ibm.com with ESMTP id 3jjytx1398-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Sep 2022 14:22:34 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28EEMVc435193200 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 14 Sep 2022 14:22:31 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8181152050; Wed, 14 Sep 2022 14:22:31 +0000 (GMT) Received: from li-f45666cc-3089-11b2-a85c-c57d1a57929f.ibm.com.com (unknown [9.65.200.242]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id DF48A5204E; Wed, 14 Sep 2022 14:22:30 +0000 (GMT) From: Mimi Zohar To: linux-integrity@vger.kernel.org Cc: Mimi Zohar , Petr Vorel , Stefan Berger Subject: [PATCH ima-evm-utils 2/4] Define and verify the template data length upper bounds Date: Wed, 14 Sep 2022 10:22:23 -0400 Message-Id: <20220914142225.1381077-3-zohar@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220914142225.1381077-1-zohar@linux.ibm.com> References: <20220914142225.1381077-1-zohar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 3s34ebS-gDo6LP11VQs57o1V6PrOdaGh X-Proofpoint-GUID: 3s34ebS-gDo6LP11VQs57o1V6PrOdaGh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-14_06,2022-09-14_04,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 spamscore=0 malwarescore=0 priorityscore=1501 bulkscore=0 mlxscore=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=999 phishscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2208220000 definitions=main-2209140068 Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org The template data length is variable, based on the template format. Define some sort of upper bounds. Signed-off-by: Mimi Zohar Reviewed-by: Stefan Berger --- src/evmctl.c | 3 ++- src/imaevm.h | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/evmctl.c b/src/evmctl.c index bcf724c828f7..9ab804fee37a 100644 --- a/src/evmctl.c +++ b/src/evmctl.c @@ -2189,7 +2189,8 @@ static int ima_measurement(const char *file) log_err("Unable to read template length\n"); goto out; } - if (entry.template_len == 0) { + if (entry.template_len == 0 || + entry.template_len > MAX_TEMPLATE_SIZE) { log_err("Invalid template data len\n"); goto out; } diff --git a/src/imaevm.h b/src/imaevm.h index 8114bd051514..c43312d01dec 100644 --- a/src/imaevm.h +++ b/src/imaevm.h @@ -91,6 +91,16 @@ #define MAX_DIGEST_SIZE 64 #define MAX_SIGNATURE_SIZE 1024 +/* + * The maximum template data size is dependent on the template format. For + * example the 'ima-modsig' template includes two signatures - one for the + * entire file, the other without the appended signature - and other fields + * (e.g. file digest, file name, file digest without the appended signature). + * + * Other template formats are much smaller. + */ +#define MAX_TEMPLATE_SIZE (MAX_SIGNATURE_SIZE * 4) + #define __packed __attribute__((packed)) enum evm_ima_xattr_type { From patchwork Wed Sep 14 14:22:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mimi Zohar X-Patchwork-Id: 12976224 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 96F17ECAAD3 for ; Wed, 14 Sep 2022 14:22:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229523AbiINOWo (ORCPT ); Wed, 14 Sep 2022 10:22:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229634AbiINOWn (ORCPT ); Wed, 14 Sep 2022 10:22:43 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4F0246638 for ; Wed, 14 Sep 2022 07:22:40 -0700 (PDT) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28EDIxsI029338; Wed, 14 Sep 2022 14:22:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=eBEWFzlKnohU2rGR/5DbGOVVqpYSwven9lDXVL5UxXo=; b=VyEyQ38mtq+COAwGT4JOF6IqV1RCDWDhKptGoHrCbVCNJBdULstXsWIxE2mDEbbURhoV zgS1FvaTR4+3cOrwH7bX9xZ0lc69HZZPNcGgCEPB+mUX44ElyEdIBTD/ZO7FsakZxTgF pCNpXi3DMMXz8liNFpC8Djdjkxm7xy+sdorF0VP7al6Gb0u8qg6+862uYHSh5KoeI6sv 9/AtTUD4cAGYR4HWP2tzCy9m3xlUplLANIZRfO9qRrEKspJHhnFy+fn1Ji8/Sw1uvUBV mbt8FfpCjAn2a06PhZYK0hU5/b1Xp4AKgyifhSBSCeqhhMgWUGDFauMX1vEXq/tIIthZ /g== Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jkfqytj5e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Sep 2022 14:22:37 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28EEKqgw021851; Wed, 14 Sep 2022 14:22:35 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma06ams.nl.ibm.com with ESMTP id 3jjyfr93vk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Sep 2022 14:22:35 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28EEMWwe27787758 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 14 Sep 2022 14:22:32 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4BF955204E; Wed, 14 Sep 2022 14:22:32 +0000 (GMT) Received: from li-f45666cc-3089-11b2-a85c-c57d1a57929f.ibm.com.com (unknown [9.65.200.242]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id A756E52050; Wed, 14 Sep 2022 14:22:31 +0000 (GMT) From: Mimi Zohar To: linux-integrity@vger.kernel.org Cc: Mimi Zohar , Petr Vorel , Stefan Berger Subject: [PATCH ima-evm-utils 3/4] Sanity check the template data field sizes Date: Wed, 14 Sep 2022 10:22:24 -0400 Message-Id: <20220914142225.1381077-4-zohar@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220914142225.1381077-1-zohar@linux.ibm.com> References: <20220914142225.1381077-1-zohar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: sPh5aFTjhXfYudbqcxR2hxpR5AZZ0wTh X-Proofpoint-ORIG-GUID: sPh5aFTjhXfYudbqcxR2hxpR5AZZ0wTh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-14_06,2022-09-14_04,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 lowpriorityscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 spamscore=0 priorityscore=1501 bulkscore=0 adultscore=0 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2208220000 definitions=main-2209140068 Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org The field sizes of the original "ima" template data are static, but the other template data fields are not. They're prefixed with a size. Add some data field size sanity checks in ima_show_ng(). Signed-off-by: Mimi Zohar Reviewed-by: Stefan Berger --- src/evmctl.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/evmctl.c b/src/evmctl.c index 9ab804fee37a..4a071143679e 100644 --- a/src/evmctl.c +++ b/src/evmctl.c @@ -1591,8 +1591,9 @@ void ima_ng_show(struct template_entry *entry) { uint8_t *fieldp = entry->template; uint32_t field_len; - int total_len = entry->template_len, digest_len, len, sig_len, fbuf_len; + int total_len = entry->template_len, digest_len, len, fbuf_len; uint8_t *digest, *sig = NULL, *fbuf = NULL; + int sig_len = 0; char *algo, *path; int found; int err; @@ -1601,33 +1602,65 @@ void ima_ng_show(struct template_entry *entry) field_len = *(uint32_t *)fieldp; fieldp += sizeof(field_len); total_len -= sizeof(field_len); + if (total_len < 0) { + log_err("Template \"%s\" invalid template data\n", entry->name); + return; + } algo = (char *)fieldp; len = strnlen(algo, field_len - 1) + 1; digest_len = field_len - len; + if (digest_len < SHA_DIGEST_LENGTH || + digest_len > MAX_DIGEST_SIZE) { + log_err("Template \"%s\" invalid digest length\n", entry->name); + return; + } digest = fieldp + len; /* move to next field */ fieldp += field_len; total_len -= field_len; + if (total_len < 0) { + log_err("Template \"%s\" invalid template data\n", entry->name); + return; + } /* get path */ field_len = *(uint32_t *)fieldp; fieldp += sizeof(field_len); total_len -= sizeof(field_len); + if (field_len == 0 || field_len > PATH_MAX || total_len < field_len) { + log_err("Template \"%s\" invalid file pathname\n", entry->name); + return; + } path = (char *)fieldp; /* move to next field */ fieldp += field_len; total_len -= field_len; + if (total_len < 0) { + log_err("Template \"%s\" invalid template data\n", entry->name); + return; + } if (!strcmp(entry->name, "ima-sig") || !strcmp(entry->name, "ima-sigv2")) { - /* get signature */ + /* get signature, if it exists */ field_len = *(uint32_t *)fieldp; fieldp += sizeof(field_len); + if (field_len > MAX_SIGNATURE_SIZE) { + log_err("Template \"%s\" invalid file signature size\n", + entry->name); + return; + } + total_len -= sizeof(field_len); + if (total_len < 0) { + log_err("Template \"%s\" invalid template data\n", + entry->name); + return; + } if (field_len) { sig = fieldp; @@ -1651,6 +1684,11 @@ void ima_ng_show(struct template_entry *entry) } } + if (total_len < 0) { + log_err("Template \"%s\" invalid template data\n", entry->name); + return; + } + /* ascii_runtime_measurements */ if (imaevm_params.verbose > LOG_INFO) { log_info("%d ", entry->header.pcr); From patchwork Wed Sep 14 14:22:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mimi Zohar X-Patchwork-Id: 12976223 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 B0976C6FA82 for ; Wed, 14 Sep 2022 14:22:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229564AbiINOWn (ORCPT ); Wed, 14 Sep 2022 10:22:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229590AbiINOWn (ORCPT ); Wed, 14 Sep 2022 10:22:43 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C41F4662E for ; Wed, 14 Sep 2022 07:22:42 -0700 (PDT) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28EDfYpl023820; Wed, 14 Sep 2022 14:22:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=5GFYGTnCZR9y51tprTuyHqbyaph8VTzYqA8AQfuX6Tw=; b=Zi6AVD8iD90y4fzsxlLfi/7vn2rzPYbmQXPT0vmpo0mcOdVAnK5OvhZXlT+R4y2g52Jy DORNlgC/1lloAOIdaj8VJ3caz3uM4T+e/zwduB8FHuJ/ETRLEzNHMwoj5gH3hv8qWjEX HcFLmJlfWJFXd52cbk/zuA8FfbxcLvGK/CVy4c2IXJg/eFHXtp8LmyRfj+27zf0nGORc oqaTxzPshHSa97v5W7otcvQ6RX65iuhLiBvaOTTwkLGvIANBDSd0a18vP2kknvL3Heo8 rJFmCxjUaS/7/EqQzfzlWvupFu+7t98pceQui8SxoZA4eYtJrPGCoQP02PGJgzNA+SXw /A== Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jkg2e1nxs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Sep 2022 14:22:39 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28EEL5rR008617; Wed, 14 Sep 2022 14:22:36 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma05fra.de.ibm.com with ESMTP id 3jjy9a0u1q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Sep 2022 14:22:36 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28EEMXch37224942 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 14 Sep 2022 14:22:33 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 136CB5204E; Wed, 14 Sep 2022 14:22:33 +0000 (GMT) Received: from li-f45666cc-3089-11b2-a85c-c57d1a57929f.ibm.com.com (unknown [9.65.200.242]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 701465204F; Wed, 14 Sep 2022 14:22:32 +0000 (GMT) From: Mimi Zohar To: linux-integrity@vger.kernel.org Cc: Mimi Zohar , Petr Vorel , Stefan Berger Subject: [PATCH ima-evm-utils 4/4] Fix tpm2_pcr_supported() output messages Date: Wed, 14 Sep 2022 10:22:25 -0400 Message-Id: <20220914142225.1381077-5-zohar@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220914142225.1381077-1-zohar@linux.ibm.com> References: <20220914142225.1381077-1-zohar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 7z00Nnxu6Mb-5n0T9GP6jFVJIiMJg3hC X-Proofpoint-ORIG-GUID: 7z00Nnxu6Mb-5n0T9GP6jFVJIiMJg3hC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-14_06,2022-09-14_04,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 mlxlogscore=935 impostorscore=0 lowpriorityscore=0 spamscore=0 bulkscore=0 clxscore=1015 adultscore=0 priorityscore=1501 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2208220000 definitions=main-2209140068 Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Remove unnecessary path check in pcr_ibmtss.c and update the syntax in the other. Signed-off-by: Mimi Zohar Reviewed-by: Stefan Berger --- src/pcr_ibmtss.c | 12 +----------- src/pcr_tsspcrread.c | 4 ++-- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/pcr_ibmtss.c b/src/pcr_ibmtss.c index b8700ddd5da8..6b38d280e80c 100644 --- a/src/pcr_ibmtss.c +++ b/src/pcr_ibmtss.c @@ -20,21 +20,11 @@ #undef MAX_DIGEST_SIZE /* imaevm uses a different value than the TSS */ #include -#define CMD "tsspcrread" - -static char path[PATH_MAX]; - int tpm2_pcr_supported(void) { if (imaevm_params.verbose > LOG_INFO) - log_info("Using %s to read PCRs.\n", CMD); - - if (get_cmd_path(CMD, path, sizeof(path))) { - log_debug("Couldn't find '%s' in $PATH\n", CMD); - return 0; - } + log_info("Using ibmtss to read PCRs.\n"); - log_debug("Found '%s' in $PATH\n", CMD); return 1; } diff --git a/src/pcr_tsspcrread.c b/src/pcr_tsspcrread.c index 95048f8a5469..39ff8f7fc14d 100644 --- a/src/pcr_tsspcrread.c +++ b/src/pcr_tsspcrread.c @@ -60,11 +60,11 @@ int tpm2_pcr_supported(void) log_info("Using %s to read PCRs.\n", CMD); if (get_cmd_path(CMD, path, sizeof(path))) { - log_debug("Couldn't find '%s' in $PATH\n", CMD); + log_info("Couldn't find '%s' in %s\n", CMD, path); return 0; } - log_debug("Found '%s' in $PATH\n", CMD); + log_debug("Found '%s' in %s\n", CMD, path); return 1; }