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=1796383488; b=ehSCnco96BBzr3qpBLmbR90fvhYowVYc22Vyxz+xKBtvAAL5FLEYuoacxpYp85j9yD4F KdYkZmaewZ9U+kwM674orrpMv3s3F4ObMPslqoaE+ZhotaUTY7nhpfc4VbkceDCsFWZUC bUsdqNSs2r+bkNKR5cgixKQKPBRHGo5WeDLvyWo0meh1gSv5ca6f5wMUeuplD5lcNCGIv GncRUmSFhg+ba5+IU2RtjWBCzPM8CdtoqQ5ny5TNES8iKK6aA3vVHiACMDPE1QHGk6Lu/ TbIrmhmyIhIDCsJSL2YuarEy/A3v2B94ALGKoYraQ6dyyl/PmUncMUpnRksVzxs47gQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383488; 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=15AUpdT6M91gFwmPWAW0Pxfastbc5TTNieXXrYaMTgo=; b=3+UqdvChrHRyVyUs/cWnrmIhlqzpozTpYgGy94WyWse6zY7qHjWbiyU+WNqxxUSbYrIp /WjcIlNCcCIMNiNbl1aQ+x8Ud3056RIV1BN2HF0naV0hD5yAnTeQT2kRcXslCWMYQWxyc kFssG/591B/ybWpe1Cr6fGqNchpJoXLWiyhlvXRgs8TqMIWP3WK/a8ArO3ZOeWV+v7u9P RRWEo6fQhk6iJBKSvvo4K2R2pnfhwwxrqwUiJws7PjsA0wsFryn7PfQYtC1aYhWfSUSSi 1x8W1oPDdT4WrQwInSvNn3gumTC+jaWF3jUYovYGd87lTj6FkUDAc8aqg+erO92UcGQ== 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="o4U/V43k"; 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 A4E7F606A32D; Fri, 4 Dec 2026 11:24:48 +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=o4U/V43k Received: by smtp.kernel.org (Postfix) with ESMTPSA id 194DC1F000C2; Fri, 4 Dec 2026 11:24:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383488; bh=15AUpdT6M91gFwmPWAW0Pxfastbc5TTNieXXrYaMTgo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=o4U/V43k5anncjpbxzQBit6aXr+EgD0301r2R7op7/AHbawwpnPBgoSBao5b6078u XW8S7X+22yB+xRFFSPhP5yPRSxFv7vSD9c5beDuZXmUKQ+jBgQRHKhh6vvVfzTB6cG wPHR8kXkhkYRgMNvY7PSCZg3YqKJ85Sx6XfEvJmo= 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.12 245/555] s390/cert_store: Only allow the kernel to create cert_store_key keys Date: Fri, 4 Dec 2026 19:04:48 +0900 Message-ID: <20261204100618.512572758@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@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.12-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 35b64bad24c19..8e9c0025f2dba 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