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=1796381939; b=neoKpfBQcGl1WFu393slSJ2X7rgWPKMu9F3nBHgKmVI0UyAElTHJ798+fNDLXwP42/AC a/tT5/IRlw0N2kt5qBQWKC8PZbyJTZ+f3Nv9QnaJKXnRXMNaFvjBGveFTLx9kzkHx22i5 MqftW+dHsbENeC4Zxqr7RHHcLcMkoxoC2Xc1aceTf5x1ZvZ5O2x3UkYE6b8hD9SqAcS8h p/Cvfy8+uoEF/W43JqicPmMZFa2aLEtM4Nzw4CdFYDfonuX+HT3jW/d8jQh8CNPmn7u5e ULzym+bwgjdS0w9kTlEgwbfL6cjGVw7XrqPQAVikuFT0fAP58TzO3cGoYI02XLU0hrA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381939; 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=YFIPWQg4oYreMbJ/Am+VwLs3kfAQHO6LtS4vr1Yf2x0=; b=C06aA+exOBTcf5HRrsi1DdFdC4UnpElmwehcZC5qtWoARD99EKZBaWDFM34K4PD0l2mh ado1X1yVV+cti30Y4q+XiSl31c4UH5SMBl3rPMQ8tZc7cy5hcbCRt4pKdMw4u8M7XY3dE ERJvsn2Uhv+OeQDPjyfK6+eVopxNzsb8WKZdUq6qiKyXyu56KKsq0PB22c1j2qGi5Uxna NpeUeCdGlwlkyhEdaeQ7JZthlkJxRidQhj9gbGSPZN0rt+uncYAXfBLeo95zaiJWFw1Sr lyx1lS+HRp6DKyMPaT/fMMD5hLOtyRjPg4mjtYlejIAm9vmpd1qCy4V9FESClC6JQGw== 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=EcovwLGV; 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 0F6A1606A322; Fri, 4 Dec 2026 10:58:58 +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=EcovwLGV Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F2EF1F00934; Fri, 4 Dec 2026 10:58:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381938; bh=YFIPWQg4oYreMbJ/Am+VwLs3kfAQHO6LtS4vr1Yf2x0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=EcovwLGV0MMmh8p8IhvWODpslGwSEtCnNJxASyL1vujRzawRZvRIpOUvfYb2fhia0 XteoxoQfiGw7Kt86CfJNk2Y03RzXQG3Cl6ANCYnIeBq176TJPlsLhrBtYQMzPJVCw5 iPjB/k8OJ3zb+SUCdkcaBbrQIlogf3xzUZI3AeCI= 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.18 239/703] s390/cert_store: Only allow the kernel to create cert_store_key keys Date: Fri, 4 Dec 2026 19:02:18 +0900 Message-ID: <20261204100634.166374867@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-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 8c93b94335624..791c35dd50161 100644 --- a/arch/s390/kernel/cert_store.c +++ b/arch/s390/kernel/cert_store.c @@ -45,6 +45,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__) @@ -147,12 +150,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, @@ -761,6 +776,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(); @@ -769,6 +785,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