Fix zcrypt handler functions
Subsystems (2)
Harald Freudenberger
maintainercover Fix zcrypt handler functions
As of now only one patch dealing with a missing initial message length check on receive of a zcrypt message type 50 or 6.
Changelog:
v0: Initial version, just one patch fixing missing initial message
length check at all 3 handler functions.
Harald Freudenberger (1):
s390/crypto: Fix out-of-bounds access in zcrypt message type handlers
drivers/s390/crypto/zcrypt_msgtype50.c | 3 ++- drivers/s390/crypto/zcrypt_msgtype6.c | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-)
--
2.43.0
Harald Freudenberger
maintainerPATCH 1/1 s390/crypto: Fix out-of-bounds access in zcrypt message type handlers
Add length validation before accessing reply message structures in zcrypt_msgtype6_receive(), zcrypt_msgtype6_receive_ep11(), and zcrypt_msgtype50_receive() to prevent out-of-bounds reads and potential kernel memory disclosure.
The handlers now verify that reply->len is sufficient before accessing structure fields like cprb_ver_id. When validation fails, only the message type field is overwritten with an error code, preventing attackers from mixing user-controlled request data with short hardware responses to bypass validation and leak kernel memory.
--- drivers/s390/crypto/zcrypt_msgtype50.c | 3 ++- drivers/s390/crypto/zcrypt_msgtype6.c | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/s390/crypto/zcrypt_msgtype50.c +2 -1
@@ -424,7 +424,8 @@ static void zcrypt_msgtype50_receive(struct ap_queue *aq, t80h = reply->msg; -if (t80h->type !=TYPE80_RSP_CODE ) { +if (reply->len <sizeof (struct type80_hdr ) || + t80h->type !=TYPE80_RSP_CODE ) {if (reply->len <sizeof (error_reply))memcpy (msg->msg, &error_reply,sizeof (error_reply));else
drivers/s390/crypto/zcrypt_msgtype6.c +4 -2
@@ -943,7 +943,8 @@ static void zcrypt_msgtype6_receive(struct ap_queue *aq, t86r = reply->msg; -if (t86r->hdr.type !=TYPE86_RSP_CODE || +if (reply->len <sizeof (struct type86x_reply ) || + t86r->hdr.type !=TYPE86_RSP_CODE || t86r->cprbx.cprb_ver_id !=0x02 ) {if (reply->len <sizeof (error_reply))memcpy (msg->msg, &error_reply,sizeof (error_reply));
@@ -1032,7 +1033,8 @@ static void zcrypt_msgtype6_receive_ep11(struct ap_queue *aq, t86r = reply->msg; -if (t86r->hdr.type !=TYPE86_RSP_CODE || +if (reply->len <sizeof (struct type86_ep11_reply ) || + t86r->hdr.type !=TYPE86_RSP_CODE || t86r->cprbx.cprb_ver_id !=0x04 ) {if (reply->len <sizeof (error_reply))memcpy (msg->msg, &error_reply,sizeof (error_reply));
Signature · 1 line
2.43.0
Re: [PATCH v1 1/1] s390/crypto: Fix out-of-bounds access in zcrypt message type handlers
Quoted 18 lines · Harald Freudenberger
Add length validation before accessing reply message structures in
zcrypt_msgtype6_receive(),zcrypt_msgtype6_receive_ep11(), andzcrypt_msgtype50_receive()to prevent out-of-bounds reads and potential kernel memory disclosure.The handlers now verify that
reply->lenis sufficient before accessing structure fields likecprb_ver_id. When validation fails, only the message type field is overwritten with an error code, preventing attackers from mixing user-controlled request data with short hardware responses to bypass validation and leak kernel memory.Fixes 3b6245fd303f ("s390/zcrypt: Separate msgtype implementation from card modules.")Signed-off-by Harald Freudenberger <[email protected]>--- drivers/s390/crypto/zcrypt_msgtype50.c | 3 ++- drivers/s390/crypto/zcrypt_msgtype6.c | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-)
[ snip ]