Skip to content

Commit b43088f

Browse files
hfreudeVasily Gorbik
authored andcommitted
s390/zcrypt: fix warning about field-spanning write
This patch fixes the warning memcpy: detected field-spanning write (size 60) of single field "to" at drivers/s390/crypto/zcrypt_api.h:173 (size 2) WARNING: CPU: 1 PID: 2114 at drivers/s390/crypto/zcrypt_api.h:173 prep_ep11_ap_msg+0x2c6/0x2e0 [zcrypt] The code has been rewritten to use a union in combination with a flex array to clearly state which part of the buffer the payload is to be copied in via z_copy_from_user function (which may call memcpy() in case of in-kernel calls). Signed-off-by: Harald Freudenberger <[email protected]> Suggested-by: Jürgen Christ <[email protected]> Reviewed-by: Jürgen Christ <[email protected]> Signed-off-by: Vasily Gorbik <[email protected]>
1 parent e38de48 commit b43088f

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

drivers/s390/crypto/zcrypt_msgtype6.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,10 @@ static int xcrb_msg_to_type6cprb_msgx(bool userspace, struct ap_message *ap_msg,
342342
};
343343
struct {
344344
struct type6_hdr hdr;
345-
struct CPRBX cprbx;
345+
union {
346+
struct CPRBX cprbx;
347+
DECLARE_FLEX_ARRAY(u8, userdata);
348+
};
346349
} __packed * msg = ap_msg->msg;
347350

348351
int rcblen = CEIL4(xcrb->request_control_blk_length);
@@ -403,7 +406,8 @@ static int xcrb_msg_to_type6cprb_msgx(bool userspace, struct ap_message *ap_msg,
403406
msg->hdr.fromcardlen2 = xcrb->reply_data_length;
404407

405408
/* prepare CPRB */
406-
if (z_copy_from_user(userspace, &msg->cprbx, xcrb->request_control_blk_addr,
409+
if (z_copy_from_user(userspace, msg->userdata,
410+
xcrb->request_control_blk_addr,
407411
xcrb->request_control_blk_length))
408412
return -EFAULT;
409413
if (msg->cprbx.cprb_len + sizeof(msg->hdr.function_code) >
@@ -469,9 +473,14 @@ static int xcrb_msg_to_type6_ep11cprb_msgx(bool userspace, struct ap_message *ap
469473

470474
struct {
471475
struct type6_hdr hdr;
472-
struct ep11_cprb cprbx;
473-
unsigned char pld_tag; /* fixed value 0x30 */
474-
unsigned char pld_lenfmt; /* payload length format */
476+
union {
477+
struct {
478+
struct ep11_cprb cprbx;
479+
unsigned char pld_tag; /* fixed value 0x30 */
480+
unsigned char pld_lenfmt; /* length format */
481+
} __packed;
482+
DECLARE_FLEX_ARRAY(u8, userdata);
483+
};
475484
} __packed * msg = ap_msg->msg;
476485

477486
struct pld_hdr {
@@ -500,7 +509,7 @@ static int xcrb_msg_to_type6_ep11cprb_msgx(bool userspace, struct ap_message *ap
500509
msg->hdr.fromcardlen1 = xcrb->resp_len;
501510

502511
/* Import CPRB data from the ioctl input parameter */
503-
if (z_copy_from_user(userspace, &msg->cprbx.cprb_len,
512+
if (z_copy_from_user(userspace, msg->userdata,
504513
(char __force __user *)xcrb->req, xcrb->req_len)) {
505514
return -EFAULT;
506515
}

0 commit comments

Comments
 (0)