From patchwork Thu Jul 8 16:04:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 12365617 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2B3AC07E9C for ; Thu, 8 Jul 2021 16:04:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE64361878 for ; Thu, 8 Jul 2021 16:04:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229592AbhGHQG4 (ORCPT ); Thu, 8 Jul 2021 12:06:56 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:28667 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229992AbhGHQGz (ORCPT ); Thu, 8 Jul 2021 12:06:55 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 168G35kG010199 for ; Thu, 8 Jul 2021 12:04:12 -0400 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=OheOjOvjFCHWUFxL8esB+H/tHA6Itrq2T6gbh1QiIU8=; b=OcTjg9h9UuTABDPZbNQyIExHD6bctlJX81QhbpoWZCriB+XiH3ylIfV87aHF6s2GI1r9 gNMGexvCVTQZxuzmk/hNfXYtos8FdvpH8QKodCbHdehrU685bzdTqokjoM9QUzxREt2U xjMpBbjrhYbg7Ol8B59jKzQjHMEjtcd0BztM4FabHmnnKBfZEqcrlR2h5KXGd2RJWLOM Zm3AoHiqEa+NKu6nRoDW6B5TvbFcmBWeNoAvclJ/SiAuAWOvcnyMcmNT4WSCU8jhRAWs lqvC1wPe1taamnzy15B9GgbqXslB/LRnmsWIPIMtoScDCzhC16EkS5Oqmdi/Qypc7gwP UA== Received: from ppma03wdc.us.ibm.com (ba.79.3fa9.ip4.static.sl-reverse.com [169.63.121.186]) by mx0a-001b2d01.pphosted.com with ESMTP id 39p2yf3ecv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 08 Jul 2021 12:04:12 -0400 Received: from pps.filterd (ppma03wdc.us.ibm.com [127.0.0.1]) by ppma03wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 168FvhlS016608 for ; Thu, 8 Jul 2021 16:04:11 GMT Received: from b01cxnp22035.gho.pok.ibm.com (b01cxnp22035.gho.pok.ibm.com [9.57.198.25]) by ppma03wdc.us.ibm.com with ESMTP id 39jfhd79rj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 08 Jul 2021 16:04:11 +0000 Received: from b01ledav002.gho.pok.ibm.com (b01ledav002.gho.pok.ibm.com [9.57.199.107]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 168G4AlJ32244012 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 8 Jul 2021 16:04:10 GMT Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 15BE0124064; Thu, 8 Jul 2021 16:04:10 +0000 (GMT) Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 082EC124062; Thu, 8 Jul 2021 16:04:10 +0000 (GMT) Received: from localhost.localdomain (unknown [9.47.158.155]) by b01ledav002.gho.pok.ibm.com (Postfix) with ESMTP; Thu, 8 Jul 2021 16:04:09 +0000 (GMT) From: Stefan Berger To: linux-integrity@vger.kernel.org Cc: zohar@linux.ibm.com, Stefan Berger Subject: [PATCH ima-evm-utils v2 1/4] evmctl: Remove filtering support for file types unsupported by IMA Date: Thu, 8 Jul 2021 12:04:05 -0400 Message-Id: <20210708160408.2779849-2-stefanb@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210708160408.2779849-1-stefanb@linux.ibm.com> References: <20210708160408.2779849-1-stefanb@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 8upYi8Qw0CeXuPqSzqzQb_mQBtYEDUkR X-Proofpoint-GUID: 8upYi8Qw0CeXuPqSzqzQb_mQBtYEDUkR X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-07-08_09:2021-07-08,2021-07-08 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 bulkscore=0 spamscore=0 priorityscore=1501 clxscore=1015 malwarescore=0 mlxlogscore=999 impostorscore=0 adultscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107080083 Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Remove support for filtering on file types unsupported by IMA from evmctl. This now prevents func(de->d_name) to be invoked on symlinks, block device files, etc. since signature verification on those file types is not supported by IMA in the kernel. Signed-off-by: Stefan Berger --- README | 2 +- src/evmctl.c | 13 +------------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/README b/README index 321045d..2ccac46 100644 --- a/README +++ b/README @@ -51,7 +51,7 @@ OPTIONS -o, --portable generate portable EVM signatures -p, --pass password for encrypted signing key -r, --recursive recurse into directories (sign) - -t, --type file types to fix 'fdsxm' (f: file, d: directory, s: block/char/symlink) + -t, --type file types to fix 'fxm' (f: file) x - skip fixing if both ima and evm xattrs exist (use with caution) m - stay on the same filesystem (like 'find -xdev') -n print result to stdout instead of setting xattr diff --git a/src/evmctl.c b/src/evmctl.c index 7a6f202..04f14af 100644 --- a/src/evmctl.c +++ b/src/evmctl.c @@ -142,10 +142,6 @@ typedef int (*find_cb_t)(const char *path); static int find(const char *path, int dts, find_cb_t func); #define REG_MASK (1 << DT_REG) -#define DIR_MASK (1 << DT_DIR) -#define LNK_MASK (1 << DT_LNK) -#define CHR_MASK (1 << DT_CHR) -#define BLK_MASK (1 << DT_BLK) struct command cmds[]; static void print_usage(struct command *cmd); @@ -668,10 +664,6 @@ static int get_file_type(const char *path, const char *search_type) switch (search_type[i]) { case 'f': dts |= REG_MASK; break; - case 'd': - dts |= DIR_MASK; break; - case 's': - dts |= BLK_MASK | CHR_MASK | LNK_MASK; break; case 'x': check_xattr = true; break; case 'm': @@ -1371,9 +1363,6 @@ static int find(const char *path, int dts, find_cb_t func) return -1; } - if (dts & DIR_MASK) - func(path); - closedir(dir); return 0; @@ -2517,7 +2506,7 @@ static void usage(void) " -o, --portable generate portable EVM signatures\n" " -p, --pass password for encrypted signing key\n" " -r, --recursive recurse into directories (sign)\n" - " -t, --type file types to fix 'fdsxm' (f: file, d: directory, s: block/char/symlink)\n" + " -t, --type file types to fix 'fxm' (f: file)\n" " x - skip fixing if both ima and evm xattrs exist (use with caution)\n" " m - stay on the same filesystem (like 'find -xdev')\n" " -n print result to stdout instead of setting xattr\n" From patchwork Thu Jul 8 16:04:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 12365615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1424C11F66 for ; Thu, 8 Jul 2021 16:04:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AD9106187E for ; Thu, 8 Jul 2021 16:04:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230126AbhGHQGz (ORCPT ); Thu, 8 Jul 2021 12:06:55 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:5629 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229592AbhGHQGz (ORCPT ); Thu, 8 Jul 2021 12:06:55 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 168G2xoq009769 for ; Thu, 8 Jul 2021 12:04:12 -0400 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=NiI+e9gdznPLyTzi0q05yYGC1NGFxJfy3OMiAwXiNU8=; b=WIf/iNItxLV+FGVTDhUD907pdYxQo18syfm5nSrfNLgyKJFuI6/I0ICCDTwLUJc93hjl CJh05vGfw3W4hyIm686ROwXjy1qbmA+XiWER/DphXZ7PNd9ERUAbi6jD/cv/oIpXDz44 l9xnAKPoMxWA5sbexC4+2O2cN4/BiRpzgII/fAsC6CgjbbKir75NfM8xqTrEmxh+emnQ J0oD63wVi8Wn+uD/9iYTZNJdqVlDtqopJrQ6Vr3YslMmKZ+zTCyz5NGC+nqL//KyWbze we2UxJKBYAjiFsuxZuuLNBFtyfShGQZhGibPvlcvB4YE6a5nxbqwrtSwQJqEj2dzGwH4 Iw== Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0a-001b2d01.pphosted.com with ESMTP id 39p2yf3ecs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 08 Jul 2021 12:04:12 -0400 Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 168Fx6ah027125 for ; Thu, 8 Jul 2021 16:04:10 GMT Received: from b01cxnp22035.gho.pok.ibm.com (b01cxnp22035.gho.pok.ibm.com [9.57.198.25]) by ppma05wdc.us.ibm.com with ESMTP id 39jfhd7c8h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 08 Jul 2021 16:04:10 +0000 Received: from b01ledav002.gho.pok.ibm.com (b01ledav002.gho.pok.ibm.com [9.57.199.107]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 168G4ASm37945838 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 8 Jul 2021 16:04:10 GMT Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 326A212406E; Thu, 8 Jul 2021 16:04:10 +0000 (GMT) Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2548512406C; Thu, 8 Jul 2021 16:04:10 +0000 (GMT) Received: from localhost.localdomain (unknown [9.47.158.155]) by b01ledav002.gho.pok.ibm.com (Postfix) with ESMTP; Thu, 8 Jul 2021 16:04:10 +0000 (GMT) From: Stefan Berger To: linux-integrity@vger.kernel.org Cc: zohar@linux.ibm.com, Stefan Berger Subject: [PATCH ima-evm-utils v2 2/4] libimaevm: Remove calculation of a digest over a device file Date: Thu, 8 Jul 2021 12:04:06 -0400 Message-Id: <20210708160408.2779849-3-stefanb@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210708160408.2779849-1-stefanb@linux.ibm.com> References: <20210708160408.2779849-1-stefanb@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: yuT6fdRIDmfJAf9dtitylU3vGsvCgt-C X-Proofpoint-GUID: yuT6fdRIDmfJAf9dtitylU3vGsvCgt-C X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-07-08_09:2021-07-08,2021-07-08 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 bulkscore=0 spamscore=0 priorityscore=1501 clxscore=1015 malwarescore=0 mlxlogscore=999 impostorscore=0 adultscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107080083 Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Signature verification on device files is not supported by IMA in the kernel, so remove calculation of digests over devices files. Signed-off-by: Stefan Berger Reviewed-by: Mimi Zohar --- src/libimaevm.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/libimaevm.c b/src/libimaevm.c index 2856270..4d51901 100644 --- a/src/libimaevm.c +++ b/src/libimaevm.c @@ -225,16 +225,6 @@ static int add_link_hash(const char *path, EVP_MD_CTX *ctx) return !EVP_DigestUpdate(ctx, buf, len); } -static int add_dev_hash(struct stat *st, EVP_MD_CTX *ctx) -{ - uint32_t dev = st->st_rdev; - unsigned major = (dev & 0xfff00) >> 8; - unsigned minor = (dev & 0xff) | ((dev >> 12) & 0xfff00); - - log_info("device: %u:%u\n", major, minor); - return !EVP_DigestUpdate(ctx, &dev, sizeof(dev)); -} - int ima_calc_hash(const char *file, uint8_t *hash) { const EVP_MD *md; @@ -281,10 +271,6 @@ int ima_calc_hash(const char *file, uint8_t *hash) case S_IFLNK: err = add_link_hash(file, pctx); break; - case S_IFIFO: case S_IFSOCK: - case S_IFCHR: case S_IFBLK: - err = add_dev_hash(&st, pctx); - break; default: log_err("Unsupported file type (0x%x)", st.st_mode & S_IFMT); err = -1; From patchwork Thu Jul 8 16:04:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 12365619 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D811DC07E99 for ; Thu, 8 Jul 2021 16:04:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C5E9B61874 for ; Thu, 8 Jul 2021 16:04:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230145AbhGHQG7 (ORCPT ); Thu, 8 Jul 2021 12:06:59 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:14398 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229992AbhGHQG6 (ORCPT ); Thu, 8 Jul 2021 12:06:58 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 168G3kmg075106 for ; Thu, 8 Jul 2021 12:04:17 -0400 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=AF+afRAj6xC18HRymqmCo8vWiya647NOdPLgPKzOQi8=; b=Xg3sc+OGJ1L7uDX/F7r2F+mPs1Izk1uNxaMWgtq3HHsa/SsSKEhHPgp41J9O1Wv/j70x B2tq4vZOT2Eo9pbMFeY4EpSHxv2EM28daAwx27XI1jkPflqr8GqEq7XyZK1DTd8aMVWR AOHZcy8RP+sUV9dd3ATySZ9YnF5Jwkn3xnjitmpvx2XGU9ubaRe3FQAmxlCCy0OvgFd7 jYyqjNA9Hu1KBCw3XmqnZXjtMnLDjqYG62q0J3n2Cqk19gQQeMb9dqb8L0TyVzrFKVDT MRXH1rVQy4IWJqYl+h3p8urWqXcTslre8Rn3znzHAekrXgIaa53kVghesXibQCuch37y 7g== Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0a-001b2d01.pphosted.com with ESMTP id 39nhcb8eef-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 08 Jul 2021 12:04:16 -0400 Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 168Fx5Gl027109 for ; Thu, 8 Jul 2021 16:04:10 GMT Received: from b01cxnp22035.gho.pok.ibm.com (b01cxnp22035.gho.pok.ibm.com [9.57.198.25]) by ppma05wdc.us.ibm.com with ESMTP id 39jfhd7c8k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 08 Jul 2021 16:04:10 +0000 Received: from b01ledav002.gho.pok.ibm.com (b01ledav002.gho.pok.ibm.com [9.57.199.107]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 168G4AJn37486870 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 8 Jul 2021 16:04:10 GMT Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 44E03124074; Thu, 8 Jul 2021 16:04:10 +0000 (GMT) Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 40E33124072; Thu, 8 Jul 2021 16:04:10 +0000 (GMT) Received: from localhost.localdomain (unknown [9.47.158.155]) by b01ledav002.gho.pok.ibm.com (Postfix) with ESMTP; Thu, 8 Jul 2021 16:04:10 +0000 (GMT) From: Stefan Berger To: linux-integrity@vger.kernel.org Cc: zohar@linux.ibm.com, Stefan Berger Subject: [PATCH ima-evm-utils v2 3/4] libimaevm: Remove calculation of a digest over a directory Date: Thu, 8 Jul 2021 12:04:07 -0400 Message-Id: <20210708160408.2779849-4-stefanb@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210708160408.2779849-1-stefanb@linux.ibm.com> References: <20210708160408.2779849-1-stefanb@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: KJzlNzE1pIXlvtKv2twV-SOPGEqLt2QC X-Proofpoint-GUID: KJzlNzE1pIXlvtKv2twV-SOPGEqLt2QC X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-07-08_10:2021-07-08,2021-07-08 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 phishscore=0 mlxlogscore=999 mlxscore=0 spamscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 adultscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107080083 Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Signature verification on directories is not supported by IMA in the kernel, so remove the calculation of digests over directories. Signed-off-by: Stefan Berger Reviewed-by: Mimi Zohar --- src/libimaevm.c | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/src/libimaevm.c b/src/libimaevm.c index 4d51901..07a25c9 100644 --- a/src/libimaevm.c +++ b/src/libimaevm.c @@ -177,40 +177,6 @@ out: return err; } -static int add_dir_hash(const char *file, EVP_MD_CTX *ctx) -{ - struct dirent *de; - DIR *dir; - unsigned long long ino; - unsigned int type; - int result = 0; - - dir = opendir(file); - if (!dir) { - log_err("Failed to open: %s\n", file); - return -1; - } - - while ((de = readdir(dir))) { - ino = de->d_ino; - type = de->d_type; - log_debug("entry: %s, ino: %llu, type: %u, reclen: %hu\n", - de->d_name, ino, type, de->d_reclen); - if (EVP_DigestUpdate(ctx, de->d_name, strlen(de->d_name)) != 1 || - EVP_DigestUpdate(ctx, &ino, sizeof(ino)) != 1|| - EVP_DigestUpdate(ctx, &type, sizeof(type)) != 1) { - log_err("EVP_DigestUpdate() failed\n"); - output_openssl_errors(); - result = 1; - break; - } - } - - closedir(dir); - - return result; -} - static int add_link_hash(const char *path, EVP_MD_CTX *ctx) { int len; @@ -265,9 +231,6 @@ int ima_calc_hash(const char *file, uint8_t *hash) case S_IFREG: err = add_file_hash(file, pctx); break; - case S_IFDIR: - err = add_dir_hash(file, pctx); - break; case S_IFLNK: err = add_link_hash(file, pctx); break; From patchwork Thu Jul 8 16:04:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 12365613 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0E3CC07E9E for ; Thu, 8 Jul 2021 16:04:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ABF6161874 for ; Thu, 8 Jul 2021 16:04:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230032AbhGHQGz (ORCPT ); Thu, 8 Jul 2021 12:06:55 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:48780 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229992AbhGHQGy (ORCPT ); Thu, 8 Jul 2021 12:06:54 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 168G3lBT075185 for ; Thu, 8 Jul 2021 12:04:12 -0400 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=3gJxilfmgb3aZYy10i+tUGinihr/lvJD/KIwxH+mKYE=; b=pA0YJ7BrcPFpGWPRJQkliAX47xsbN0jjHqAhul/qPZmywZno7TghMreLSe7DZz1hqZho deC/31W7Jj7mxZFXaCvk/Zg0M7B3mzFrdyFtSJUKgCwuBwv97+a3861ZynyPVZGrlN26 wSmz0NyeaSToqhKSifgj+My3MMtADK3fOhiSRk5TihDPKY7tAR15r8jnOr7d538FA37O MeNHCe5DuxU/9jHf/NQr25w/wx7yqanPXaKioHFpPnS1lhGp0tF5tGZWfsMucN8Odn0c dfraclMlw/PO647LBLSgaM4BWYEjO1MQFo6YQ/qk6fCToPwzczui2bkjacCR9K2Q2a4Y IA== Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0a-001b2d01.pphosted.com with ESMTP id 39nhcb8eeq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 08 Jul 2021 12:04:12 -0400 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 168FvNrW019075 for ; Thu, 8 Jul 2021 16:04:11 GMT Received: from b01cxnp22035.gho.pok.ibm.com (b01cxnp22035.gho.pok.ibm.com [9.57.198.25]) by ppma03dal.us.ibm.com with ESMTP id 39jhq1cepj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 08 Jul 2021 16:04:11 +0000 Received: from b01ledav002.gho.pok.ibm.com (b01ledav002.gho.pok.ibm.com [9.57.199.107]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 168G4AJc31261112 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 8 Jul 2021 16:04:10 GMT Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5D7F4124060; Thu, 8 Jul 2021 16:04:10 +0000 (GMT) Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 505B1124055; Thu, 8 Jul 2021 16:04:10 +0000 (GMT) Received: from localhost.localdomain (unknown [9.47.158.155]) by b01ledav002.gho.pok.ibm.com (Postfix) with ESMTP; Thu, 8 Jul 2021 16:04:10 +0000 (GMT) From: Stefan Berger To: linux-integrity@vger.kernel.org Cc: zohar@linux.ibm.com, Stefan Berger Subject: [PATCH ima-evm-utils v2 4/4] libimaevm: Remove calculation of a digest over a symbolic link Date: Thu, 8 Jul 2021 12:04:08 -0400 Message-Id: <20210708160408.2779849-5-stefanb@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210708160408.2779849-1-stefanb@linux.ibm.com> References: <20210708160408.2779849-1-stefanb@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: pNxkojln4zdK813f06FS4kPyUZSU1rNj X-Proofpoint-GUID: pNxkojln4zdK813f06FS4kPyUZSU1rNj X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-07-08_10:2021-07-08,2021-07-08 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 phishscore=0 mlxlogscore=999 mlxscore=0 spamscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 adultscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107080083 Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Signature verification on symbolic links is not supported by IMA in the kernel, so remove the calculation of digests over symbolic links. Signed-off-by: Stefan Berger Reviewed-by: Mimi Zohar --- src/libimaevm.c | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/libimaevm.c b/src/libimaevm.c index 07a25c9..6591d20 100644 --- a/src/libimaevm.c +++ b/src/libimaevm.c @@ -177,20 +177,6 @@ out: return err; } -static int add_link_hash(const char *path, EVP_MD_CTX *ctx) -{ - int len; - char buf[1024]; - - len = readlink(path, buf, sizeof(buf)); - /* 0-length links are also an error */ - if (len <= 0) - return -1; - - log_info("link: %s -> %.*s\n", path, len, buf); - return !EVP_DigestUpdate(ctx, buf, len); -} - int ima_calc_hash(const char *file, uint8_t *hash) { const EVP_MD *md; @@ -231,9 +217,6 @@ int ima_calc_hash(const char *file, uint8_t *hash) case S_IFREG: err = add_file_hash(file, pctx); break; - case S_IFLNK: - err = add_link_hash(file, pctx); - break; default: log_err("Unsupported file type (0x%x)", st.st_mode & S_IFMT); err = -1;