* [PATCH v6 0/2] Improve code in zcrypt msg type 6 handling
@ 2026-07-27 8:31 Harald Freudenberger
2026-07-27 8:31 ` [PATCH v6 1/2] s390/zcrypt: Improve CCA CPRB length and overflow checks Harald Freudenberger
2026-07-27 8:32 ` [PATCH v6 2/2] s390/zcrypt: Improve EP11 " Harald Freudenberger
0 siblings, 2 replies; 7+ messages in thread
From: Harald Freudenberger @ 2026-07-27 8:31 UTC (permalink / raw)
To: dengler, fcallies
Cc: freude, linux-s390, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev
Rework the limit and overflow checks in the both functions
xcrb_msg_to_type6_ep11cprb_msgx() and xcrb_msg_to_type6cprb_msgx().
Changelog:
v1: initial version, one patch dealing with overflow checks around
the use of the CEIL4 macro in zcrypt_msgtype6.c
v2: Sashiko found a regression: The check
if (ap_msg->len > ap_msg->bufsize)
was missing in the rework. Added again this important check.
v3: - Split into two patches - one for CCA one for EP11
- rework upper limit/overflow check
- add lower limit check
v4: - tried to address all the remaining complains from sashiko.
v5: - Yea, sashiko still found out that the min req size needs
to take the minimal payload header into account. Fixed.
v6: - And finally add padding zeros when there is a gap between
user space provided message size and rounded message size
in kernel.
Harald Freudenberger (2):
s390/zcrypt: Improve CCA CPRB length and overflow checks
s390/zcrypt: Improve EP11 CPRB length and overflow checks
drivers/s390/crypto/zcrypt_msgtype6.c | 101 ++++++++++++++------------
1 file changed, 55 insertions(+), 46 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v6 1/2] s390/zcrypt: Improve CCA CPRB length and overflow checks
2026-07-27 8:31 [PATCH v6 0/2] Improve code in zcrypt msg type 6 handling Harald Freudenberger
@ 2026-07-27 8:31 ` Harald Freudenberger
2026-07-27 8:47 ` sashiko-bot
2026-07-27 12:11 ` Holger Dengler
2026-07-27 8:32 ` [PATCH v6 2/2] s390/zcrypt: Improve EP11 " Harald Freudenberger
1 sibling, 2 replies; 7+ messages in thread
From: Harald Freudenberger @ 2026-07-27 8:31 UTC (permalink / raw)
To: dengler, fcallies
Cc: freude, linux-s390, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev
The xcrb_msg_to_type6cprb_msgx() function lacks proper input
validation, creating security vulnerabilities:
1. Integer overflow after CEIL4 alignment: Signed int variables could
overflow during 4-byte boundary alignment, causing undersized
buffer allocations or incorrect bounds checking.
2. Missing minimum size validation: The CPRBX structure is copied from
userspace without verifying sufficient buffer length. Undersized
buffers cause uninitialized memory access when reading structure
fields like cprbx.cprb_len and cprbx.domain.
3. Arithmetic overflow in sum calculations: Adding control block and
data block sizes could overflow, bypassing size checks and enabling
buffer overflows.
4. Potential kernel memory leak if copy_from_user() only copies
xcrb->request_control_blk_length bytes but the processing of the
message works with the rounded up to 4 byte boundary buffer size.
Fix by using size_t for length calculations, adding U32_MAX boundary
checks after alignment, validating minimum control block size before
copying from userspace, and detecting sum calculation overflows. Fix
the possible kernel memory leak by zeroing the trailing bytes.
Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
---
drivers/s390/crypto/zcrypt_msgtype6.c | 77 +++++++++++++--------------
1 file changed, 37 insertions(+), 40 deletions(-)
diff --git a/drivers/s390/crypto/zcrypt_msgtype6.c b/drivers/s390/crypto/zcrypt_msgtype6.c
index 40f72cdf284d..2e4aef330b68 100644
--- a/drivers/s390/crypto/zcrypt_msgtype6.c
+++ b/drivers/s390/crypto/zcrypt_msgtype6.c
@@ -342,49 +342,40 @@ static int xcrb_msg_to_type6cprb_msgx(bool userspace, struct ap_message *ap_msg,
};
} __packed * msg = ap_msg->msg;
- int rcblen = CEIL4(xcrb->request_control_blk_length);
- int req_sumlen, resp_sumlen;
- char *req_data = ap_msg->msg + sizeof(struct type6_hdr) + rcblen;
- char *function_code;
+ size_t req_cblen, rep_cblen, req_sumlen, rep_sumlen;
+ char *function_code, *req_data;
- if (CEIL4(xcrb->request_control_blk_length) <
- xcrb->request_control_blk_length)
- return -EINVAL; /* overflow after alignment*/
-
- /* length checks */
+ /* request length and overflow checks */
+ if (xcrb->request_control_blk_length < sizeof(struct CPRBX))
+ return -EINVAL;
+ req_cblen = CEIL4((size_t)xcrb->request_control_blk_length);
+ if (req_cblen > U32_MAX)
+ return -EINVAL;
ap_msg->len = sizeof(struct type6_hdr) +
- CEIL4(xcrb->request_control_blk_length) +
- xcrb->request_data_length;
+ req_cblen + xcrb->request_data_length;
if (ap_msg->len > ap_msg->bufsize)
return -EINVAL;
-
- /*
- * Overflow check
- * sum must be greater (or equal) than the largest operand
- */
- req_sumlen = CEIL4(xcrb->request_control_blk_length) +
- xcrb->request_data_length;
- if ((CEIL4(xcrb->request_control_blk_length) <=
- xcrb->request_data_length) ?
+ req_sumlen = req_cblen + xcrb->request_data_length;
+ if (req_sumlen > U32_MAX)
+ return -EINVAL;
+ if (req_cblen <= xcrb->request_data_length ?
req_sumlen < xcrb->request_data_length :
- req_sumlen < CEIL4(xcrb->request_control_blk_length)) {
+ req_sumlen < req_cblen) {
return -EINVAL;
}
- if (CEIL4(xcrb->reply_control_blk_length) <
- xcrb->reply_control_blk_length)
- return -EINVAL; /* overflow after alignment*/
-
- /*
- * Overflow check
- * sum must be greater (or equal) than the largest operand
- */
- resp_sumlen = CEIL4(xcrb->reply_control_blk_length) +
- xcrb->reply_data_length;
- if ((CEIL4(xcrb->reply_control_blk_length) <=
- xcrb->reply_data_length) ?
- resp_sumlen < xcrb->reply_data_length :
- resp_sumlen < CEIL4(xcrb->reply_control_blk_length)) {
+ /* reply length and overflow checks */
+ if (xcrb->reply_control_blk_length < sizeof(struct CPRBX))
+ return -EINVAL;
+ rep_cblen = CEIL4((size_t)xcrb->reply_control_blk_length);
+ if (rep_cblen > U32_MAX)
+ return -EINVAL;
+ rep_sumlen = rep_cblen + xcrb->reply_data_length;
+ if (rep_sumlen > U32_MAX)
+ return -EINVAL;
+ if (rep_cblen <= xcrb->reply_data_length ?
+ rep_sumlen < xcrb->reply_data_length :
+ rep_sumlen < rep_cblen) {
return -EINVAL;
}
@@ -393,7 +384,7 @@ static int xcrb_msg_to_type6cprb_msgx(bool userspace, struct ap_message *ap_msg,
memcpy(msg->hdr.agent_id, &xcrb->agent_ID, sizeof(xcrb->agent_ID));
msg->hdr.tocardlen1 = xcrb->request_control_blk_length;
if (xcrb->request_data_length) {
- msg->hdr.offset2 = msg->hdr.offset1 + rcblen;
+ msg->hdr.offset2 = msg->hdr.offset1 + req_cblen;
msg->hdr.tocardlen2 = xcrb->request_data_length;
}
msg->hdr.fromcardlen1 = xcrb->reply_control_blk_length;
@@ -404,6 +395,9 @@ static int xcrb_msg_to_type6cprb_msgx(bool userspace, struct ap_message *ap_msg,
xcrb->request_control_blk_addr,
xcrb->request_control_blk_length))
return -EFAULT;
+ if (xcrb->request_control_blk_length < req_cblen)
+ memset(msg->userdata + xcrb->request_control_blk_length,
+ 0, req_cblen - xcrb->request_control_blk_length);
if (msg->cprbx.cprb_len + sizeof(msg->hdr.function_code) >
xcrb->request_control_blk_length)
return -EINVAL;
@@ -437,10 +431,13 @@ static int xcrb_msg_to_type6cprb_msgx(bool userspace, struct ap_message *ap_msg,
}
/* copy data block */
- if (xcrb->request_data_length &&
- z_copy_from_user(userspace, req_data, xcrb->request_data_address,
- xcrb->request_data_length))
- return -EFAULT;
+ if (xcrb->request_data_length) {
+ req_data = ap_msg->msg + sizeof(struct type6_hdr) + req_cblen;
+ if (z_copy_from_user(userspace, req_data,
+ xcrb->request_data_address,
+ xcrb->request_data_length))
+ return -EFAULT;
+ }
return 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v6 2/2] s390/zcrypt: Improve EP11 CPRB length and overflow checks
2026-07-27 8:31 [PATCH v6 0/2] Improve code in zcrypt msg type 6 handling Harald Freudenberger
2026-07-27 8:31 ` [PATCH v6 1/2] s390/zcrypt: Improve CCA CPRB length and overflow checks Harald Freudenberger
@ 2026-07-27 8:32 ` Harald Freudenberger
2026-07-27 8:45 ` sashiko-bot
2026-07-27 12:14 ` Holger Dengler
1 sibling, 2 replies; 7+ messages in thread
From: Harald Freudenberger @ 2026-07-27 8:32 UTC (permalink / raw)
To: dengler, fcallies
Cc: freude, linux-s390, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev
The xcrb_msg_to_type6_ep11cprb_msgx() function lacks proper input
validation, creating security vulnerabilities:
1. Missing minimum size validation: The ep11_cprb structure and
subsequent payload fields (pld_tag, pld_lenfmt) are copied from
userspace without verifying sufficient buffer length.
2. Arithmetic overflow in length calculations: CEIL4 alignment could
overflow, bypassing size checks and enabling buffer overflows.
3. There was a gap between the message size copied from user space and
the message buffer sent down to the card. The msg buffer size is
rounded up to 4 byte boundary.
Fix by using size_t for length calculations, adding U32_MAX boundary
checks after alignment, and validating minimum request size and
minimum reply size before copying from userspace. Also pad the gap
between user space copied message and message buffer sent down to the
card by zeros.
Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
---
drivers/s390/crypto/zcrypt_msgtype6.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/drivers/s390/crypto/zcrypt_msgtype6.c b/drivers/s390/crypto/zcrypt_msgtype6.c
index 2e4aef330b68..f4cca7fcaeea 100644
--- a/drivers/s390/crypto/zcrypt_msgtype6.c
+++ b/drivers/s390/crypto/zcrypt_msgtype6.c
@@ -477,16 +477,25 @@ static int xcrb_msg_to_type6_ep11cprb_msgx(bool userspace, struct ap_message *ap
unsigned int dom_val; /* domain id */
} __packed * payload_hdr = NULL;
- if (CEIL4(xcrb->req_len) < xcrb->req_len)
- return -EINVAL; /* overflow after alignment*/
+ size_t req_len, rep_len;
- /* length checks */
- ap_msg->len = sizeof(struct type6_hdr) + CEIL4(xcrb->req_len);
+ /* request length and overflow checks */
+ if (xcrb->req_len < sizeof(struct ep11_cprb) +
+ 2 * sizeof(unsigned char) + sizeof(struct pld_hdr))
+ return -EINVAL;
+ req_len = CEIL4(xcrb->req_len);
+ if (req_len < xcrb->req_len || req_len > U32_MAX)
+ return -EINVAL;
+ ap_msg->len = sizeof(struct type6_hdr) + req_len;
if (ap_msg->len > ap_msg->bufsize)
return -EINVAL;
- if (CEIL4(xcrb->resp_len) < xcrb->resp_len)
- return -EINVAL; /* overflow after alignment*/
+ /* reply length and overflow checks */
+ if (xcrb->resp_len < sizeof(struct ep11_cprb))
+ return -EINVAL;
+ rep_len = CEIL4(xcrb->resp_len);
+ if (rep_len < xcrb->resp_len || rep_len > U32_MAX)
+ return -EINVAL;
/* prepare type6 header */
msg->hdr = static_type6_ep11_hdr;
@@ -498,6 +507,9 @@ static int xcrb_msg_to_type6_ep11cprb_msgx(bool userspace, struct ap_message *ap
(char __force __user *)xcrb->req, xcrb->req_len)) {
return -EFAULT;
}
+ if (xcrb->req_len < req_len)
+ memset(msg->userdata + xcrb->req_len, 0,
+ req_len - xcrb->req_len);
if ((msg->pld_lenfmt & 0x80) == 0x80) { /*ext.len.fmt 2 or 3*/
switch (msg->pld_lenfmt & 0x03) {
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v6 2/2] s390/zcrypt: Improve EP11 CPRB length and overflow checks
2026-07-27 8:32 ` [PATCH v6 2/2] s390/zcrypt: Improve EP11 " Harald Freudenberger
@ 2026-07-27 8:45 ` sashiko-bot
2026-07-27 12:14 ` Holger Dengler
1 sibling, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-07-27 8:45 UTC (permalink / raw)
To: Harald Freudenberger
Cc: Vasily Gorbik, linux-s390, Alexander Gordeev, Heiko Carstens
> The xcrb_msg_to_type6_ep11cprb_msgx() function lacks proper input
> validation, creating security vulnerabilities:
> 1. Missing minimum size validation: The ep11_cprb structure and
> subsequent payload fields (pld_tag, pld_lenfmt) are copied from
> userspace without verifying sufficient buffer length.
> 2. Arithmetic overflow in length calculations: CEIL4 alignment could
> overflow, bypassing size checks and enabling buffer overflows.
> 3. There was a gap between the message size copied from user space and
> the message buffer sent down to the card. The msg buffer size is
> rounded up to 4 byte boundary.
>
> Fix by using size_t for length calculations, adding U32_MAX boundary
> checks after alignment, and validating minimum request size and
> minimum reply size before copying from userspace. Also pad the gap
> between user space copied message and message buffer sent down to the
> card by zeros.
>
> Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260727083200.151976-1-freude@linux.ibm.com?part=2
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v6 1/2] s390/zcrypt: Improve CCA CPRB length and overflow checks
2026-07-27 8:31 ` [PATCH v6 1/2] s390/zcrypt: Improve CCA CPRB length and overflow checks Harald Freudenberger
@ 2026-07-27 8:47 ` sashiko-bot
2026-07-27 12:11 ` Holger Dengler
1 sibling, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-07-27 8:47 UTC (permalink / raw)
To: Harald Freudenberger
Cc: Heiko Carstens, Alexander Gordeev, linux-s390, Vasily Gorbik
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Integer overflow in `xcrb_msg_to_type6_ep11cprb_msgx` allows bypassing message length checks, leading to an out-of-bounds `memset` in `copy_from_user` that panics the kernel.
- [High] Missing minimum size validation in `xcrb_msg_to_type6_ep11cprb_msgx` allows uninitialized memory access.
- [High] Kernel memory leak via uninitialized alignment padding bytes in `xcrb_msg_to_type6_ep11cprb_msgx`.
- [High] The driver trusts length and offset values (`offset1`, `count1`) from the hardware's type86_fmt2 message without fully checking them against the received message length, which can lead to an out-of-bounds kernel memory read.
--
--- Patch [1]: [PATCH v6 1/2] s390/zcrypt: Improve CCA CPRB length and overflow checks ---
commit 7784ed33ea5e9edca90b3daa3295185e1ce64459
Author: Harald Freudenberger <freude@linux.ibm.com>
s390/zcrypt: Improve CCA CPRB length and overflow checks
The xcrb_msg_to_type6cprb_msgx() function lacks proper input validation,
creating several security vulnerabilities including integer overflows, missing
minimum size validations, and a potential kernel memory leak. This patch fixes
these issues by using size_t for length calculations, adding boundary checks,
and zeroing trailing bytes.
> diff --git a/drivers/s390/crypto/zcrypt_msgtype6.c b/drivers/s390/crypto/zcrypt_msgtype6.c
> index 40f72cdf284d3..2e4aef330b680 100644
> --- a/drivers/s390/crypto/zcrypt_msgtype6.c
> +++ b/drivers/s390/crypto/zcrypt_msgtype6.c
> @@ -342,49 +342,40 @@ static int xcrb_msg_to_type6cprb_msgx(bool userspace, struct ap_message *ap_msg,
[ ... ]
> - if (CEIL4(xcrb->request_control_blk_length) <
> - xcrb->request_control_blk_length)
> - return -EINVAL; /* overflow after alignment*/
> -
> - /* length checks */
> + /* request length and overflow checks */
> + if (xcrb->request_control_blk_length < sizeof(struct CPRBX))
> + return -EINVAL;
[Severity: High]
This isn't a bug introduced by this patch, but it appears a similar missing
minimum size validation exists in xcrb_msg_to_type6_ep11cprb_msgx().
Can a small req_len (e.g., 0) cause reads of uninitialized kernel heap memory
when extracting fields like pld_lenfmt or flags?
drivers/s390/crypto/zcrypt_msgtype6.c:xcrb_msg_to_type6_ep11cprb_msgx() {
...
if ((msg->pld_lenfmt & 0x80) == 0x80) {
...
}
> + req_cblen = CEIL4((size_t)xcrb->request_control_blk_length);
> + if (req_cblen > U32_MAX)
> + return -EINVAL;
> ap_msg->len = sizeof(struct type6_hdr) +
> - CEIL4(xcrb->request_control_blk_length) +
> - xcrb->request_data_length;
> + req_cblen + xcrb->request_data_length;
> if (ap_msg->len > ap_msg->bufsize)
> return -EINVAL;
[Severity: Critical]
This is a pre-existing issue, but it looks like xcrb_msg_to_type6_ep11cprb_msgx()
has an integer overflow similar to the one fixed in this patch.
Can a massive req_len cause an integer overflow when computing ap_msg->len,
bypassing the ap_msg->bufsize bounds check?
drivers/s390/crypto/zcrypt_msgtype6.c:xcrb_msg_to_type6_ep11cprb_msgx() {
...
ap_msg->len = sizeof(struct type6_hdr) + CEIL4(xcrb->req_len);
...
if (z_copy_from_user(userspace, msg->userdata,
(char __force __user *)xcrb->req, xcrb->req_len)) {
...
}
If z_copy_from_user() is called with the large length, the copy_from_user()
fallback memset could write outside the allocated kernel buffer.
[ ... ]
> @@ -404,6 +395,9 @@ static int xcrb_msg_to_type6cprb_msgx(bool userspace, struct ap_message *ap_msg,
> xcrb->request_control_blk_addr,
> xcrb->request_control_blk_length))
> return -EFAULT;
> + if (xcrb->request_control_blk_length < req_cblen)
> + memset(msg->userdata + xcrb->request_control_blk_length,
> + 0, req_cblen - xcrb->request_control_blk_length);
[Severity: High]
This is a pre-existing issue, but does xcrb_msg_to_type6_ep11cprb_msgx() leak
kernel memory via uninitialized alignment padding bytes in a similar way?
The buffer length sent to the hardware incorporates alignment, but only req_len
bytes are copied, leaving padding bytes uninitialized:
drivers/s390/crypto/zcrypt_msgtype6.c:xcrb_msg_to_type6_ep11cprb_msgx() {
...
if (z_copy_from_user(userspace, msg->userdata,
(char __force __user *)xcrb->req, xcrb->req_len)) {
...
}
[ ... ]
> @@ -437,10 +431,13 @@ static int xcrb_msg_to_type6cprb_msgx(bool userspace, struct ap_message *ap_msg,
> }
>
> /* copy data block */
> - if (xcrb->request_data_length &&
> - z_copy_from_user(userspace, req_data, xcrb->request_data_address,
> - xcrb->request_data_length))
> - return -EFAULT;
> + if (xcrb->request_data_length) {
> + req_data = ap_msg->msg + sizeof(struct type6_hdr) + req_cblen;
> + if (z_copy_from_user(userspace, req_data,
> + xcrb->request_data_address,
> + xcrb->request_data_length))
> + return -EFAULT;
> + }
>
> return 0;
> }
[Severity: High]
This isn't a bug introduced by this patch, but does convert_type86_xcrb()
trust length and offset values from the hardware without fully checking them?
zcrypt_msgtype6_receive() only validates offset2 and count2 if count2 is
non-zero, ignoring offset1 and count1 during the bounds check:
drivers/s390/crypto/zcrypt_msgtype6.c:zcrypt_msgtype6_receive() {
...
if (t86r->fmt2.count2)
len = t86r->fmt2.offset2 + t86r->fmt2.count2;
...
}
Later, convert_type86_xcrb() uses offset1 and count1 for a copy to user space
without verifying they are within the initialized message buffer:
drivers/s390/crypto/zcrypt_msgtype6.c:convert_type86_xcrb() {
...
if (z_copy_to_user(userspace, xcrb->reply_control_blk_addr,
data + msg->fmt2.offset1, msg->fmt2.count1))
...
}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260727083200.151976-1-freude@linux.ibm.com?part=1
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v6 1/2] s390/zcrypt: Improve CCA CPRB length and overflow checks
2026-07-27 8:31 ` [PATCH v6 1/2] s390/zcrypt: Improve CCA CPRB length and overflow checks Harald Freudenberger
2026-07-27 8:47 ` sashiko-bot
@ 2026-07-27 12:11 ` Holger Dengler
1 sibling, 0 replies; 7+ messages in thread
From: Holger Dengler @ 2026-07-27 12:11 UTC (permalink / raw)
To: Harald Freudenberger
Cc: fcallies, linux-s390, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev
On 7/27/26 10:31, Harald Freudenberger wrote:
> The xcrb_msg_to_type6cprb_msgx() function lacks proper input
> validation, creating security vulnerabilities:
> 1. Integer overflow after CEIL4 alignment: Signed int variables could
> overflow during 4-byte boundary alignment, causing undersized
> buffer allocations or incorrect bounds checking.
> 2. Missing minimum size validation: The CPRBX structure is copied from
> userspace without verifying sufficient buffer length. Undersized
> buffers cause uninitialized memory access when reading structure
> fields like cprbx.cprb_len and cprbx.domain.
> 3. Arithmetic overflow in sum calculations: Adding control block and
> data block sizes could overflow, bypassing size checks and enabling
> buffer overflows.
> 4. Potential kernel memory leak if copy_from_user() only copies
> xcrb->request_control_blk_length bytes but the processing of the
> message works with the rounded up to 4 byte boundary buffer size.
>
> Fix by using size_t for length calculations, adding U32_MAX boundary
> checks after alignment, validating minimum control block size before
> copying from userspace, and detecting sum calculation overflows. Fix
> the possible kernel memory leak by zeroing the trailing bytes.
The last sentence should go into a separate patch. See my comment below.
> Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
The length check looks good so far. Only the min-length check need some
rework (as discussed).
> ---
> drivers/s390/crypto/zcrypt_msgtype6.c | 77 +++++++++++++--------------
> 1 file changed, 37 insertions(+), 40 deletions(-)
>
> diff --git a/drivers/s390/crypto/zcrypt_msgtype6.c b/drivers/s390/crypto/zcrypt_msgtype6.c
> index 40f72cdf284d..2e4aef330b68 100644
> --- a/drivers/s390/crypto/zcrypt_msgtype6.c
> +++ b/drivers/s390/crypto/zcrypt_msgtype6.c
[...]
> @@ -404,6 +395,9 @@ static int xcrb_msg_to_type6cprb_msgx(bool userspace, struct ap_message *ap_msg,
> xcrb->request_control_blk_addr,
> xcrb->request_control_blk_length))
> return -EFAULT;
> + if (xcrb->request_control_blk_length < req_cblen)
> + memset(msg->userdata + xcrb->request_control_blk_length,
> + 0, req_cblen - xcrb->request_control_blk_length);
Can you please move this wipe into a separate patch? It is not related
to the input checking but addresses another class of vulnerability.
I think it is worth to describe this issue/fix in its own commit message.
> if (msg->cprbx.cprb_len + sizeof(msg->hdr.function_code) >
> xcrb->request_control_blk_length)
> return -EINVAL;[...]
--
Mit freundlichen Grüßen / Kind regards
Holger Dengler
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v6 2/2] s390/zcrypt: Improve EP11 CPRB length and overflow checks
2026-07-27 8:32 ` [PATCH v6 2/2] s390/zcrypt: Improve EP11 " Harald Freudenberger
2026-07-27 8:45 ` sashiko-bot
@ 2026-07-27 12:14 ` Holger Dengler
1 sibling, 0 replies; 7+ messages in thread
From: Holger Dengler @ 2026-07-27 12:14 UTC (permalink / raw)
To: Harald Freudenberger
Cc: fcallies, linux-s390, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev
On 7/27/26 10:32, Harald Freudenberger wrote:
> The xcrb_msg_to_type6_ep11cprb_msgx() function lacks proper input
> validation, creating security vulnerabilities:
> 1. Missing minimum size validation: The ep11_cprb structure and
> subsequent payload fields (pld_tag, pld_lenfmt) are copied from
> userspace without verifying sufficient buffer length.
> 2. Arithmetic overflow in length calculations: CEIL4 alignment could
> overflow, bypassing size checks and enabling buffer overflows.
> 3. There was a gap between the message size copied from user space and
> the message buffer sent down to the card. The msg buffer size is
> rounded up to 4 byte boundary.
>
> Fix by using size_t for length calculations, adding U32_MAX boundary
> checks after alignment, and validating minimum request size and
> minimum reply size before copying from userspace. Also pad the gap
> between user space copied message and message buffer sent down to the
> card by zeros.
>
> Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
> ---
> drivers/s390/crypto/zcrypt_msgtype6.c | 24 ++++++++++++++++++------
> 1 file changed, 18 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/s390/crypto/zcrypt_msgtype6.c b/drivers/s390/crypto/zcrypt_msgtype6.c
> index 2e4aef330b68..f4cca7fcaeea 100644
> --- a/drivers/s390/crypto/zcrypt_msgtype6.c
> +++ b/drivers/s390/crypto/zcrypt_msgtype6.c
[...]> @@ -498,6 +507,9 @@ static int
xcrb_msg_to_type6_ep11cprb_msgx(bool userspace, struct ap_message *ap
> (char __force __user *)xcrb->req, xcrb->req_len)) {
> return -EFAULT;
> }
> + if (xcrb->req_len < req_len)
> + memset(msg->userdata + xcrb->req_len, 0,
> + req_len - xcrb->req_len);
Same here, please move the memset to a separate patch.
(Maybe both wipes can go into one commit)
>
> if ((msg->pld_lenfmt & 0x80) == 0x80) { /*ext.len.fmt 2 or 3*/
> switch (msg->pld_lenfmt & 0x03) {
--
Mit freundlichen Grüßen / Kind regards
Holger Dengler
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-07-27 12:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-27 8:31 [PATCH v6 0/2] Improve code in zcrypt msg type 6 handling Harald Freudenberger
2026-07-27 8:31 ` [PATCH v6 1/2] s390/zcrypt: Improve CCA CPRB length and overflow checks Harald Freudenberger
2026-07-27 8:47 ` sashiko-bot
2026-07-27 12:11 ` Holger Dengler
2026-07-27 8:32 ` [PATCH v6 2/2] s390/zcrypt: Improve EP11 " Harald Freudenberger
2026-07-27 8:45 ` sashiko-bot
2026-07-27 12:14 ` Holger Dengler
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox