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 12/15] s390/cert_store: Validate hash length in check_certificate_valid()
Date: Mon, 16 Nov 2026 21:27:22 +0200	[thread overview]
Message-ID: <avtZGgO0DtD8Vn9Y@kernel.org> (raw)
In-Reply-To: <20261116143534.158375-13-hca@linux.ibm.com>

On Mon, Nov 16, 2026 at 03:35:31PM +0100, Heiko Carstens wrote:
> Validate that vc_hash_length is SHA256_DIGEST_SIZE before checking the
> hash and use sizeof(hash) in memcmp(). This avoids an out-of-bounds
> read if vc_hash_length is incorrect.
> 
> Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
> ---
>  arch/s390/kernel/cert_store.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
> index 551b538ea930..ecfb7641d427 100644
> --- a/arch/s390/kernel/cert_store.c
> +++ b/arch/s390/kernel/cert_store.c
> @@ -261,13 +261,11 @@ static int diag320(unsigned long subcode, void *addr)
>  static int check_certificate_hash(const struct vce *vce)
>  {
>  	u8 hash[SHA256_DIGEST_SIZE];
> -	u16 vc_hash_length;
>  	u8 *vce_hash;
>  
>  	vce_hash = (u8 *)vce + vce->vce_hdr.vc_hash_offset;
> -	vc_hash_length = vce->vce_hdr.vc_hash_length;
>  	sha256((u8 *)vce + vce->vce_hdr.vc_offset, vce->vce_hdr.vc_length, hash);
> -	if (memcmp(vce_hash, hash, vc_hash_length) == 0)
> +	if (memcmp(vce_hash, hash, sizeof(hash)) == 0)
>  		return 0;
>  
>  	pr_dbf_msg("SHA256 hash of received certificate does not match");
> @@ -293,6 +291,10 @@ static int check_certificate_valid(const struct vce *vce)
>  		pr_dbf_msg("Hash type is not supported");
>  		return -EINVAL;
>  	}
> +	if (vce->vce_hdr.vc_hash_length != SHA256_DIGEST_SIZE) {
> +		pr_dbf_msg("Hash length is not supported");
> +		return -EINVAL;
> +	}
>  
>  	return check_certificate_hash(vce);
>  }
> -- 
> 2.56.1
> 

I'll stop here :-)

Br, Jarkko

  parent reply	other threads:[~2026-11-16 19:27 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 14:35 [PATCH 00/15] s390/cert_store: Various fixes Heiko Carstens
2026-11-16 14:35 ` [PATCH 01/15] s390/cert_store: Hold keyring->sem while reading the keyring Heiko Carstens
2026-11-16 17:57   ` sashiko-bot
2026-11-16 14:35 ` [PATCH 02/15] s390/cert_store: Fix return code handling in invalidate_keyring_keys() Heiko Carstens
2026-11-16 17:55   ` sashiko-bot
2026-11-16 19:44   ` Jarkko Sakkinen
2026-11-16 14:35 ` [PATCH 03/15] s390/cert_store: Fix potential use-after-free " Heiko Carstens
2026-11-16 17:08   ` Jarkko Sakkinen
2026-11-16 18:01   ` sashiko-bot
2026-11-16 14:35 ` [PATCH 04/15] s390/cert_store: Check key_lookup() return code " Heiko Carstens
2026-11-16 17:09   ` Jarkko Sakkinen
2026-11-16 17:52   ` sashiko-bot
2026-11-16 14:35 ` [PATCH 05/15] s390/cert_store: Unlink before invalidate " Heiko Carstens
2026-11-16 17:53   ` sashiko-bot
2026-11-16 18:40   ` Jarkko Sakkinen
2026-11-16 14:35 ` [PATCH 06/15] s390/cert_store: Fix cs_keyring reference leak in fill_cs_keyring() Heiko Carstens
2026-11-16 17:57   ` sashiko-bot
2026-11-16 18:42   ` Jarkko Sakkinen
2026-11-16 14:35 ` [PATCH 07/15] s390/cert_store: Fix potential use-after-free caused by find_cs_keyring() Heiko Carstens
2026-11-16 18:00   ` sashiko-bot
2026-11-16 18:44   ` Jarkko Sakkinen
2026-11-16 14:35 ` [PATCH 08/15] s390/cert_store: Remove unnecessary static specifier in create_cs_keyring() Heiko Carstens
2026-11-16 17:48   ` sashiko-bot
2026-11-16 19:00   ` Jarkko Sakkinen
2026-11-16 14:35 ` [PATCH 09/15] s390/cert_store: Fix error handling of get_user_session_keyring() Heiko Carstens
2026-11-16 17:58   ` sashiko-bot
2026-11-16 19:01   ` Jarkko Sakkinen
2026-11-16 14:35 ` [PATCH 10/15] s390/cert_store: Fix keyring refcount handling in get_user_session_keyring() Heiko Carstens
2026-11-16 17:49   ` sashiko-bot
2026-11-16 19:01   ` Jarkko Sakkinen
2026-11-16 14:35 ` [PATCH 11/15] s390/cert_store: Do not search the process keyrings for the cert_store keyring Heiko Carstens
2026-11-16 17:53   ` sashiko-bot
2026-11-16 19:02   ` Jarkko Sakkinen
2026-11-16 14:35 ` [PATCH 12/15] s390/cert_store: Validate hash length in check_certificate_valid() Heiko Carstens
2026-11-16 17:51   ` sashiko-bot
2026-11-16 19:27   ` Jarkko Sakkinen [this message]
2026-11-17 15:46     ` Heiko Carstens
2026-11-17 16:02       ` Jarkko Sakkinen
2026-11-16 14:35 ` [PATCH 13/15] s390/cert_store: Fix max_vcxe_length output in pr_dbf_vcssb() Heiko Carstens
2026-11-16 17:53   ` sashiko-bot
2026-11-16 14:35 ` [PATCH 14/15] s390/cert_store: Fix out-of-bounds read in pr_dbf_vce() Heiko Carstens
2026-11-16 17:56   ` sashiko-bot
2026-11-16 14:35 ` [PATCH 15/15] s390/cert_store: Initialize ism array in query_diag320_subcodes() Heiko Carstens
2026-11-16 17:55   ` 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=avtZGgO0DtD8Vn9Y@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.