Skip to content

Commit c0ec2a7

Browse files
pizhenweiherbertx
authored andcommitted
crypto: virtio/akcipher - Fix stack overflow on memcpy
sizeof(struct virtio_crypto_akcipher_session_para) is less than sizeof(struct virtio_crypto_op_ctrl_req::u), copying more bytes from stack variable leads stack overflow. Clang reports this issue by commands: make -j CC=clang-14 mrproper >/dev/null 2>&1 make -j O=/tmp/crypto-build CC=clang-14 allmodconfig >/dev/null 2>&1 make -j O=/tmp/crypto-build W=1 CC=clang-14 drivers/crypto/virtio/ virtio_crypto_akcipher_algs.o Fixes: 59ca6c9 ("virtio-crypto: implement RSA algorithm") Link: https://lore.kernel.org/all/[email protected]/ Cc: <[email protected]> Signed-off-by: zhenwei pi <[email protected]> Tested-by: Nathan Chancellor <[email protected]> # build Acked-by: Michael S. Tsirkin <[email protected]> Acked-by: Jason Wang <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 24c890d commit c0ec2a7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/crypto/virtio/virtio_crypto_akcipher_algs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ static void virtio_crypto_dataq_akcipher_callback(struct virtio_crypto_request *
104104
}
105105

106106
static int virtio_crypto_alg_akcipher_init_session(struct virtio_crypto_akcipher_ctx *ctx,
107-
struct virtio_crypto_ctrl_header *header, void *para,
107+
struct virtio_crypto_ctrl_header *header,
108+
struct virtio_crypto_akcipher_session_para *para,
108109
const uint8_t *key, unsigned int keylen)
109110
{
110111
struct scatterlist outhdr_sg, key_sg, inhdr_sg, *sgs[3];
@@ -128,7 +129,7 @@ static int virtio_crypto_alg_akcipher_init_session(struct virtio_crypto_akcipher
128129

129130
ctrl = &vc_ctrl_req->ctrl;
130131
memcpy(&ctrl->header, header, sizeof(ctrl->header));
131-
memcpy(&ctrl->u, para, sizeof(ctrl->u));
132+
memcpy(&ctrl->u.akcipher_create_session.para, para, sizeof(*para));
132133
input = &vc_ctrl_req->input;
133134
input->status = cpu_to_le32(VIRTIO_CRYPTO_ERR);
134135

0 commit comments

Comments
 (0)