6.18.57-rc1 review
Subsystems (4)
Greg Kroah-Hartman
maintainerPATCH 612/621 s390/zcrypt: Improve CCA CPRB length and overflow checks
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harald Freudenberger <[email protected]>
commit 35ac6754ba6da45fd193f5ce3f665f7490b830d5 upstream.
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.
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.
--- drivers/s390/crypto/zcrypt_msgtype6.c | 81 +++++++++++++++------------------- 1 file changed, 37 insertions(+), 44 deletions(-)
drivers/s390/crypto/zcrypt_msgtype6.c +37 -44
@@ -343,49 +343,39 @@ static int xcrb_msg_to_type6cprb_msgx(bo }; }__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; - -if (CEIL4 (xcrb->request_control_blk_length) < - xcrb->request_control_blk_length) -return -EINVAL ;/* overflow after alignment*/ - -/* length checks */ - ap_msg->len =sizeof (struct type6_hdr ) + -CEIL4 (xcrb->request_control_blk_length) + - xcrb->request_data_length; +size_t req_cblen, rep_cblen, req_sumlen, rep_sumlen; +char *function_code, *req_data; + +/* 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 ; + req_sumlen = req_cblen + xcrb->request_data_length; +if (req_sumlen >U32_MAX ) +return -EINVAL ; + ap_msg->len =sizeof (struct type6_hdr ) + req_sumlen;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) ? +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 ; }
@@ -394,7 +384,7 @@ static int xcrb_msg_to_type6cprb_msgx(bomemcpy (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;
@@ -405,8 +395,8 @@ static int xcrb_msg_to_type6cprb_msgx(bo xcrb->request_control_blk_addr, xcrb->request_control_blk_length))return -EFAULT ; -if (msg->cprbx.cprb_len +sizeof (msg->hdr.function_code) > - xcrb->request_control_blk_length) +/* copy subfunction code into AP msg type 6 function code field */ +if (msg->cprbx.cprb_len > req_cblen -sizeof (msg->hdr.function_code))return -EINVAL ; function_code = ((unsigned char *)&msg->cprbx) + msg->cprbx.cprb_len; memcpy(msg->hdr.function_code, function_code,
@@ -438,10 +428,13 @@ static int xcrb_msg_to_type6cprb_msgx(bo }/* 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 ; }
Greg Kroah-Hartman
maintainerPATCH 613/621 s390/zcrypt: Improve EP11 CPRB length and overflow checks
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harald Freudenberger <[email protected]>
commit 17ac0bc866fc624cd05f022dcd8b730c0af11bb1 upstream.
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. The payload is asn1 encoded but the function just uses a simple c struct overlay to access some fields of the payload.
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. Do a very simple asn1 parsing of the payload up to the function value field.
--- drivers/s390/crypto/zcrypt_msgtype6.c | 152 +++++++++++++++++++++++++--------- 1 file changed, 113 insertions(+), 39 deletions(-)
drivers/s390/crypto/zcrypt_msgtype6.c +113 -39
@@ -20,6 +20,7 @@#include <linux/slab.h> #include <linux/atomic.h> #include <linux/uaccess.h> +#include <linux/unaligned.h> #include "ap_bus.h" #include "zcrypt_api.h"
@@ -35,6 +36,9 @@#define CEXXC_RESPONSE_TYPE_XCRB 1#define CEXXC_RESPONSE_TYPE_EP11 2 +/* smallest possible EP11 payload size */ +#define MIN_EP11_PAYLOAD_SIZE 5 +MODULE_AUTHOR ("IBM Corporation" );MODULE_DESCRIPTION ("Cryptographic Coprocessor (message type 6), " \"Copyright IBM Corp. 2001, 2023" );
@@ -439,12 +443,59 @@ static int xcrb_msg_to_type6cprb_msgx(boreturn 0 ; } +/* +* Simple asn1 int reader/decoder 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_decode (const u8 *buf,size_t intlen,u32 *u) +{ +switch (intlen) { +case 1 : + *u = (u32)(*buf); +return 1 ; +case 2 : + *u = (u32 )get_unaligned_be16 (buf); +return 2 ; +case 4 : + *u = (u32 )get_unaligned_be32 (buf); +return 4 ; +default : +return -EINVAL ; + } +} + +/* +* Simple asn1 length parse helper function +* Returns number of bytes processed or < 0 on failure +* Only accepts length encoded within the length octet +* or for long form 1, 2 or 4 octet length bytes. +*/ +static inline int asn1_length_decode (const u8 *buf,size_t buflen,u32 *u) +{ +int i; + +if (buflen <1 ) +return -EINVAL ; + +if (*buf <128 ) { + *u = (u32)(*buf &0x7F ); +return 1 ; + } + + i = *buf &0x7F ; +if (--buflen < i) +return -EINVAL ; + i =asn1_int_decode (++buf, i, u); + +return i <0 ? i : i +1 ; +} +static int xcrb_msg_to_type6_ep11cprb_msgx (bool userspace,struct ap_message *ap_msg,struct ep11_urb *xcrb,unsigned int *fcode,unsigned int *domain) { -unsigned int lfmt;static struct type6_hdr static_type6_ep11_hdr = { .type =0x06 , .rqid = {0x00 ,0x01 },
@@ -457,34 +508,32 @@ static int xcrb_msg_to_type6_ep11cprb_msstruct {struct type6_hdr hdr;union { -struct { -struct ep11_cprb cprbx; -unsigned char pld_tag;/* fixed value 0x30 */ -unsigned char pld_lenfmt;/* length format */ - } __packed; +struct ep11_cprb cprbx; DECLARE_FLEX_ARRAY(u8, userdata); }; } __packed * msg = ap_msg->msg; -struct pld_hdr { -unsigned char func_tag;/* fixed value 0x4 */ -unsigned char func_len;/* fixed value 0x4 */ -unsigned int func_val;/* function ID */ -unsigned char dom_tag;/* fixed value 0x4 */ -unsigned char dom_len;/* fixed value 0x4 */ -unsigned int dom_val;/* domain id */ - } __packed * payload_hdr = NULL; +size_t req_len, rep_len, pld_len; +unsigned char *pld; +int offs =0 , i; +unsigned int u; -if (CEIL4 (xcrb->req_len) < xcrb->req_len) -return -EINVAL ;/* overflow after alignment*/ - -/* 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 ) +MIN_EP11_PAYLOAD_SIZE ) +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;
@@ -493,26 +542,51 @@ static int xcrb_msg_to_type6_ep11cprb_ms/* Import CPRB data from the ioctl input parameter */ if (z_copy_from_user (userspace, msg->userdata, - (char __force __user *)xcrb->req, xcrb->req_len)) { + (char __force __user *)xcrb->req, xcrb->req_len))return -EFAULT ; - } -if ((msg->pld_lenfmt &0x80 ) ==0x80 ) {/*ext.len.fmt 2 or 3*/ -switch (msg->pld_lenfmt &0x03 ) { -case 1 : - lfmt =2 ; -break ; -case 2 : - lfmt =3 ; -break ; -default : -return -EINVAL ; - } - }else { - lfmt =1 ;/* length format #1 */ - } - payload_hdr = (struct pld_hdr *)((&msg->pld_lenfmt) + lfmt); - *fcode = payload_hdr->func_val &0xFFFF ; + pld = msg->userdata +sizeof (struct ep11_cprb ); + pld_len = msg->cprbx.payload_len; +if (pld_len != xcrb->req_len -sizeof (struct ep11_cprb )) +return -EINVAL ; +/* +* At this point pld_len is always >= MIN_EP11_PAYLOAD_SIZE +* and the smallest supported asn1 payload is: +* payload tag (1 octet) +* payload length (1-5 octets) +* function tag (1 octet) +* function length (1-5 octets) +* function value (1-4 octets) +*/ + +/* payload tag */ +if (pld[offs++] !=0x30 ) +return -EINVAL ; +/* payload length field */ + i =asn1_length_decode (pld + offs, pld_len - offs, &u); +if (i <0 ) +return -EINVAL ; + offs += i; +if (offs >= pld_len || u > pld_len - offs) +return -EINVAL ; +/* function tag */ +if (pld[offs++] !=0x04 ) +return -EINVAL ; +/* function length */ +if (offs >= pld_len) +return -EINVAL ; + i =asn1_length_decode (pld + offs, pld_len - offs, &u); +if (i <0 ) +return -EINVAL ; + offs += i; +if (offs >= pld_len || u > pld_len - offs) +return -EINVAL ; +/* function value */ + i =asn1_int_decode (pld + offs, u, &u); +if (i <0 ) +return -EINVAL ; + offs += i; + *fcode =0xFFFF & u;/* enable special processing based on the cprbs flags special bit */ if (msg->cprbx.flags &0x20 )
Greg Kroah-Hartman
maintainerPATCH 614/621 s390/zcrypt: Improve EP11 CPRB domain handling with ASN.1 parsing
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harald Freudenberger <[email protected]>
commit 0864a163783bff109b548266921829ea794edc93 upstream.
The zcrypt_msgtype6_send_ep11_cprb() function uses fragile struct overlays to access and modify the domain field in the EP11 CPRB payload, creating maintainability and security concerns:
1. Struct overlay approach (pld_hdr) assumes fixed payload structure and doesn't validate the actual ASN.1 encoding.
2. Complex length format detection logic is error-prone and doesn't properly validate bounds at each parsing step.
3. Direct struct member access bypasses proper ASN.1 validation.
Fix by replacing struct overlays with explicit ASN.1 parsing that validates each field (payload tag/length, function tag/length/value, optional domain tag/length/value) with proper bounds checking at every step. Add asn1_int_encode() helper function to safely write integer values with correct endianness conversion. This makes the code consistent with the validation pattern introduced with the rework of the xcrb_msg_to_type6_ep11cprb_msgx() function.
--- drivers/s390/crypto/zcrypt_msgtype6.c | 127 +++++++++++++++++++++++++--------- 1 file changed, 96 insertions(+), 31 deletions(-)
drivers/s390/crypto/zcrypt_msgtype6.c +96 -31
@@ -1229,6 +1229,28 @@ int prep_ep11_ap_msg(bool userspace, str }/* +* 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 : + *buf = (u8 )u; +return 1 ; +case 2 : +put_unaligned_be16 ((u16 )u, buf); +return 2 ; +case 4 : +put_unaligned_be32 ((u32 )u, buf); +return 4 ; +default : +return -EINVAL ; + } +} + +/* * The request distributor calls this function if it picked the CEX4P * device to handle a send_ep11_cprb request. * @zq: pointer to zcrypt_queue structure that identifies the
@@ -1240,51 +1262,94 @@ static long zcrypt_msgtype6_send_ep11_cp struct ap_message *ap_msg) {int rc; -unsigned int lfmt;struct ap_response_type *resp_type = &ap_msg->response;struct {struct type6_hdr hdr;struct ep11_cprb cprbx; -unsigned char pld_tag;/* fixed value 0x30 */ -unsigned char pld_lenfmt;/* payload length format */ } __packed * msg = ap_msg->msg; -struct pld_hdr { -unsigned char func_tag;/* fixed value 0x4 */ -unsigned char func_len;/* fixed value 0x4 */ -unsigned int func_val;/* function ID */ -unsigned char dom_tag;/* fixed value 0x4 */ -unsigned char dom_len;/* fixed value 0x4 */ -unsigned int dom_val;/* domain id */ - } __packed * payload_hdr = NULL;/* * The target domain field within the cprb body/payload block will be * replaced by the usage domain for non-management commands only. * Therefore we check the first bit of the 'flags' parameter for * management command indication. -* 0 - non management command -* 1 - management command */ -if (!((msg->cprbx.flags &0x80 ) ==0x80 )) { - msg->cprbx.target_id = (unsigned int ) -AP_QID_QUEUE (zq->queue->qid); - -if ((msg->pld_lenfmt &0x80 ) ==0x80 ) {/*ext.len.fmt 2 or 3*/ -switch (msg->pld_lenfmt &0x03 ) { -case 1 : - lfmt =2 ; -break ; -case 2 : - lfmt =3 ; -break ; -default : +if (!(msg->cprbx.flags &0x80 )) { +int i, offs =0 ; +size_t pld_len; +u8 *pld; +u32 u; + +/* update target field in ep11_cprb */ + msg->cprbx.target_id = (u32 )AP_QID_QUEUE (zq->queue->qid); + +/* ptr and length to payload */ + pld = ap_msg->msg + +sizeof (struct type6_hdr ) +sizeof (struct ep11_cprb ); + pld_len = msg->cprbx.payload_len; +if (pld_len <MIN_EP11_PAYLOAD_SIZE ) +return -EINVAL ; + +/* +* Parse the asn1 payload, at least we have +* pld tag (1 octet) +* payload length (1-5 octets) +* function tag (1 octet) +* function length (1-5 octets) +* function value (1-4 octets) +* ----- optional fields ----- +* domain tag (1 octet) +* domain length (1-5 octets) +* domain value (1-4 octets) +* ... maybe much more data ... +*/ + +/* payload tag */ +if (pld[offs++] !=0x30 ) +return -EINVAL ; +/* payload length field */ + i =asn1_length_decode (pld + offs, pld_len - offs, &u); +if (i <0 ) +return -EINVAL ; + offs += i; +if (offs >= pld_len || u > pld_len - offs) +return -EINVAL ; +/* function tag */ +if (pld[offs++] !=0x04 ) +return -EINVAL ; +/* function length */ +if (offs >= pld_len) +return -EINVAL ; + i =asn1_length_decode (pld + offs, pld_len - offs, &u); +if (i <0 ) +return -EINVAL ; + offs += i; +if (u > pld_len - offs) +return -EINVAL ; +/* skip over the function value */ + offs += u; +/* is there some payload left which could hold a domain value ? */ +if (offs < pld_len && pld_len - offs >=3 ) { +/* domain tag */ +if (pld[offs++] !=0x04 ) +return -EINVAL ; +/* domain length */ + i =asn1_length_decode (pld + offs, pld_len - offs, &u); +if (i <0 ) +return -EINVAL ; + offs += i; +if (offs >= pld_len || u > pld_len - offs) +return -EINVAL ; +/* +* pld[offs] is now at the start of the domain value +* with the value sprawled in u octets. +*/ + i =asn1_int_encode (pld + offs, u, +AP_QID_QUEUE (zq->queue->qid)); +if (i <0 )return -EINVAL ; - } - }else { - lfmt =1 ;/* length format #1 */ + offs += i; } - payload_hdr = (struct pld_hdr *)((&msg->pld_lenfmt) + lfmt); - payload_hdr->dom_val =AP_QID_QUEUE (zq->queue->qid); }/*
Greg Kroah-Hartman
maintainerPATCH 615/621 s390/zcrypt: Pad trailing CCA or EP11 message with zeros
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harald Freudenberger <[email protected]>
commit eb363254472493e3458156fc11fd56dca92f4333 upstream.
The both functions xcrb_msg_to_type6cprb_msgx() and xcrb_msg_to_type6_ep11cprb_msgx() copy the user space message into a kernel buffer based on the message length. But on further processing the message is supposed to be 4 byte length adjusted. Thus up to 3 bytes of uninitialized kernel memory are forwarded to further processing steps and may unwanted expose kernel memory to the crypto card firmware.
This patch contains code to pad the gap between user space copied message and message buffer length sent down to further processing of the CCA or EP11 message to zeros.
--- drivers/s390/crypto/zcrypt_msgtype6.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/s390/crypto/zcrypt_msgtype6.c +8 -0
@@ -399,6 +399,10 @@ static int xcrb_msg_to_type6cprb_msgx(bo xcrb->request_control_blk_addr, xcrb->request_control_blk_length))return -EFAULT ; +/* pad tail with 0 up to req_cblen */ +if (xcrb->request_control_blk_length < req_cblen) +memset (msg->userdata + xcrb->request_control_blk_length, +0 , req_cblen - xcrb->request_control_blk_length);/* copy subfunction code into AP msg type 6 function code field */ if (msg->cprbx.cprb_len > req_cblen -sizeof (msg->hdr.function_code))return -EINVAL ;
@@ -544,6 +548,10 @@ static int xcrb_msg_to_type6_ep11cprb_msif (z_copy_from_user (userspace, msg->userdata, (char __force __user *)xcrb->req, xcrb->req_len))return -EFAULT ; +/* pad tail with 0 up to req_len */ +if (xcrb->req_len < req_len) +memset (msg->userdata + xcrb->req_len,0 , + req_len - xcrb->req_len); pld = msg->userdata +sizeof (struct ep11_cprb ); pld_len = msg->cprbx.payload_len;
Greg Kroah-Hartman
maintainerPATCH 616/621 accel/amdxdna: Resume power for creating and destroying hardware context
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lizhi Hou <[email protected]>
commit e00f78679f5a3d98b650fc9397c4d358ab570725 upstream.
When the hardware is powered down by auto-suspend, creating or destroying a hardware context without resuming power will fail.
Call amdxdna_pm_resume_get() before requesting the hardware to create or destroy a hardware context.
--- drivers/accel/amdxdna/aie2_ctx.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/accel/amdxdna/aie2_ctx.c +8 -1
@@ -616,10 +616,14 @@ int aie2_hwctx_init(struct amdxdna_hwctx goto free_entity; } + ret =amdxdna_pm_resume_get (xdna); +if (ret) + goto free_col_list; + ret =aie2_alloc_resource (hwctx);if (ret) {XDNA_ERR (xdna,"Alloc hw resource failed, ret %d" , ret); - goto free_col_list; + goto suspend_put; } ret = aie2_map_host_buf(xdna->dev_handle, hwctx->fw_ctx_id,
@@ -634,6 +638,7 @@ int aie2_hwctx_init(struct amdxdna_hwctxXDNA_ERR (xdna,"Create syncobj failed, ret %d" , ret); goto release_resource; } +amdxdna_pm_suspend_put (xdna); hwctx->status =HWCTX_STAT_INIT ; ndev = xdna->dev_handle;
@@ -646,6 +651,8 @@ int aie2_hwctx_init(struct amdxdna_hwctx release_resource:aie2_release_resource (hwctx); +suspend_put: +amdxdna_pm_suspend_put (xdna); free_col_list:kfree (hwctx->col_list); free_entity:
Greg Kroah-Hartman
maintainerPATCH 617/621 accel/amdxdna: Fix race condition when checking rpm_on
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lizhi Hou <[email protected]>
commit 00ffe45ece80160aef446d74ded906352f21dd72 upstream.
When autosuspend is triggered, driver rpm_on flag is set to indicate that a suspend/resume is already in progress. However, when a userspace application submits a command during this narrow window, amdxdna_pm_resume_get() may incorrectly skip the resume operation because the rpm_on flag is still set. This results in commands being submitted while the device has not actually resumed, causing unexpected behavior.
The set_dpm() is called by suspend/resume, it relied on rpm_on flag to avoid calling into rpm suspend/resume recursivly. So to fix this, remove the use of the rpm_on flag entirely. Instead, introduce aie2_pm_set_dpm() which explicitly resumes the device before invoking set_dpm(). With this change, set_dpm() is called directly inside the suspend or resume execution path. Otherwise, aie2_pm_set_dpm() is called.
--- drivers/accel/amdxdna/aie2_message.c | 1 - drivers/accel/amdxdna/aie2_pci.c | 2 +- drivers/accel/amdxdna/aie2_pci.h | 1 + drivers/accel/amdxdna/aie2_pm.c | 17 ++++++++++++++++- drivers/accel/amdxdna/aie2_smu.c | 27 ++++----------------------- drivers/accel/amdxdna/amdxdna_pci_drv.h | 1 - drivers/accel/amdxdna/amdxdna_pm.c | 22 ++-------------------- 7 files changed, 24 insertions(+), 47 deletions(-)
drivers/accel/amdxdna/aie2_message.c +0 -1
@@ -37,7 +37,6 @@ static int aie2_send_mgmt_msg_wait(strucif (!ndev->mgmt_chann)return -ENODEV ; -drm_WARN_ON (&xdna->ddev, xdna->rpm_on && !mutex_is_locked (&xdna->dev_lock)); ret =xdna_send_msg_wait (xdna, ndev->mgmt_chann, msg);if (ret == -ETIME )aie2_destroy_mgmt_chann (ndev);
drivers/accel/amdxdna/aie2_pci.c +1 -1
@@ -306,7 +306,7 @@ static int aie2_xrs_set_dft_dpm_level(stif (ndev->pw_mode !=POWER_MODE_DEFAULT || ndev->dpm_level == dpm_level)return 0 ; -return ndev->priv->hw_ops.set_dpm (ndev, dpm_level); +return aie2_pm_set_dpm (ndev, dpm_level); }static struct xrs_action_ops aie2_xrs_actions = {
drivers/accel/amdxdna/aie2_pci.h +1 -0
@@ -247,6 +247,7 @@ int npu4_set_dpm(struct amdxdna_dev_hdl/* aie2_pm.c */ int aie2_pm_init (struct amdxdna_dev_hdl *ndev);int aie2_pm_set_mode (struct amdxdna_dev_hdl *ndev,enum amdxdna_power_mode_type target); +int aie2_pm_set_dpm (struct amdxdna_dev_hdl *ndev,u32 dpm_level);/* aie2_psp.c */ struct psp_device *aie2m_psp_create (struct drm_device *ddev,struct psp_config *conf);
drivers/accel/amdxdna/aie2_pm.c +16 -1
@@ -10,6 +10,7 @@#include "aie2_pci.h" #include "amdxdna_pci_drv.h" +#include "amdxdna_pm.h" #define AIE2_CLK_GATING_ENABLE 1#define AIE2_CLK_GATING_DISABLE 0
@@ -26,6 +27,20 @@ static int aie2_pm_set_clk_gating(structreturn 0 ; } +int aie2_pm_set_dpm (struct amdxdna_dev_hdl *ndev,u32 dpm_level) +{ +int ret; + + ret =amdxdna_pm_resume_get (ndev->xdna); +if (ret) +return ret; + + ret = ndev->priv->hw_ops.set_dpm (ndev, dpm_level); +amdxdna_pm_suspend_put (ndev->xdna); + +return ret; +} +int aie2_pm_init (struct amdxdna_dev_hdl *ndev) {int ret;
@@ -94,7 +109,7 @@ int aie2_pm_set_mode(struct amdxdna_dev_return -EOPNOTSUPP ; } - ret = ndev->priv->hw_ops.set_dpm (ndev, dpm_level); + ret =aie2_pm_set_dpm (ndev, dpm_level);if (ret)return ret;
drivers/accel/amdxdna/aie2_smu.c +4 -23
@@ -11,7 +11,6 @@#include "aie2_pci.h" #include "amdxdna_pci_drv.h" -#include "amdxdna_pm.h" #define SMU_RESULT_OK 1
@@ -67,16 +66,12 @@ int npu1_set_dpm(struct amdxdna_dev_hdlu32 freq;int ret; - ret =amdxdna_pm_resume_get (ndev->xdna); -if (ret) -return ret; - ret =aie2_smu_exec (ndev,AIE2_SMU_SET_MPNPUCLK_FREQ , ndev->priv->dpm_clk_tbl[dpm_level].npuclk, &freq);if (ret) {XDNA_ERR (ndev->xdna,"Set npu clock to %d failed, ret %d\n" , ndev->priv->dpm_clk_tbl[dpm_level].npuclk, ret); - goto suspend_put; +return ret; } ndev->npuclk_freq = freq;
@@ -85,10 +80,9 @@ int npu1_set_dpm(struct amdxdna_dev_hdlif (ret) {XDNA_ERR (ndev->xdna,"Set h clock to %d failed, ret %d\n" , ndev->priv->dpm_clk_tbl[dpm_level].hclk, ret); - goto suspend_put; +return ret; } -amdxdna_pm_suspend_put (ndev->xdna); ndev->hclk_freq = freq; ndev->dpm_level = dpm_level; ndev->max_tops =2 * ndev->total_col;
@@ -98,35 +92,26 @@ int npu1_set_dpm(struct amdxdna_dev_hdl ndev->npuclk_freq, ndev->hclk_freq);return 0 ; - -suspend_put: -amdxdna_pm_suspend_put (ndev->xdna); -return ret; }int npu4_set_dpm (struct amdxdna_dev_hdl *ndev,u32 dpm_level) {int ret; - ret =amdxdna_pm_resume_get (ndev->xdna); -if (ret) -return ret; - ret =aie2_smu_exec (ndev,AIE2_SMU_SET_HARD_DPMLEVEL , dpm_level,NULL );if (ret) {XDNA_ERR (ndev->xdna,"Set hard dpm level %d failed, ret %d " , dpm_level, ret); - goto suspend_put; +return ret; } ret =aie2_smu_exec (ndev,AIE2_SMU_SET_SOFT_DPMLEVEL , dpm_level,NULL );if (ret) {XDNA_ERR (ndev->xdna,"Set soft dpm level %d failed, ret %d" , dpm_level, ret); - goto suspend_put; +return ret; } -amdxdna_pm_suspend_put (ndev->xdna); ndev->npuclk_freq = ndev->priv->dpm_clk_tbl[dpm_level].npuclk; ndev->hclk_freq = ndev->priv->dpm_clk_tbl[dpm_level].hclk; ndev->dpm_level = dpm_level;
@@ -137,10 +122,6 @@ int npu4_set_dpm(struct amdxdna_dev_hdl ndev->npuclk_freq, ndev->hclk_freq);return 0 ; - -suspend_put: -amdxdna_pm_suspend_put (ndev->xdna); -return ret; }int aie2_smu_init (struct amdxdna_dev_hdl *ndev)
drivers/accel/amdxdna/amdxdna_pci_drv.h +0 -1
@@ -100,7 +100,6 @@ struct amdxdna_dev {struct amdxdna_fw_ver fw_ver;struct rw_semaphore notifier_lock;/* for mmu notifier*/ struct workqueue_struct *notifier_wq; -bool rpm_on; };/*
drivers/accel/amdxdna/amdxdna_pm.c +2 -20
@@ -15,14 +15,9 @@ int amdxdna_pm_suspend(struct device *de {struct amdxdna_dev *xdna =to_xdna_dev (dev_get_drvdata (dev));int ret = -EOPNOTSUPP ; -bool rpm; -if (xdna->dev_info->ops->suspend) { - rpm = xdna->rpm_on; - xdna->rpm_on = false; +if (xdna->dev_info->ops->suspend) ret = xdna->dev_info->ops->suspend (xdna); - xdna->rpm_on = rpm; - }XDNA_DBG (xdna,"Suspend done ret %d" , ret);return ret;
@@ -32,14 +27,9 @@ int amdxdna_pm_resume(struct device *dev {struct amdxdna_dev *xdna =to_xdna_dev (dev_get_drvdata (dev));int ret = -EOPNOTSUPP ; -bool rpm; -if (xdna->dev_info->ops->resume) { - rpm = xdna->rpm_on; - xdna->rpm_on = false; +if (xdna->dev_info->ops->resume) ret = xdna->dev_info->ops->resume (xdna); - xdna->rpm_on = rpm; - }XDNA_DBG (xdna,"Resume done ret %d" , ret);return ret;
@@ -50,9 +40,6 @@ int amdxdna_pm_resume_get(struct amdxdnastruct device *dev = xdna->ddev.dev;int ret; -if (!xdna->rpm_on) -return 0 ; - ret =pm_runtime_resume_and_get (dev);if (ret) {XDNA_ERR (xdna,"Resume failed: %d" , ret);
@@ -66,9 +53,6 @@ void amdxdna_pm_suspend_put(struct amdxd {struct device *dev = xdna->ddev.dev; -if (!xdna->rpm_on) -return ; -pm_runtime_put_autosuspend (dev); }
@@ -81,14 +65,12 @@ void amdxdna_pm_init(struct amdxdna_devpm_runtime_use_autosuspend (dev);pm_runtime_allow (dev);pm_runtime_put_autosuspend (dev); - xdna->rpm_on = true; }void amdxdna_pm_fini (struct amdxdna_dev *xdna) {struct device *dev = xdna->ddev.dev; - xdna->rpm_on = false;pm_runtime_get_noresume (dev);pm_runtime_forbid (dev); }
Greg Kroah-Hartman
maintainerPATCH 618/621 accel/amdxdna: Fix crash when destroying a suspended hardware context
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lizhi Hou <[email protected]>
commit 8363c02863332992a1822688da41f881d88d1631 upstream.
If userspace issues an ioctl to destroy a hardware context that has already been automatically suspended, the driver may crash because the mailbox channel pointer is NULL for the suspended context.
Fix this by checking the mailbox channel pointer in aie2_destroy_context() before accessing it.
--- drivers/accel/amdxdna/aie2_message.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/accel/amdxdna/aie2_message.c +3 -0
@@ -273,6 +273,9 @@ int aie2_destroy_context(struct amdxdna_if (hwctx->fw_ctx_id ==-1 )return 0 ; +if (!hwctx->priv->mbox_chann) +return 0 ; +xdna_mailbox_stop_channel (hwctx->priv->mbox_chann); ret =aie2_destroy_context_req (ndev, hwctx->fw_ctx_id);xdna_mailbox_destroy_channel (hwctx->priv->mbox_chann);
Greg Kroah-Hartman
maintainerPATCH 619/621 workqueue: Annotate alloc_workqueue_va() with __printf(1, 0)
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tejun Heo <[email protected]>
commit 20e81c64c905bd765e69ef07920d2b1130dc79b6 upstream.
alloc_workqueue_va() forwards its va_list to __alloc_workqueue() which ultimately feeds vsnprintf(). __alloc_workqueue() already carries __printf(1, 0); the new wrapper needs the same annotation so format string checking propagates through the forwarding.
--- kernel/workqueue.c | 1 + 1 file changed, 1 insertion(+)
kernel/workqueue.c +1 -0
@@ -5875,6 +5875,7 @@ err_destroy:return NULL ; } +__printf(1, 0) static struct workqueue_struct *alloc_workqueue_va(const char *fmt, unsigned int flags, int max_active,
Greg Kroah-Hartman
maintainerPATCH 620/621 ACPI: scan: Do not mark button ACPI devices as wakeup-capable
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit 91ba8de81bcb8cea922ee9427e54798a16dfd724 ]
It is generally questionable to mark struct acpi_device "devices" as wakeup-capable because they represent firmware entities that by themselves have no wakeup capabilities.
It was done for struct acpi_device "devices" corresponding to buttons because the ACPI button driver was binding to them directly, but now that corresponding platform devices are created for the buttons and they are marked as wakeup-capable by the ACPI button driver, there is no reason to continue doing it.
Update acpi_wakeup_gpe_init() accordingly.
Stable-dep-of: 57c31e6d620f ("ACPI: scan: Use acpi_setup_gpe_for_wake() for buttons")
--- drivers/acpi/scan.c | 1 - 1 file changed, 1 deletion(-)
drivers/acpi/scan.c +0 -1
@@ -1029,7 +1029,6 @@ static bool acpi_wakeup_gpe_init(struct acpi_device *device) wakeup->sleep_state == ACPI_STATE_S5) wakeup->sleep_state =ACPI_STATE_S4 ;acpi_mark_gpe_for_wake (wakeup->gpe_device, wakeup->gpe_number); -device_set_wakeup_capable (&device->dev, true);return true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 621/621 ACPI: scan: Use acpi_setup_gpe_for_wake() for buttons
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit 57c31e6d620f132dcf610b2c52b4cdbd203c6f4a ]
After starting to use platform devices for representing buttons enumerated via ACPI, acpi_mark_gpe_for_wake() is insufficient for preparing their GPEs to wake up the system from sleep because it does not change the "dispatch type" of the given GPE to ACPI_GPE_DISPATCH_NOTIFY. Subsequently, this causes acpi_enable_gpe() in __acpi_device_wakeup_enable() to fail and system suspend transitions to be aborted.
Address this by updating acpi_wakeup_gpe_init() to use acpi_setup_gpe_for_wake() for buttons like for any other devices.
This allows acpi_setup_gpe_for_wake() to be simplified further because buttons are not a special case in it any more, so do that as well.
--- drivers/acpi/scan.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/acpi/scan.c +4 -14
@@ -1005,15 +1005,11 @@ static int acpi_bus_extract_wakeup_device_power_package(struct acpi_device *dev)return err; } -/* Do not use a button for S5 wakeup */ -#define ACPI_AVOID_WAKE_FROM_S5 BIT(0) -static bool acpi_wakeup_gpe_init (struct acpi_device *device) {static const struct acpi_device_id button_device_ids[] = { - {"PNP0C0C" ,0 },/* Power button */ - {"PNP0C0D" ,ACPI_AVOID_WAKE_FROM_S5 },/* Lid */ - {"PNP0C0E" ,ACPI_AVOID_WAKE_FROM_S5 },/* Sleep button */ + {"PNP0C0D" ,0 },/* Lid */ + {"PNP0C0E" ,0 },/* Sleep button */ {"" ,0 }, };struct acpi_device_wakeup *wakeup = &device->wakeup;
@@ -1022,15 +1018,9 @@ static bool acpi_wakeup_gpe_init(struct acpi_device *device) wakeup->flags.notifier_present =0 ; -/* Power button, Lid switch always enable wakeup */ match =acpi_match_acpi_device (button_device_ids, device); -if (match) { -if ((match->driver_data &ACPI_AVOID_WAKE_FROM_S5 ) && - wakeup->sleep_state ==ACPI_STATE_S5 ) - wakeup->sleep_state =ACPI_STATE_S4 ; -acpi_mark_gpe_for_wake (wakeup->gpe_device, wakeup->gpe_number); -return true; - } +if (match && wakeup->sleep_state ==ACPI_STATE_S5 ) + wakeup->sleep_state =ACPI_STATE_S4 ; status =acpi_setup_gpe_for_wake (device->handle, wakeup->gpe_device, wakeup->gpe_number);
Signature · 1 line
2.53.0
Quoted 8 lines · On Tue, 13 Oct 2026 13:29:55 +0200 Greg Kroah-Hartman…
This is the start of the stable review cycle for the 6.18.57 release. There are 621 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Thu, 15 Oct 2026 11:28:22 +0000. Anything received after that time might be too late.
For this one, like others, I am hitting the crypto_krb5_* everywhere plus, for riscv64, the RISCV_ISA_EXT_H issue I reported.
I hope that helps!
Cheers,
Miguel
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.18.57 release. There are 621 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Thu, 15 Oct 2026 11:28:22 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 9 lines
https://www.kernel.org/pub/linux/kernel/v6.x/stable-review/patch-6.18.57-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-6.18.y
and the diffstat can be found below.thanks,
greg k-h
Compiled and booted on my test system. No dmesg regressions.
thanks,
-- Shuah
Build tested in our x86,arm64,loongarch config successfully without error.
I met the same riscv 'RISCV_ISA_EXT_H' build issue others had reported.
Best Regards
Wentao Guan
Log:arch/riscv/kernel/cpufeature.c: In function ‘riscv_clear_hypervisor_csr’:arch/riscv/kernel/cpufeature.c:1140:43: error: ‘RISCV_ISA_EXT_H’ undeclared (first use in this function); did you mean ‘RISCV_ISA_EXT_h’?
1140 | if (!riscv_has_extension_unlikely(RISCV_ISA_EXT_H))
| ^~~~~~~~~~~~~~~
| RISCV_ISA_EXT_h
arch/riscv/kernel/cpufeature.c:1140:43: note: each undeclared identifier is reported only once for each function it appears in
CC arch/riscv/kernel/acpi.o
CC arch/riscv/kernel/pi/cmdline_early.o
CC arch/riscv/kernel/acpi_numa.o