All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: Heiko Carstens <hca@linux.ibm.com>
Cc: Anastasia Eskova <anastasia.eskova@ibm.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	Peter Oberparleiter <oberpar@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	keyrings@vger.kernel.org, linux-s390@vger.kernel.org
Subject: Re: [PATCH 2/2] s390/cert_store: Only allow the kernel to create cert_store_key keys
Date: Mon, 23 Nov 2026 15:43:47 +0200	[thread overview]
Message-ID: <awRDE-HZNcxGqmiv@kernel.org> (raw)
In-Reply-To: <20261123102324.483917-3-hca@linux.ibm.com>

On Mon, Nov 23, 2026 at 11:23:24AM +0100, Heiko Carstens wrote:
> From: Anastasia Eskova <anastasia.eskova@ibm.com>
> 
> 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 <anastasia.eskova@ibm.com>
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
> ---
>  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 6f5c63cd907f..6e518ff38322 100644
> --- a/arch/s390/kernel/cert_store.c
> +++ b/arch/s390/kernel/cert_store.c
> @@ -46,6 +46,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__)
>  
> @@ -148,12 +151,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,
> @@ -768,6 +783,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();
> @@ -776,6 +792,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
> 

I can give this despite a bit out of context for me because I'm already
somewhat familiar with the implementation overall:

Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

Br, Jarkko

  reply	other threads:[~2026-11-23 13:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 10:23 [PATCH 0/2] s390/cert_store: Restrict link creation and key type creation Heiko Carstens
2026-11-23 10:23 ` [PATCH 1/2] s390/cert_store: Allocate keyring with link restriction Heiko Carstens
2026-11-23 13:42   ` Jarkko Sakkinen
2026-11-23 14:11     ` Heiko Carstens
2026-11-23 14:18       ` Jarkko Sakkinen
2026-11-23 14:20         ` Jarkko Sakkinen
2026-11-23 10:23 ` [PATCH 2/2] s390/cert_store: Only allow the kernel to create cert_store_key keys Heiko Carstens
2026-11-23 13:43   ` Jarkko Sakkinen [this message]
2026-11-23 10:31 ` [PATCH 0/2] s390/cert_store: Restrict link creation and key type creation sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=awRDE-HZNcxGqmiv@kernel.org \
    --to=jarkko@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=anastasia.eskova@ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=oberpar@linux.ibm.com \
    --cc=svens@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.