Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp3392635ybc; Mon, 18 Nov 2019 14:40:10 -0800 (PST) X-Google-Smtp-Source: APXvYqzKmTc9vgwtRUJ5sNMW1QQweruRhWrOgcni9OaOiUdD+J+UFNJuH5Cz/ttx7mXNlzK55lax X-Received: by 2002:a17:906:2444:: with SMTP id a4mr27214802ejb.134.1574116810443; Mon, 18 Nov 2019 14:40:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574116810; cv=none; d=google.com; s=arc-20160816; b=QofyVFkGNo6GcHFVrCwzZMq6cEZgy4csa8Mcg1oABF2XhotSK0JI2AEMiqd7H8e7e+ Ar3E1f0kqfQTpcAtBlMoWpsUwN9J7riMM0f0PrG2oEyhsDRZyMUkB5NCyhCCyuMsTB/H T7rrUVvRLIIU9UGKiceEb0L8TFeeZoQW5Sumtmx1kQ6E+Nu2ZsfIUbdczaNkRLXN/E6A 8eJP7YuJNoGBmWFnXBrj6D/W1a/1eGUgIYwqWsrotS/siUt9ThuMpsdMC9iCrpFuxKHp hkdtZiL7HAeB5E2IytSk5jHZHVC9A3RQIePac0kKy2x5+NXT+TP2Mv1gy8zn47DQ6MvI 1tSQ== 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=ezcY0DaINd1FR3b0Y/IK94Q2dD9Cgf/AVRRWw/OCE8I=; b=GWX034sAeo8x9Gd9wIdxksKRb+v5/skUlBOC3SXTSuQxfj4EIViJpKImXtMkIpRnFa j9Mlf0UAjZissGgTAewS8DT3I5WIfMP0bQlT21AlNgfAAHQNFAB2jCn06E5/DHN1Kdh4 asWRh3BCBi0jVfjEAfIYUFhQgG2LmU8B+xr+3raHF0jMS/RBz2i6OJYtFWa7eFwbknTf Bp2H0EHmm5rNzPugjso81TGzR0MhurH+yMGYyD1QVWkqmh49O5tQw9FMSySsoQRxzYll KBdT9Paol0R1dAS3UpEuYq5v/Z00WyBaoxNkg1PhSlkAq0oPXVOHGYoJ6IhVeitAmFVa wPJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=BysBLpme; 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 a52si13966255eda.450.2019.11.18.14.39.46; Mon, 18 Nov 2019 14:40:10 -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=BysBLpme; 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 S1727004AbfKRWiZ (ORCPT + 99 others); Mon, 18 Nov 2019 17:38:25 -0500 Received: from linux.microsoft.com ([13.77.154.182]:50918 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726705AbfKRWiZ (ORCPT ); Mon, 18 Nov 2019 17:38:25 -0500 Received: from nramas-ThinkStation-P520.corp.microsoft.com (unknown [131.107.174.108]) by linux.microsoft.com (Postfix) with ESMTPSA id 0F7622007681; Mon, 18 Nov 2019 14:38:24 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0F7622007681 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1574116704; bh=ezcY0DaINd1FR3b0Y/IK94Q2dD9Cgf/AVRRWw/OCE8I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BysBLpmewwD9bLgjNuzH4H+UpbNRLSncZr6zOaqjlnmdkaMABiKm0JMI+/T1egmj4 HKW/f+wj+9d1/ud/8I48W6ORJH/JTHkksSCJdYc8yxQ1LK4Aj6hS4Kp6YZcau+7XgF bVNs+rHrLAzhAZ34R7ftIlXzQN1q65ciU750Tzdg= From: Lakshmi Ramasubramanian To: zohar@linux.ibm.com, linux-integrity@vger.kernel.org Cc: linux-kernel@vger.kernel.org, keyrings@vger.kernel.org Subject: [PATCH v8 1/5] IMA: Add KEY_CHECK func to measure keys Date: Mon, 18 Nov 2019 14:38:14 -0800 Message-Id: <20191118223818.3353-2-nramas@linux.microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191118223818.3353-1-nramas@linux.microsoft.com> References: <20191118223818.3353-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 Cc: Sasha Levin Cc: James Morris --- Documentation/ABI/testing/ima_policy | 7 ++++++- security/integrity/ima/ima.h | 1 + security/integrity/ima/ima_policy.c | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Documentation/ABI/testing/ima_policy b/Documentation/ABI/testing/ima_policy index 29aaedf33246..3823c27894c5 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,8 @@ 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