From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796386397; b=GM5IVncGqc0sv7tCRQnhOc/wCCs6WMfBs9Ev59rhllRTAi+1r60D4ixztUeomW9RcO5R 6u0jJqNdSu9bppD3gBhCXBMfJyylPeYUoXgXmfQKnu3+8Qvm1wlab4KjNyNyK+KJXelVB jvaQfFgoQl4HUuKhdM42VAHbMcdel65DwVOM+vfRm0Q/UN2IBnmerqUuCDE0juVIXUXzx KDDawt6oBJJ9gpKkpQoqeTqAq9td56OZQ2BcFAKyjOfzjh5z7TUf/tvcFLlO0ttrlwphw V7QCeIs/hjGG5p2xHF0uCy3CZv09Cwck9+bQ202kfcYzz6Hyx4lXmJSlKMPu+MGd0AQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386397; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=hfQzWUmOQrPR5qJ3mvvXVmMj19qrgtuqK7qjgWJ00hI=; b=IogVNZhqeUA5Z6XzJyEbskxW/q9Q+oXDcoTtqLDdeLvREUAaFdvU+Qy7L8VGohlCZYHS cT5hoJY8sPN6dpWoaoYmvUH8vn22KBesVOZoAnW2y/XSaIuTPanud0AYRfnjevjqeDxQd x4lDs7SwqPyPrGBkSSMSElU1LbjWTQ/b/EysIemB9TvPYT1r02D8quy2ZD73GWxBip0Fj wG34uvjmskqx62ydXfo0khsD77u2ObwKRQ8WHCl4yZbe7+85maAEmxZzCcHPTTlcwflKG ftY8OlnLcsq0Y0dnAHVxwotxkB2ukLC6d0Lfz/8/WAnVALJ3M6olUqVJQqSNS0waAjA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=fq28zjLh; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAA90606A32C; Fri, 4 Dec 2026 12:13:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=fq28zjLh Received: by smtp.kernel.org (Postfix) with ESMTPSA id 243AE1F000C2; Fri, 4 Dec 2026 12:13:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796386396; bh=hfQzWUmOQrPR5qJ3mvvXVmMj19qrgtuqK7qjgWJ00hI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fq28zjLhiGu7F/2GTpy2oDtaGG8gRjG9A0QB1GA4sSq7aoMAmPRztJkXIus51PFUz JyZz3yWWloB/p2Jg7n0RLnGrnig0KXPpe/0OklrZupU5Ty5yw1dNtl/DwJdv1KToE2 5ufAgj2vnigzOJKRloV/tjSuuMu0BuLM/PF9PN6g= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Anastasia Eskova , Jarkko Sakkinen , Heiko Carstens , Sasha Levin Subject: [PATCH 6.6 0937/1167] s390/cert_store: Only allow the kernel to create cert_store_key keys Date: Fri, 4 Dec 2026 19:06:04 +0900 Message-ID: <20261204100726.599498973@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Anastasia Eskova [ Upstream commit 23a04cb4f2bdbfc87fc4e1c15450e7f8cfc9842a ] Keys of type cert_store_key can be created by any user with add_key() in any keyring, as the key type has no vet_description() callback. The type is registered whenever CONFIG_CERT_STORE is enabled, even if the machine has no DIAG 320 support. cert_store_key_describe() expects a description in the format created by get_key_description(), i.e. a 64 byte key name followed by the VCE index and the certificate store token. If a key with a shorter description is created, seq_puts() may read beyond the end of the description allocation. Reading /proc/keys may then disclose adjacent kernel heap memory to the user space. Also, a consumer which trusts keys by type can be fooled by keys that were not created from the certificate store. Add a vet_description() callback which only accepts the task currently executing refresh_store(), which creates all valid keys of this type. Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates") Signed-off-by: Anastasia Eskova Reviewed-by: Jarkko Sakkinen Signed-off-by: Heiko Carstens Signed-off-by: Sasha Levin --- arch/s390/kernel/cert_store.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c index 67a55afeb6c13..3dcbc30a52508 100644 --- a/arch/s390/kernel/cert_store.c +++ b/arch/s390/kernel/cert_store.c @@ -44,6 +44,9 @@ static debug_info_t *cert_store_dbf; static debug_info_t *cert_store_hexdump; +/* Task currently running refresh_store(). Written under cs_refresh_lock. */ +static struct task_struct *cs_refresh_task; + #define pr_dbf_msg(fmt, ...) \ debug_sprintf_event(cert_store_dbf, 3, fmt "\n", ## __VA_ARGS__) @@ -146,12 +149,24 @@ static void cert_store_key_describe(const struct key *key, struct seq_file *m) seq_printf(m, ": %u", key->datalen); } +/* + * Only the kernel may create keys of this type. Accept the task which runs + * refresh_store(), as it cannot execute userspace during the refresh. + */ +static int cert_store_key_vet_description(const char *description) +{ + if (READ_ONCE(cs_refresh_task) != current) + return -EPERM; + return 0; +} + /* * Certificate store key type takes over properties of * user key but cannot be updated. */ static struct key_type key_type_cert_store_key = { .name = CERT_STORE_KEY_TYPE_NAME, + .vet_description = cert_store_key_vet_description, .preparse = user_preparse, .free_preparse = user_free_preparse, .instantiate = generic_key_instantiate, @@ -760,6 +775,7 @@ static ssize_t refresh_store(struct kobject *kobj, struct kobj_attribute *attr, if (rc) return rc; + WRITE_ONCE(cs_refresh_task, current); for (retries = 0; retries < DIAG_MAX_RETRIES; retries++) { /* Request certificates from certificate store. */ rc = fill_cs_keyring(); @@ -768,6 +784,7 @@ static ssize_t refresh_store(struct kobject *kobj, struct kobj_attribute *attr, if (rc != -EAGAIN) break; } + WRITE_ONCE(cs_refresh_task, NULL); cs_status_val = rc; mutex_unlock(&cs_refresh_lock); -- 2.53.0