Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp991584ybl; Wed, 4 Dec 2019 14:43:52 -0800 (PST) X-Google-Smtp-Source: APXvYqw98smMC1S5hNjn2EljLUSXuZR8vvCwWf1+VekDkHpN+0jSwTNT6kq7W9yil1Xkdqw8NzLQ X-Received: by 2002:aca:3456:: with SMTP id b83mr4801884oia.82.1575499432006; Wed, 04 Dec 2019 14:43:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575499431; cv=none; d=google.com; s=arc-20160816; b=kZ+avTg1nkgDC+auKZp+pR8e3aQkr3uVROmHKBT38/kC9PNCoaBK73yhazc5nj9AhZ ZS3/8YLGhNoMSogKdq7+D0BmxgB6KhOACrNEJYqS6MYKkdhZ/NwtsaE79KmwkTU0RcxT ab1cDDQPkjMhwwTuYNwurAdzFy75/swbL1nfnjkOsckYjkYxnEFyiARzf7F1A8hSzhqt ZGaqiHBHA2gzYDwlZjvNIgzoNNKppig7zek26vhls8/zcQlT6jk6WcrRPjM2OBNCpA9o T4j4qr84kL/oOc/i7983DhNJmszPkDFj6QRityUadlHoQ6JlSwQFhVHsAf6V5GkWu2In 8oJw== 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=uyjvkd5wYoMbXwgtp3x/u3NHam91vrscRvlPELzvU0M=; b=KNLH+k17eIA1jNUx//o2CXnU7zpkx1lEU+GdBCKqacZuHWeFTxAWVgojrFG3GsK2PP 4fj7NpA6zIASdg8MnYnjEB9JmYhjJvivetntu4U4Ew+os6bFF9r0BALQw0/5jfsZzZFb mKK3E7FtWEqKbCGtjUm3ZcL03MIyj95q40rwTw6VGHdAgfUTvfOTiLP0244Zi01xZ1iN xyVVlNoWfR4XFghLZtmvMWP+0WRl+dwoc4crxL43rasBOaBz69J4enAFnHv/3uQRsFoH aTrJxiF1Trzn/wSExAl5o58NGr1NB9qhuc1auT9KuWqPl3dIwjx+67+r0ITwA0TAy61y e9Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=tFCFJSwS; 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 v126si4095443oib.42.2019.12.04.14.43.40; Wed, 04 Dec 2019 14:43:51 -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=tFCFJSwS; 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 S1728532AbfLDWly (ORCPT + 99 others); Wed, 4 Dec 2019 17:41:54 -0500 Received: from linux.microsoft.com ([13.77.154.182]:50158 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728330AbfLDWli (ORCPT ); Wed, 4 Dec 2019 17:41:38 -0500 Received: from nramas-ThinkStation-P520.corp.microsoft.com (unknown [131.107.174.108]) by linux.microsoft.com (Postfix) with ESMTPSA id 78C812010AE8; Wed, 4 Dec 2019 14:41:37 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 78C812010AE8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1575499297; bh=uyjvkd5wYoMbXwgtp3x/u3NHam91vrscRvlPELzvU0M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tFCFJSwSUckr5KemCBgiZPIs8MdN5wBjWuXvartQ1rKtmQKEAisCMyrF+9xzUmLQh 7xSPkwEtFJlYCEE4i1uHH1sj2RxrcxkEO37dcVygL8Rqq8YATlA6I0aADFBbCAsPdb n0iL1r1B6SLeliqmPGdAlkK7YsGa475q/oif+RTw= 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 v10 3/6] IMA: Define an IMA hook to measure keys Date: Wed, 4 Dec 2019 14:41:28 -0800 Message-Id: <20191204224131.3384-4-nramas@linux.microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191204224131.3384-1-nramas@linux.microsoft.com> References: <20191204224131.3384-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 asymmetric keys used for verifying file signatures, certificates, etc. This patch defines a new IMA hook namely ima_post_key_create_or_update() to measure the payload used to create a new key or update an existing key. The IMA hook is defined in a new file namely ima_asymmetric_keys.c which is built only if CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE is enabled. Signed-off-by: Lakshmi Ramasubramanian --- security/integrity/ima/Makefile | 1 + security/integrity/ima/ima_asymmetric_keys.c | 52 ++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 security/integrity/ima/ima_asymmetric_keys.c diff --git a/security/integrity/ima/Makefile b/security/integrity/ima/Makefile index 31d57cdf2421..207a0a9eb72c 100644 --- a/security/integrity/ima/Makefile +++ b/security/integrity/ima/Makefile @@ -12,3 +12,4 @@ ima-$(CONFIG_IMA_APPRAISE) += ima_appraise.o ima-$(CONFIG_IMA_APPRAISE_MODSIG) += ima_modsig.o ima-$(CONFIG_HAVE_IMA_KEXEC) += ima_kexec.o obj-$(CONFIG_IMA_BLACKLIST_KEYRING) += ima_mok.o +obj-$(CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE) += ima_asymmetric_keys.o diff --git a/security/integrity/ima/ima_asymmetric_keys.c b/security/integrity/ima/ima_asymmetric_keys.c new file mode 100644 index 000000000000..994d89d58af9 --- /dev/null +++ b/security/integrity/ima/ima_asymmetric_keys.c @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2019 Microsoft Corporation + * + * Author: Lakshmi Ramasubramanian (nramas@linux.microsoft.com) + * + * File: ima_asymmetric_keys.c + * Defines an IMA hook to measure asymmetric keys on key + * create or update. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include "ima.h" + +/** + * ima_post_key_create_or_update - measure asymmetric keys + * @keyring: keyring to which the key is linked to + * @key: created or updated key + * @payload: The data used to instantiate or update the key. + * @payload_len: The length of @payload. + * @flags: key flags + * @create: flag indicating whether the key was created or updated + * + * Keys can only be measured, not appraised. + * The payload data used to instantiate or update the key is measured. + */ +void ima_post_key_create_or_update(struct key *keyring, struct key *key, + const void *payload, size_t payload_len, + unsigned long flags, bool create) +{ + /* Only asymmetric keys are handled by this hook. */ + if (key->type != &key_type_asymmetric) + return; + + if (!payload || (payload_len == 0)) + return; + + /* + * keyring->description points to the name of the keyring + * (such as ".builtin_trusted_keys", ".ima", etc.) to + * which the given key is linked to. + * + * The name of the keyring is passed in the "eventname" + * parameter to process_buffer_measurement() and is set + * in the "eventname" field in ima_event_data for + * the key measurement IMA event. + */ + process_buffer_measurement(payload, payload_len, + keyring->description, KEY_CHECK, 0); +} -- 2.17.1