Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp464196ybx; Wed, 30 Oct 2019 18:22:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqzW93a3ai5t65ZqYoGFZi/5vCUp8rQQSBhvAuaRPLAqogb0b1z2wueZqcaPg6COfeiBqcLY X-Received: by 2002:a05:6402:488:: with SMTP id k8mr3016153edv.293.1572484969915; Wed, 30 Oct 2019 18:22:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572484969; cv=none; d=google.com; s=arc-20160816; b=ocXHpxwCQ7x3FMex/RdOx/Eh6DFtzUuKsEB0FrUyl2fyZ3FCIhlQxEWwP4f0MWxhj8 q0vlwRQRaXVDwPhTNMbNDP4mnFFNq1R0eFS3onE8JQ5f3q9/LxoK5K7hOWVsSyAHxCRr K7E5eJN4lUy7ZP41E0tuFgYyqgEBpSoLcoXxH3IZkqO6fHIsgJas9anu6ivJsFRR4C6p nKbi58j4HCZ9oQdoX3gW6DkfZDnXZ7corU2qB8Ac4AZs3nS63ZhyY0/CJjW1Mc6hdCzk 5Ou/qZpxWrT2MNkk7+h8i8SMhPB8de7Uyi1LyqzGbsYaGnGjtSj3NyHt9V5loHgzYcF+ cZCg== 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=RqMz75eioSPQPfWpUYryf90rJHg/WjOPYhEZZl7VA8U=; b=mIuctf1FY6nUBMxIANYSJShAOGgCkvgyc0S2cSsqYfr7YUyvfIlKKeYX6nv9DyVz0b +D0HS8b5zI7WSH8UOBejGJUeugNZjHfrvPvXbUwf6c/i5bAVhnqekYmG8pFj/1ksQYL2 nJtfxvETb56AEnlDwJliTWd6RX6S4FmR0NsakIQDtS13wZ8pg0CfH7ABxMq88nD9Ruc5 0vy0RVEsz3mr79Siude9eIO8J9ppebkfXIAV9KzgzIs1/j0h0W68THKh6F+58ljajK1t h/zoFJK1pSjfJATQ0ia1njLh4D28NdpSxpdbjMfdfKpKVCVSuiGyiVh3mGZx4a7UykGr Duhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=g7lu73QS; 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 w14si2412746ejv.112.2019.10.30.18.22.26; Wed, 30 Oct 2019 18:22:49 -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=g7lu73QS; 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 S1726680AbfJaBTS (ORCPT + 99 others); Wed, 30 Oct 2019 21:19:18 -0400 Received: from linux.microsoft.com ([13.77.154.182]:34404 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726316AbfJaBTR (ORCPT ); Wed, 30 Oct 2019 21:19:17 -0400 Received: from nramas-ThinkStation-P520.corp.microsoft.com (unknown [131.107.174.108]) by linux.microsoft.com (Postfix) with ESMTPSA id B0CB22010AC0; Wed, 30 Oct 2019 18:19:16 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com B0CB22010AC0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1572484756; bh=RqMz75eioSPQPfWpUYryf90rJHg/WjOPYhEZZl7VA8U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g7lu73QSWsjqmDPwqqNimRTunhhlVKf5Rp4COY+BU9Ybmcem+q4On7oOhJZ7ePvTz iuQj3HMspram5CCthGBj0zoS6W/pyMLv1tYbt7r0dFI2YtKgbTED+s9z4qXWO1jS8w 914I0vofydvtlGiInXeChrf25Xm5c33kiRy6O1Qw= 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 1/9] KEYS: Defined an IMA hook to measure keys on key create or update Date: Wed, 30 Oct 2019 18:19:02 -0700 Message-Id: <20191031011910.2574-2-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 Asymmetric keys used for verifying file signatures or certificates are currently not included in the IMA measurement list. This patch defines a new IMA hook namely ima_post_key_create_or_update() to measure asymmetric keys. Signed-off-by: Lakshmi Ramasubramanian --- security/integrity/ima/ima.h | 2 ++ security/integrity/ima/ima_main.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index 997a57137351..22d0628faf56 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include "../integrity.h" diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c index 492b8f241d39..18e1bc105be7 100644 --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -635,6 +635,9 @@ void process_buffer_measurement(const void *buf, int size, int action = 0; u32 secid; + if (!ima_policy_flag) + return; + if (func) { security_task_getsecid(current, &secid); action = ima_get_action(NULL, current_cred(), secid, 0, func, @@ -695,6 +698,29 @@ void ima_kexec_cmdline(const void *buf, int size) } } +/** + * ima_post_key_create_or_update - measure asymmetric keys + * @keyring: keyring to which the key is linked to + * @key: created or updated key + * @flags: key flags + * @create: flag indicating whether the key was created or updated + * + * Keys can only be measured, not appraised. + */ +void ima_post_key_create_or_update(struct key *keyring, struct key *key, + unsigned long flags, bool create) +{ + const struct public_key *pk; + + if (key->type != &key_type_asymmetric) + return; + + pk = key->payload.data[asym_crypto]; + process_buffer_measurement(pk->key, pk->keylen, + keyring->description, + NONE, 0); +} + static int __init init_ima(void) { int error; -- 2.17.1