Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp991140ybl; Wed, 4 Dec 2019 14:43:16 -0800 (PST) X-Google-Smtp-Source: APXvYqx20OanvtIJCc8mYlX/zZCmjKovvE2UuFzyVhdJfcIFKAMZWD6UWA1e9uuURbkU4Gzk2A3u X-Received: by 2002:a54:488d:: with SMTP id r13mr4464048oic.115.1575499395992; Wed, 04 Dec 2019 14:43:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575499395; cv=none; d=google.com; s=arc-20160816; b=CFX152uTyYqvS7RG721lDolBhPCfU4IvFb8QQi7P0IFX0SXcficNiskBlxxgXSyTAU gfbJgXEXrwBQbO3PvFvTU6603CPx0IrjXaML07A2HloHBrrpUlDgKzqi/QOpOJvXtb9g VdkjzowHRW4cDDUdtyLScenr+pnCmtU2nwTwDHuzO6OsxRHY8rTgRSSnEsPx73iC9JOe 00bAUeO/AJ65IHGyzo8YqIgTFqZOxGcACl/B+WtwBxLJoodOAmZ+rfSQS7AhsSjMEsam Bb2M9yqyNL5WACMLIUMr/hj7lYykshI3QSIqXRZxMXTNDyxj6uf/iBZH4VMA14a+xwuv W7rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=L4puKXt7OmrSagN42Huxd1vQTKOco/JYM8kKj45zf2k=; b=UAQ7n2zFMRe9fZp3BBFhzBXiKGDpC14LtVpdLR7oE+z0Wozee2/OsInRG5Xtw4cdZ4 fwoUPSsdGphMBIXGtxkoe2YgWmuJiTnpf6CwnVaAOYK4Jo9+qhKy0o+CMho/qtRAZpmn PHUs1d1NgAcc9TK2rZUdUsG2iM5l+yBTPZz2MJaISzb3q/8229Zno4shs5+sFQUpbmng gycj2nmCMu1H+SdoSWMKCu8dgRdbUn6cij95LV9uhQLICLeahmAVwEHLBmk96OEPPm4M TrZg5971JkrEME//7YXKn6yq2WG4wN+sOX6s1+dekmqPz+KZ5wfMgbIM/jsnopXsTlwF djLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=Buek2F9l; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g25si4089305otp.20.2019.12.04.14.43.03; Wed, 04 Dec 2019 14:43:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=Buek2F9l; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728552AbfLDWmA (ORCPT + 99 others); Wed, 4 Dec 2019 17:42:00 -0500 Received: from linux.microsoft.com ([13.77.154.182]:50140 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728284AbfLDWli (ORCPT ); Wed, 4 Dec 2019 17:41:38 -0500 Received: from nramas-ThinkStation-P520.corp.microsoft.com (unknown [131.107.174.108]) by linux.microsoft.com (Postfix) with ESMTPSA id 5003120B4762; Wed, 4 Dec 2019 14:41:37 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5003120B4762 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1575499297; bh=L4puKXt7OmrSagN42Huxd1vQTKOco/JYM8kKj45zf2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Buek2F9ll8/bUHrhBgsViGYaRaAayGefcfg1p/6jSG8lGyFdn74jFOjDhLIGv0lth OCPEHjH59CUe33w0Kp3t+PNuLKCkzSWHVmQK6EA+cY937+VB3Qmwbh8V/Le2lpN222 FfYcp8C8jRBqumLtEZyRmM/sWX8Hp6ameMe8rhPo= From: Lakshmi Ramasubramanian To: zohar@linux.ibm.com, linux-integrity@vger.kernel.org Cc: eric.snowberg@oracle.com, dhowells@redhat.com, mathew.j.martineau@linux.intel.com, matthewgarrett@google.com, sashal@kernel.org, jamorris@linux.microsoft.com, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org Subject: [PATCH v10 2/6] IMA: Add KEY_CHECK func to measure keys Date: Wed, 4 Dec 2019 14:41:27 -0800 Message-Id: <20191204224131.3384-3-nramas@linux.microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191204224131.3384-1-nramas@linux.microsoft.com> References: <20191204224131.3384-1-nramas@linux.microsoft.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Measure keys loaded onto any keyring. This patch defines a new IMA policy func namely KEY_CHECK to measure keys. Updated ima_match_rules() to check for KEY_CHECK and ima_parse_rule() to handle KEY_CHECK. Signed-off-by: Lakshmi Ramasubramanian --- Documentation/ABI/testing/ima_policy | 6 +++++- security/integrity/ima/ima.h | 1 + security/integrity/ima/ima_policy.c | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Documentation/ABI/testing/ima_policy b/Documentation/ABI/testing/ima_policy index 29aaedf33246..066d32797500 100644 --- a/Documentation/ABI/testing/ima_policy +++ b/Documentation/ABI/testing/ima_policy @@ -29,7 +29,7 @@ Description: base: func:= [BPRM_CHECK][MMAP_CHECK][CREDS_CHECK][FILE_CHECK][MODULE_CHECK] [FIRMWARE_CHECK] [KEXEC_KERNEL_CHECK] [KEXEC_INITRAMFS_CHECK] - [KEXEC_CMDLINE] + [KEXEC_CMDLINE] [KEY_CHECK] mask:= [[^]MAY_READ] [[^]MAY_WRITE] [[^]MAY_APPEND] [[^]MAY_EXEC] fsmagic:= hex value @@ -113,3 +113,7 @@ Description: Example of appraise rule allowing modsig appended signatures: appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig|modsig + + Example of measure rule using KEY_CHECK to measure all keys: + + measure func=KEY_CHECK diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index df4ca482fb53..fe6c698617bd 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -193,6 +193,7 @@ static inline unsigned long ima_hash_key(u8 *digest) hook(KEXEC_INITRAMFS_CHECK) \ hook(POLICY_CHECK) \ hook(KEXEC_CMDLINE) \ + hook(KEY_CHECK) \ hook(MAX_CHECK) #define __ima_hook_enumify(ENUM) ENUM, diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index f19a895ad7cd..1525a28fd705 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -373,7 +373,7 @@ static bool ima_match_rules(struct ima_rule_entry *rule, struct inode *inode, { int i; - if (func == KEXEC_CMDLINE) { + if ((func == KEXEC_CMDLINE) || (func == KEY_CHECK)) { if ((rule->flags & IMA_FUNC) && (rule->func == func)) return true; return false; @@ -997,6 +997,8 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry) entry->func = POLICY_CHECK; else if (strcmp(args[0].from, "KEXEC_CMDLINE") == 0) entry->func = KEXEC_CMDLINE; + else if (strcmp(args[0].from, "KEY_CHECK") == 0) + entry->func = KEY_CHECK; else result = -EINVAL; if (!result) -- 2.17.1