From patchwork Thu Jul 25 06:13:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Chikunov X-Patchwork-Id: 11057995 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF0FA14DB for ; Thu, 25 Jul 2019 06:13:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE67D28923 for ; Thu, 25 Jul 2019 06:13:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2D1B2897C; Thu, 25 Jul 2019 06:13:10 +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 E21F42893A for ; Thu, 25 Jul 2019 06:13:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728994AbfGYGNJ (ORCPT ); Thu, 25 Jul 2019 02:13:09 -0400 Received: from vmicros1.altlinux.org ([194.107.17.57]:36570 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726001AbfGYGNJ (ORCPT ); Thu, 25 Jul 2019 02:13:09 -0400 Received: from imap.altlinux.org (imap.altlinux.org [194.107.17.38]) by vmicros1.altlinux.org (Postfix) with ESMTP id 816B672CC6C; Thu, 25 Jul 2019 09:13:07 +0300 (MSK) Received: from beacon.altlinux.org (unknown [185.6.174.98]) by imap.altlinux.org (Postfix) with ESMTPSA id 5EE074A4AE8; Thu, 25 Jul 2019 09:13:07 +0300 (MSK) From: Vitaly Chikunov To: Mimi Zohar , Dmitry Kasatkin , linux-integrity@vger.kernel.org Subject: [PATCH 1/2] ima-evm-utils: Do not allow fallback and unknown hash algos Date: Thu, 25 Jul 2019 09:13:05 +0300 Message-Id: <20190725061306.30515-1-vt@altlinux.org> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 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 Falling back and permissiveness could have security implications. Signed-off-by: Vitaly Chikunov --- src/evmctl.c | 4 ++++ src/libimaevm.c | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/evmctl.c b/src/evmctl.c index 3289061..3766343 100644 --- a/src/evmctl.c +++ b/src/evmctl.c @@ -584,6 +584,10 @@ static int hash_ima(const char *file) int len, err, offset; int algo = get_hash_algo(params.hash_algo); + if (algo < 0) { + log_err("Unknown hash algo: %s\n", params.hash_algo); + return -1; + } if (algo > PKEY_HASH_SHA1) { hash[0] = IMA_XATTR_DIGEST_NG; hash[1] = algo; diff --git a/src/libimaevm.c b/src/libimaevm.c index 2d99570..86c5784 100644 --- a/src/libimaevm.c +++ b/src/libimaevm.c @@ -571,8 +571,7 @@ int get_hash_algo(const char *algo) !strcmp(algo, hash_algo_name[i])) return i; - log_info("digest %s not found, fall back to sha1\n", algo); - return PKEY_HASH_SHA1; + return -1; } static int get_hash_algo_from_sig(unsigned char *sig) @@ -920,6 +919,10 @@ int sign_hash_v2(const char *algo, const unsigned char *hash, int size, const ch hdr->version = (uint8_t) DIGSIG_VERSION_2; hdr->hash_algo = get_hash_algo(algo); + if (hdr->hash_algo == -1) { + log_err("sign_hash_v2: hash algo is unknown: %s\n", algo); + return -1; + } calc_keyid_v2(&keyid, name, pkey); hdr->keyid = keyid; From patchwork Thu Jul 25 06:13:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Chikunov X-Patchwork-Id: 11057997 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2D761746 for ; Thu, 25 Jul 2019 06:13:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D5B228929 for ; Thu, 25 Jul 2019 06:13:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11E0928987; Thu, 25 Jul 2019 06:13:13 +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 A7F3E28980 for ; Thu, 25 Jul 2019 06:13:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726001AbfGYGNM (ORCPT ); Thu, 25 Jul 2019 02:13:12 -0400 Received: from vmicros1.altlinux.org ([194.107.17.57]:36612 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729146AbfGYGNL (ORCPT ); Thu, 25 Jul 2019 02:13:11 -0400 Received: from imap.altlinux.org (imap.altlinux.org [194.107.17.38]) by vmicros1.altlinux.org (Postfix) with ESMTP id C032672CCE7; Thu, 25 Jul 2019 09:13:09 +0300 (MSK) Received: from beacon.altlinux.org (unknown [185.6.174.98]) by imap.altlinux.org (Postfix) with ESMTPSA id 935564A4AE8; Thu, 25 Jul 2019 09:13:09 +0300 (MSK) From: Vitaly Chikunov To: Mimi Zohar , Dmitry Kasatkin , linux-integrity@vger.kernel.org Subject: [PATCH 2/2] ima-evm-utils: Show used hash algo in verbose mode Date: Thu, 25 Jul 2019 09:13:06 +0300 Message-Id: <20190725061306.30515-2-vt@altlinux.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190725061306.30515-1-vt@altlinux.org> References: <20190725061306.30515-1-vt@altlinux.org> MIME-Version: 1.0 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 could be useful for users. Signed-off-by: Vitaly Chikunov --- This will conflict with not accepted `params' rename patch. src/evmctl.c | 2 +- src/libimaevm.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/evmctl.c b/src/evmctl.c index 3766343..75dd163 100644 --- a/src/evmctl.c +++ b/src/evmctl.c @@ -605,7 +605,7 @@ static int hash_ima(const char *file) len += offset; if (params.verbose >= LOG_INFO) - log_info("hash: "); + log_info("hash(%s): ", params.hash_algo); if (sigdump || params.verbose >= LOG_INFO) dump(hash, len); diff --git a/src/libimaevm.c b/src/libimaevm.c index 86c5784..11dbf11 100644 --- a/src/libimaevm.c +++ b/src/libimaevm.c @@ -822,7 +822,7 @@ int sign_hash_v1(const char *hashalgo, const unsigned char *hash, int size, cons return -1; } - log_info("hash: "); + log_info("hash(%s): ", hashalgo); log_dump(hash, size); key = read_priv_key(keyfile, params.keypass);