All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Harald Freudenberger" <freude@linux.ibm.com>
Cc: linux-s390@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>
Subject: Re: [PATCH v8 4/5] s390/zcrypt: Improve EP11 CPRB domain handling with ASN.1 parsing
Date: Wed, 29 Jul 2026 14:50:16 +0000	[thread overview]
Message-ID: <20260729145016.EB7061F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260729143928.191969-5-freude@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Undefined behavior due to unaligned memory access via direct pointer casting.
--

--- Patch [4]: [PATCH v8 4/5] s390/zcrypt: Improve EP11 CPRB domain handling with ASN.1 parsing ---
commit 78d69567226ac24ed3207a9812dbc20b238a13e1
Author: Harald Freudenberger <freude@linux.ibm.com>

s390/zcrypt: Improve EP11 CPRB domain handling with ASN.1 parsing

This commit replaces struct overlays with explicit ASN.1 parsing for
EP11 CPRB payload domain fields, adding validation and a new helper
function for safely encoding integer values.

> diff --git a/drivers/s390/crypto/zcrypt_msgtype6.c b/drivers/s390/crypto/zcrypt_msgtype6.c
> index c4b5d9b85f7a9..59e182d1bddf9 100644
> --- a/drivers/s390/crypto/zcrypt_msgtype6.c
> +++ b/drivers/s390/crypto/zcrypt_msgtype6.c
> @@ -1223,6 +1223,28 @@ int prep_ep11_ap_msg(bool userspace, struct ep11_urb *xcrb,
>  					       func_code, domain);
>  }
>  
> +/*
> + * Simple asn1 int writer/encoder helper function
> + * Returns number of bytes processed or < 0 on failure
> + * Only accepts int length values of 1, 2 or 4.
> + */
> +static inline int asn1_int_encode(u8 *buf, size_t intlen, u32 u)
> +{
> +	switch (intlen) {
> +	case 1:
> +		*((u8 *)buf) = (u8)u;
> +		return 1;
> +	case 2:
> +		*((u16 *)buf) = cpu_to_be16(u);

[Severity: Medium]
Could this lead to unaligned memory accesses?

When asn1_int_encode() is called from zcrypt_msgtype6_send_ep11_cprb()
using pld + offs, the offset is dynamically calculated from variable length
ASN.1 tags and lengths, which may leave the buf pointer unaligned.

While s390 hardware handles unaligned accesses, directly casting a potentially
unaligned u8 pointer to u16* could violate C standard alignment rules and
potentially lead to compiler misoptimization. Would it be safer to use
put_unaligned_be16() here?

> +		return 2;
> +	case 4:
> +		*((u32 *)buf) = cpu_to_be32(u);

[Severity: Medium]
Similarly, should this use put_unaligned_be32() instead of a direct cast
to u32* for the same unaligned pointer reasons?

> +		return 4;
> +	default:
> +		return -EINVAL;
> +	}
> +}

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260729143928.191969-1-freude@linux.ibm.com?part=4

  reply	other threads:[~2026-07-29 14:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29 14:39 [PATCH v8 0/5] Improve code in zcrypt msg type 6 handling Harald Freudenberger
2026-07-29 14:39 ` [PATCH v8 1/5] s390/zcrypt: Fix CPRB memory allocation in zcrypt misc code Harald Freudenberger
2026-07-29 14:52   ` sashiko-bot
2026-07-29 15:10     ` Harald Freudenberger
2026-07-29 14:39 ` [PATCH v8 2/5] s390/zcrypt: Improve CCA CPRB length and overflow checks Harald Freudenberger
2026-07-29 14:59   ` sashiko-bot
2026-07-29 15:11     ` Harald Freudenberger
2026-07-29 14:39 ` [PATCH v8 3/5] s390/zcrypt: Improve EP11 " Harald Freudenberger
2026-07-29 14:52   ` sashiko-bot
2026-07-29 14:39 ` [PATCH v8 4/5] s390/zcrypt: Improve EP11 CPRB domain handling with ASN.1 parsing Harald Freudenberger
2026-07-29 14:50   ` sashiko-bot [this message]
2026-07-29 15:25     ` Harald Freudenberger
2026-07-29 14:39 ` [PATCH v8 5/5] s390/zcrypt: Pad trailing CCA or EP11 message with zeros Harald Freudenberger
2026-07-29 15:00   ` 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=20260729145016.EB7061F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=freude@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.