All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Holger Dengler" <dengler@linux.ibm.com>
Cc: "Vasily Gorbik" <gor@linux.ibm.com>,
	linux-s390@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>
Subject: Re: [PATCH v1 1/1] s390/zcrypt: Validate length in reply before using it
Date: Thu, 20 Aug 2026 14:20:43 +0000	[thread overview]
Message-ID: <20260820142043.F40931F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260820140439.892324-2-dengler@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] The patch fixes an out-of-bounds read in `_ip_cprb_helper()` but misses identical vulnerabilities in `cca_gencipherkey()` and `_ep11_genaeskey()`.
- [High] Unvalidated length fields in the CPRBX response payload are used to advance a memory pointer, causing severe out-of-bounds reads in `cca_query_crypto_facility()`.
--

--- Patch [1]: [PATCH v1 1/1] s390/zcrypt: Validate length in reply before using it ---
commit 3fcaad86f04a2a9419691d5f1a54cc873f326675
Author: Holger Dengler <dengler@linux.ibm.com>

s390/zcrypt: Validate length in reply before using it

The length information in the reply is used to copy the key token to
the target buffer. An invalid information in t->len of the reply may
cause an over-read of the target buffer and also a over-write of the
target buffer. To prevent that, check t->len before using it.

> diff --git a/drivers/s390/crypto/zcrypt_ccamisc.c b/drivers/s390/crypto/zcrypt_ccamisc.c
> index d4ce6352b5b2e..54b8edd1dfc74 100644
> --- a/drivers/s390/crypto/zcrypt_ccamisc.c
> +++ b/drivers/s390/crypto/zcrypt_ccamisc.c
> @@ -1158,8 +1158,21 @@ static int _ip_cprb_helper(u16 cardnr, u16 domain,
>  
>  	/* do not check the key here, it may be incomplete */
>  
> -	/* copy the vlsc key token back */
> +	/*
> +	 * Copy the vlsc key token back.
> +	 * The available space in the destination (key_token) and the source
> +	 * (t) buffer is always larger as the valid range of prepparm->kb.len.
> +	 * Validate t->len ba comparing it with the length information in the
> +	 * param block of the request (prepparm->kb.len)
> +	 * The value range of prepparm->kb.len has been checked above.
> +	 */
>  	t = (struct cipherkeytoken *)prepparm->kb.tlv1.key_token;
> +	if (t->len != prepparm->kb.len - 3 * sizeof(uint16_t)) {
> +		ZCRYPT_DBF_ERR("%s reply with invalid key_token length %u\n",
> +			       __func__, t->len);
> +		rc = -EIO;
> +		goto out;
> +	}
>  	memcpy(key_token, t, t->len);
>  	*key_token_size = t->len;

[Severity: High]
This isn't a bug introduced by this patch, but since you are fixing the
unvalidated length field from the device reply here, should similar validation
be added to cca_gencipherkey() and _ep11_genaeskey()?

In drivers/s390/crypto/zcrypt_ccamisc.c:cca_gencipherkey(), the code reads
the generated token length directly from the untrusted reply and calculates
the copy length without checking bounds against the structure size:

    keybuflen = prepparm->kb.tlv1.len - 2 * sizeof(uint16_t);
    ...
    if (keybuf) {
        if (*keybufsize >= keybuflen)
            memcpy(keybuf, t, keybuflen);

Could a malicious or compromised device return an inflated length, causing
memcpy() to read thousands of bytes out-of-bounds from the cprbmem
allocation and potentially leak kernel memory to userspace?

A similar unvalidated copy appears in
drivers/s390/crypto/zcrypt_ep11misc.c:_ep11_genaeskey(), which relies entirely
on the untrusted device data length:

    memcpy(keybuf, rep_pl->data, rep_pl->data_len);

[Severity: High]
This is a pre-existing issue, but does a similar vulnerability exist in
drivers/s390/crypto/zcrypt_ccamisc.c:cca_query_crypto_facility() where the
unvalidated length field is used to advance a memory pointer?

In that function, the code blindly advances ptr using an unchecked length
provided by the device payload:

    len = *((u16 *)ptr);
    if (len > sizeof(u16)) {
        ...
        ptr += len;
    }

If the hardware returns a corrupt or malicious length, could ptr advance
far beyond the cprbmem buffer bounds, leading to an out-of-bounds dereference
on the next iteration or exposing arbitrary kernel memory during the
subsequent memcpy()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260820140439.892324-2-dengler@linux.ibm.com?part=1

  reply	other threads:[~2026-08-20 14:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-20 14:04 [PATCH v1 0/1] 390/zcrypt: Validate length information in reply Holger Dengler
2026-08-20 14:04 ` [PATCH v1 1/1] s390/zcrypt: Validate length in reply before using it Holger Dengler
2026-08-20 14:20   ` sashiko-bot [this message]
2026-08-20 15:40     ` Holger Dengler
2026-08-20 14:46   ` Harald Freudenberger
2026-08-20 15:04     ` Holger Dengler

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=20260820142043.F40931F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=dengler@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-s390@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.