Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp873145ybl; Wed, 11 Dec 2019 08:48:40 -0800 (PST) X-Google-Smtp-Source: APXvYqxxxEQQaCxXP5xe+odk2xTtP5vAcNZro0pkaLKj8DTLj2Es9ZRuMFZWmLoMzoS3vqO+iE6U X-Received: by 2002:a9d:6649:: with SMTP id q9mr2863224otm.313.1576082920064; Wed, 11 Dec 2019 08:48:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576082920; cv=none; d=google.com; s=arc-20160816; b=jfGtyofOIZdE4UhcUnPu3I/AMa1AGGXu+Ri+kL6jZmvH9aYFkiPNprO9JBBpk2ZCiv BNhXboqC5GylIUckg5Hj1Z8o/4GkFyFXNSLZnsppDWGTCTo1jenUx2sU1w/gcsEprltT rEuLSyJJ2Yy8eX0sd2sQke0+LlsHUWHFy7fg4sjrQPegaOTgyqj4ufOtbkKasjvDX8Wu ZK9n/wqlskIF/8mFG49qmsGImShY9dj/Mh6qi2maX8uun6qmpF1uByCDHb1wCwA7EymO 5YXD05S8DJWeb42xUSL8fyfBQh+T7d7Hbfbb0i+w8S3F2onDzChqwy1hGht6qTmB/wRj YaAA== 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=xfXlPwV6ll6xVRquYxVt+gWc6A+AEcMUngaP3rSs6s91EPsRbsSvDsdBHgdFsvzQp1 msCgcstMX+tzx4bnQzWo1mDbZEDGO5PihwNcgP0uOOROLIkISD2QJ71aDdfQ+vHiNmV/ WyBzUSCcksiUrTuCEeEoV4bIx7XqPN3W/9dEyi6d4FiJX5WMLfIdCpp66CtsjTlLvr6D ScF1TttudutcUNP1VlXBeO8MzQFFhACAaZ4vmblcJL39kyOO+nwtiR4uO15iTmngj2j0 kOUfSsD/H7UY7xL1foOdPXY4r0FhZNASH8xkqgYcPjujpqqhHu8APTWFAm2acVr1CPpJ tEXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=gcGSHlut; 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 m8si1414122otr.11.2019.12.11.08.48.25; Wed, 11 Dec 2019 08:48:40 -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=gcGSHlut; 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 S1730836AbfLKQrQ (ORCPT + 99 others); Wed, 11 Dec 2019 11:47:16 -0500 Received: from linux.microsoft.com ([13.77.154.182]:38734 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729616AbfLKQrP (ORCPT ); Wed, 11 Dec 2019 11:47:15 -0500 Received: from nramas-ThinkStation-P520.corp.microsoft.com (unknown [131.107.174.108]) by linux.microsoft.com (Postfix) with ESMTPSA id 0268E20B718B; Wed, 11 Dec 2019 08:47:15 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0268E20B718B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1576082835; bh=L4puKXt7OmrSagN42Huxd1vQTKOco/JYM8kKj45zf2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gcGSHlutIN15chdYa3G7CiU+yKYytbd09sdX+j63feNsfeVOiCvVwEUzW92Mk3j/M NlYRpVdL0Q8l0i/o/wUyH4sD/1FdC+eE0WFX/vq0agBQWYjFLekM6q0CjKYOaMYLuM z6QnmqOQHbJjEefVcvTQ5xy0FEk5V71KNLAdNdw0= 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 v11 2/6] IMA: Add KEY_CHECK func to measure keys Date: Wed, 11 Dec 2019 08:47:03 -0800 Message-Id: <20191211164707.4698-3-nramas@linux.microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191211164707.4698-1-nramas@linux.microsoft.com> References: <20191211164707.4698-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