Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6140051rdb; Thu, 14 Dec 2023 09:15:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IFCcb8yYvCAQv83sJR77wE2jkvgE3OoiO5q4jwiNZD0UECk9kKqs9kSPqYfWuyaiabBSF7s X-Received: by 2002:a05:6a00:2bc:b0:6d2:65a3:726e with SMTP id q28-20020a056a0002bc00b006d265a3726emr560704pfs.39.1702574154339; Thu, 14 Dec 2023 09:15:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702574154; cv=none; d=google.com; s=arc-20160816; b=EQ8KwiLMTMDghSDesJP1wu1XYpw3ARZsbrDlY/TiZEgI/M76RSY7GcZQjfxz0meXCr WWSKjXCUkioMr2RDuvbKpPyAWf21vREfxzNIySZ96PDzI2MhghOk+ik9USAeL3DxVGhW th4BzGfp68ItSivFgjjoaHrol++ZYgwbgRTQc+K7IE8WtXiHzijSf2oxrlHt3z4X0UQi 1SLEhal0TNQY68DumrM8NAQIiznaSjmZRPgBBXmaYQzJ4eB58xUpK9OjOrcwRgKFhnVI UNqWSbI6puAVmFuksXx40bvoNcJpCs+31HXbpi7QRXZYIg0Bog9/VazNrDetM2dYThXP ZOhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=K48HuKmmSYoM4htCZ70QbQs50WkI111JrIYWt4WgXFI=; fh=e4uGr9b4mUXyBbS3/T8oKWuNGdTPau3Pm4RSvXRKvaA=; b=VUd0hiChR7TAuOSBpBwO4hVkTEwKR2W740skVP3aa3gvJ7ujkFZSj8xhIcJ0CFTLEn 9bmSjws45kJtiTpTlZBYrbJWvhXtFv4g8lSn05a6wKzrMN/MZBqu6PGOJSrQaOjbLXDU Y4kCyKixK3Z8QcSaFpDqH1TB9rSXWJc6ZzxVorHZMHp/y7aLG/AeGZ7NQPA25QSv20uU DmdtvSzFlIQOx+hCm/ajqEUaggvT8L6w0d/yv/5tUhTltPiykhbfBp8TBYDZV4mGetN0 vSHtCV56e1GCaW1tILeORCelcuEpnNKVM9VX4ALakn+e2ZYMfSTUywKsWPwRM2UC9a8h flZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs+bounces-602-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-nfs+bounces-602-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 12-20020a63164c000000b005be1955657esi11539889pgw.127.2023.12.14.09.15.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 09:15:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs+bounces-602-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs+bounces-602-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-nfs+bounces-602-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 6CB95B21881 for ; Thu, 14 Dec 2023 17:14:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 36AED63DE0; Thu, 14 Dec 2023 17:14:31 +0000 (UTC) X-Original-To: linux-nfs@vger.kernel.org Received: from frasgout13.his.huawei.com (frasgout13.his.huawei.com [14.137.139.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 918CB1719; Thu, 14 Dec 2023 09:14:23 -0800 (PST) Received: from mail.maildlp.com (unknown [172.18.186.51]) by frasgout13.his.huawei.com (SkyGuard) with ESMTP id 4Srdrg2GnSz9y7ZG; Fri, 15 Dec 2023 01:00:19 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.27]) by mail.maildlp.com (Postfix) with ESMTP id 13C1814064D; Fri, 15 Dec 2023 01:14:11 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP2 (Coremail) with SMTP id GxC2BwAHuGFtN3tlDa2DAg--.53313S10; Thu, 14 Dec 2023 18:14:10 +0100 (CET) From: Roberto Sassu To: viro@zeniv.linux.org.uk, brauner@kernel.org, chuck.lever@oracle.com, jlayton@kernel.org, neilb@suse.de, kolga@netapp.com, Dai.Ngo@oracle.com, tom@talpey.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, zohar@linux.ibm.com, dmitry.kasatkin@gmail.com, dhowells@redhat.com, jarkko@kernel.org, stephen.smalley.work@gmail.com, eparis@parisplace.org, casey@schaufler-ca.com, shuah@kernel.org, mic@digikod.net Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-security-module@vger.kernel.org, linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org, Roberto Sassu , Stefan Berger Subject: [PATCH v8 18/24] security: Introduce key_post_create_or_update hook Date: Thu, 14 Dec 2023 18:08:28 +0100 Message-Id: <20231214170834.3324559-19-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231214170834.3324559-1-roberto.sassu@huaweicloud.com> References: <20231214170834.3324559-1-roberto.sassu@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:GxC2BwAHuGFtN3tlDa2DAg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fC2KfnxnUUI43ZEXa7IUbGXdUUUUUU== X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAgALBF1jj5OoPwAAs4 From: Roberto Sassu In preparation for moving IMA and EVM to the LSM infrastructure, introduce the key_post_create_or_update hook. Depending on policy, IMA measures the key content after creation or update, so that remote verifiers are aware of the operation. Other LSMs could similarly take some action after successful key creation or update. The new hook cannot return an error and cannot cause the operation to be reverted. Signed-off-by: Roberto Sassu Reviewed-by: Stefan Berger Acked-by: Casey Schaufler Reviewed-by: Mimi Zohar --- include/linux/lsm_hook_defs.h | 3 +++ include/linux/security.h | 11 +++++++++++ security/keys/key.c | 7 ++++++- security/security.c | 19 +++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h index bfb10a1e6a44..2679905f4260 100644 --- a/include/linux/lsm_hook_defs.h +++ b/include/linux/lsm_hook_defs.h @@ -403,6 +403,9 @@ LSM_HOOK(void, LSM_RET_VOID, key_free, struct key *key) LSM_HOOK(int, 0, key_permission, key_ref_t key_ref, const struct cred *cred, enum key_need_perm need_perm) LSM_HOOK(int, 0, key_getsecurity, struct key *key, char **buffer) +LSM_HOOK(void, LSM_RET_VOID, key_post_create_or_update, struct key *keyring, + struct key *key, const void *payload, size_t payload_len, + unsigned long flags, bool create) #endif /* CONFIG_KEYS */ #ifdef CONFIG_AUDIT diff --git a/include/linux/security.h b/include/linux/security.h index 7b753460f09d..766eaccc4679 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -1995,6 +1995,9 @@ void security_key_free(struct key *key); int security_key_permission(key_ref_t key_ref, const struct cred *cred, enum key_need_perm need_perm); int security_key_getsecurity(struct key *key, char **_buffer); +void security_key_post_create_or_update(struct key *keyring, struct key *key, + const void *payload, size_t payload_len, + unsigned long flags, bool create); #else @@ -2022,6 +2025,14 @@ static inline int security_key_getsecurity(struct key *key, char **_buffer) return 0; } +static inline void security_key_post_create_or_update(struct key *keyring, + struct key *key, + const void *payload, + size_t payload_len, + unsigned long flags, + bool create) +{ } + #endif #endif /* CONFIG_KEYS */ diff --git a/security/keys/key.c b/security/keys/key.c index 0260a1902922..f75fe66c2f03 100644 --- a/security/keys/key.c +++ b/security/keys/key.c @@ -935,6 +935,8 @@ static key_ref_t __key_create_or_update(key_ref_t keyring_ref, goto error_link_end; } + security_key_post_create_or_update(keyring, key, payload, plen, flags, + true); ima_post_key_create_or_update(keyring, key, payload, plen, flags, true); @@ -968,10 +970,13 @@ static key_ref_t __key_create_or_update(key_ref_t keyring_ref, key_ref = __key_update(key_ref, &prep); - if (!IS_ERR(key_ref)) + if (!IS_ERR(key_ref)) { + security_key_post_create_or_update(keyring, key, payload, plen, + flags, false); ima_post_key_create_or_update(keyring, key, payload, plen, flags, false); + } goto error_free_prep; } diff --git a/security/security.c b/security/security.c index a722d5db0a2c..423d53092604 100644 --- a/security/security.c +++ b/security/security.c @@ -5406,6 +5406,25 @@ int security_key_getsecurity(struct key *key, char **buffer) *buffer = NULL; return call_int_hook(key_getsecurity, 0, key, buffer); } + +/** + * security_key_post_create_or_update() - Notification of key create or update + * @keyring: keyring to which the key is linked to + * @key: created or updated key + * @payload: data used to instantiate or update the key + * @payload_len: length of payload + * @flags: key flags + * @create: flag indicating whether the key was created or updated + * + * Notify the caller of a key creation or update. + */ +void security_key_post_create_or_update(struct key *keyring, struct key *key, + const void *payload, size_t payload_len, + unsigned long flags, bool create) +{ + call_void_hook(key_post_create_or_update, keyring, key, payload, + payload_len, flags, create); +} #endif /* CONFIG_KEYS */ #ifdef CONFIG_AUDIT -- 2.34.1