Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp462730ybx; Wed, 30 Oct 2019 18:21:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwXDyW18uYOkPvtk0XkeJ/aLlz3BAZ4j1RPDeTD903i8pYw3vLJk1hVyLqS3LsZIUTeQztz X-Received: by 2002:a17:906:c793:: with SMTP id cw19mr1262206ejb.25.1572484881037; Wed, 30 Oct 2019 18:21:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572484881; cv=none; d=google.com; s=arc-20160816; b=NBqQvwuzBVT9HoSLIiqucK1b2C7sZOj4kA9FwWhhsXLEd6ZdBXk5hho3JmDQ7lS3JX 1G6BwCIbxWPXrZLpC2T7jZhKuvD780cZTqghv1EZS0IzOPdaY9PMu/9Tzhx6mLt3Lnr3 NSc5vexJIEvsfshd2fi4eeLEd5a0NlNk+l1Ymoi/DiUeNL5qPHMxvAcIpuqnItTWHsxx I14wqElSHPOWntLPo9Hb8CwJC33vnisx2AWo28qWUCdgR7Ty3PFePCYj6e9zrTinrs3s NgHckT+puq6giStU+uB37SZM4W/c8dRqfgvroR82G0mG4Mh/r/u7rsX4VILlBkyjWX7q aA9A== 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=Yt7zvROV2WRfOD8Z9HJCq2ITyurhwXk4qzuAU0jlehg=; b=a93vwRhNlua2Szy9B9m2H8XEpAkun7GNqHrLW/G5pznvXVYFMLeT+BjqmD6CtpAHcb 2YShMxTWaMUTYwczEIMGvLRpnmbkc1t6GGmn8BvE6tQ7qt1XlyW3PFGvzfsDHq0ubc3M DfxkmUOKhozBAvydjcQvHWFU47bPQRYzuVGbtVsI6WtnWwW93dzDKOpr8iFYLMqt06/K paPQVT1tG0I15fhF5aSB71Q86iK6Xkn6ncWK2UYYGCcc4ttlCo5fu64Ogtyp5xAXCZL/ /JaCRZ/4WE48lEV51GaiQer8x8q2gq2V83wOE22VJV3rCGfsL0zoNVvCHBaZiu9rAPSj 5BUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=AyzQn2hR; 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 o22si2480334ejm.429.2019.10.30.18.20.57; Wed, 30 Oct 2019 18:21:21 -0700 (PDT) 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=AyzQn2hR; 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 S1726973AbfJaBTr (ORCPT + 99 others); Wed, 30 Oct 2019 21:19:47 -0400 Received: from linux.microsoft.com ([13.77.154.182]:34428 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726538AbfJaBTS (ORCPT ); Wed, 30 Oct 2019 21:19:18 -0400 Received: from nramas-ThinkStation-P520.corp.microsoft.com (unknown [131.107.174.108]) by linux.microsoft.com (Postfix) with ESMTPSA id 12B5A20B4903; Wed, 30 Oct 2019 18:19:17 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 12B5A20B4903 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1572484757; bh=Yt7zvROV2WRfOD8Z9HJCq2ITyurhwXk4qzuAU0jlehg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AyzQn2hRMfh6Qz2mX5up1n0lUe0dYU8hgo5DyJD9VNUfMPfWLr/2SjkMY6F7RiQkn 7hCIlp4rCiBrVyAsUoOKXEIkuWKzzisX/zgPe7/MMPmoNm4hzovtmIhihJeEzoVLqO MmI/YId1p1jFBJPhzk2MrKHg0ocHJM7eJphz/CTA= From: Lakshmi Ramasubramanian To: zohar@linux.ibm.com, dhowells@redhat.com, matthewgarrett@google.com, sashal@kernel.org, jamorris@linux.microsoft.com, linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, keyrings@vger.kernel.org Cc: prsriva@linux.microsoft.com Subject: [PATCH v3 3/9] KEYS: Added KEYRING_CHECK policy for key measurement Date: Wed, 30 Oct 2019 18:19:04 -0700 Message-Id: <20191031011910.2574-4-nramas@linux.microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191031011910.2574-1-nramas@linux.microsoft.com> References: <20191031011910.2574-1-nramas@linux.microsoft.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org An IMA policy to manage measurement of keys is not supported. A new IMA policy is needed to manage the measurement of keys. A policy option is also needed to allow measurement of keys linked to a given set of keyrings only. This patch defines KEYRING_CHECK and keyrings in IMA policy for this purpose. KEYRING_CHECK can be added in the IMA policy to measure keys. keyrings can be, optionally, set to only measure keys added or updated to a given set of keyrings. If keyrings is not specified for KEYRING_CHECK, keys added or updated in all keyrings are measured. Signed-off-by: Lakshmi Ramasubramanian --- Documentation/ABI/testing/ima_policy | 15 +++++++++++++++ security/integrity/ima/ima.h | 1 + security/integrity/ima/ima_main.c | 2 +- security/integrity/ima/ima_policy.c | 2 +- security/integrity/ima/ima_queue.c | 2 +- 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Documentation/ABI/testing/ima_policy b/Documentation/ABI/testing/ima_policy index fc376a323908..757faf1a1a27 100644 --- a/Documentation/ABI/testing/ima_policy +++ b/Documentation/ABI/testing/ima_policy @@ -25,10 +25,12 @@ Description: lsm: [[subj_user=] [subj_role=] [subj_type=] [obj_user=] [obj_role=] [obj_type=]] option: [[appraise_type=]] [template=] [permit_directio] + [keyrings=] base: func:= [BPRM_CHECK][MMAP_CHECK][CREDS_CHECK][FILE_CHECK][MODULE_CHECK] [FIRMWARE_CHECK] [KEXEC_KERNEL_CHECK] [KEXEC_INITRAMFS_CHECK] [KEXEC_CMDLINE] + [KEYRING_CHECK] mask:= [[^]MAY_READ] [[^]MAY_WRITE] [[^]MAY_APPEND] [[^]MAY_EXEC] fsmagic:= hex value @@ -38,6 +40,9 @@ Description: fowner:= decimal value lsm: are LSM specific option: appraise_type:= [imasig] + keyrings: = list of keyrings to measure + (eg, .builtin_trusted_keys|.ima). Only valid + when action is "measure" and func is KEYRING_CHECK. template:= name of a defined IMA template type (eg, ima-ng). Only valid when action is "measure". pcr:= decimal value @@ -105,3 +110,13 @@ Description: measure func=KEXEC_KERNEL_CHECK pcr=4 measure func=KEXEC_INITRAMFS_CHECK pcr=5 + + Example of measure rules using KEYRING_CHECK + To measure keys added to + .builtin_trusted_keys or .ima keyring: + + measure func=KEYRING_CHECK keyrings=.builtin_trusted_keys|.ima + + To measure keys added to all keyrings: + + measure func=KEYRING_CHECK diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index b9600070e415..12e9ec6847b5 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -191,6 +191,7 @@ static inline unsigned long ima_hash_key(u8 *digest) hook(KEXEC_INITRAMFS_CHECK) \ hook(POLICY_CHECK) \ hook(KEXEC_CMDLINE) \ + hook(KEYRING_CHECK) \ hook(MAX_CHECK) #define __ima_hook_enumify(ENUM) ENUM, diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c index 18e1bc105be7..72ae0878ec5d 100644 --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -718,7 +718,7 @@ void ima_post_key_create_or_update(struct key *keyring, struct key *key, pk = key->payload.data[asym_crypto]; process_buffer_measurement(pk->key, pk->keylen, keyring->description, - NONE, 0); + KEYRING_CHECK, 0); } static int __init init_ima(void) diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index 6df7f641ff66..0cc49f2d5233 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -370,7 +370,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 == KEYRING_CHECK)) { if ((rule->flags & IMA_FUNC) && (rule->func == func)) return true; return false; diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c index f2503f10abf4..5625381c5a97 100644 --- a/security/integrity/ima/ima_queue.c +++ b/security/integrity/ima/ima_queue.c @@ -317,7 +317,7 @@ void ima_measure_queued_keys(void) process_buffer_measurement(entry->public_key, entry->public_key_len, entry->keyring_name, - NONE, 0); + KEYRING_CHECK, 0); list_del(&entry->list); ima_free_measure_key_entry(entry); } -- 2.17.1