Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp256258ybg; Tue, 22 Oct 2019 20:05:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqyhh3FgKUOVBmgHDUeq0Ywmo6jBjAgtx3jdEEEFdad0mbPFa5EBjW+PIIcpRajQ9Gs9n1mp X-Received: by 2002:aa7:d615:: with SMTP id c21mr2330968edr.167.1571799932968; Tue, 22 Oct 2019 20:05:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571799932; cv=none; d=google.com; s=arc-20160816; b=YH+hu+momUuhKzFCqPImY+1xF0XO64oOlf517zejGqdNkpcH/GxN7+USBj9l5Vx6LI QJeGcsDcN0qR81WPrHrItnzqyCFMJqytPyupbCQwTlcAs8EJ8/cMJP3wQQcSrRbX57j5 4j7XMMP4KYxkk3Jq0D3F0NwPYyQ17y2LLaqqfpRULOseW76C+d34/zsh9HKelk6Gm9/a twhKXGlDV3QTWDjCFJQERKplpfYCVmuuKpp39mDt30eYDHJvc4Xx0enHg+1lHAAi6Nll oJgu45xzMJ/VfajDPYUqdxZzrdhwY/GYYb2zBiZx2TGiJTmIuDhMpsAGCejLGPbmFwtP fBYw== 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=4Bq0D88j9WL7mEGpp0j6poBpUK+duhRJiZbGEgFGP/8=; b=z+5jl0RYdjYTzB/xaCWlCN/VL+WLd+hgEBrZotXEpecpdmSJlkFmUhNRC8GaqCdNLQ +Hru8lgvNUwo9aySe/oEPmoZjF0NFacywSeB9tFOTkRGXLNDS63/NDkKqeiqv+ylaQ4x q7Cbxhvh9K1JMVFGXr5DjD7tpPGWA16awm5IILM05OfyrKkdLp5lYZ6avlGb4Jq2Nq6r uvjll7Ih0ta0fmubPcp6NbK/zaxKxYV2WpTmNp5CjKYZWlQCfFx/BA3ZScFMaDRsbe5x SZrqm7sAXhI1im6VM77yrHyNH2T7gpkyXtRdbU4Knq1eHLLfWroNHBCzCZY/+/KWxU+h o4NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=GR5qiulu; 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 c27si6858261ede.425.2019.10.22.20.05.09; Tue, 22 Oct 2019 20:05:32 -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=GR5qiulu; 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 S1732769AbfJWASp (ORCPT + 99 others); Tue, 22 Oct 2019 20:18:45 -0400 Received: from linux.microsoft.com ([13.77.154.182]:45276 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732224AbfJWASZ (ORCPT ); Tue, 22 Oct 2019 20:18:25 -0400 Received: from nramas-ThinkStation-P520.corp.microsoft.com (unknown [131.107.174.108]) by linux.microsoft.com (Postfix) with ESMTPSA id 9ADA92010AC5; Tue, 22 Oct 2019 17:18:24 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 9ADA92010AC5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1571789904; bh=4Bq0D88j9WL7mEGpp0j6poBpUK+duhRJiZbGEgFGP/8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GR5qiulus8Ap/Lz+o/JQtHylY8rYL6Hwe4J3vcj3qCPdx3Eu/MnySgUf1STSslCmk +/0JcClLmQ/+57UJM7TQNqXeR37TjqwF8YcPnoUAbOVWZRTDonJFsrmllMChXvybFd 4DHp635ZK1QIAmcdvWji6U3kF9rPLiBm32MA9YAE= From: Lakshmi Ramasubramanian To: zohar@linux.ibm.com, dhowells@redhat.com, casey@schaufler-ca.com, sashal@kernel.org, jamorris@linux.microsoft.com, linux-security-module@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org Cc: nramas@linux.microsoft.com Subject: [PATCH v1 3/6] KEYS: ima hook to measure builtin_trusted_keys Date: Tue, 22 Oct 2019 17:18:15 -0700 Message-Id: <20191023001818.3684-4-nramas@linux.microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191023001818.3684-1-nramas@linux.microsoft.com> References: <20191023001818.3684-1-nramas@linux.microsoft.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a new ima hook to measure keys added to builtin_trusted_keys keyring. Updated ima_match_rules function to handle the new ima hook. This is used to determine if ima policy requires measurement of keys added to builtin_trusted_keys keyring. Signed-off-by: Lakshmi Ramasubramanian --- Documentation/ABI/testing/ima_policy | 1 + security/integrity/ima/ima.h | 1 + security/integrity/ima/ima_api.c | 1 + security/integrity/ima/ima_policy.c | 5 ++++- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/ima_policy b/Documentation/ABI/testing/ima_policy index fc376a323908..25566c74e679 100644 --- a/Documentation/ABI/testing/ima_policy +++ b/Documentation/ABI/testing/ima_policy @@ -29,6 +29,7 @@ Description: [FIRMWARE_CHECK] [KEXEC_KERNEL_CHECK] [KEXEC_INITRAMFS_CHECK] [KEXEC_CMDLINE] + [BUILTIN_TRUSTED_KEYS] mask:= [[^]MAY_READ] [[^]MAY_WRITE] [[^]MAY_APPEND] [[^]MAY_EXEC] fsmagic:= hex value diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index b6847ee1f47a..0d2908036882 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -189,6 +189,7 @@ static inline unsigned long ima_hash_key(u8 *digest) hook(KEXEC_INITRAMFS_CHECK) \ hook(POLICY_CHECK) \ hook(KEXEC_CMDLINE) \ + hook(BUILTIN_TRUSTED_KEYS) \ hook(MAX_CHECK) #define __ima_hook_enumify(ENUM) ENUM, diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c index f614e22bf39f..cc04706b7e7a 100644 --- a/security/integrity/ima/ima_api.c +++ b/security/integrity/ima/ima_api.c @@ -175,6 +175,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename, * subj,obj, and type: are LSM specific. * func: FILE_CHECK | BPRM_CHECK | CREDS_CHECK | MMAP_CHECK | MODULE_CHECK * | KEXEC_CMDLINE + * | BUILTIN_TRUSTED_KEYS * mask: contains the permission mask * fsmagic: hex value * diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index 6df7f641ff66..944636076152 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 == BUILTIN_TRUSTED_KEYS)) { if ((rule->flags & IMA_FUNC) && (rule->func == func)) return true; return false; @@ -959,6 +959,9 @@ 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, + "BUILTIN_TRUSTED_KEYS") == 0) + entry->func = BUILTIN_TRUSTED_KEYS; else result = -EINVAL; if (!result) -- 2.17.1