linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: virtio/akcipher - Fix stack overflow on memcpy
@ 2024-01-30 11:27 zhenwei pi
  2024-01-31 19:10 ` Nathan Chancellor
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: zhenwei pi @ 2024-01-30 11:27 UTC (permalink / raw)
  To: arei.gonglei, mst, jasowang, herbert
  Cc: xuanzhuo, virtualization, nathan, linux-crypto, linux-kernel,
	davem, zhenwei pi

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: 59ca6c93387d ("virtio-crypto: implement RSA algorithm")
Link: https://lore.kernel.org/all/0a194a79-e3a3-45e7-be98-83abd3e1cb7e@roeck-us.net/
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
---
 drivers/crypto/virtio/virtio_crypto_akcipher_algs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
index 2621ff8a9376..de53eddf6796 100644
--- a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
+++ b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
@@ -104,7 +104,8 @@ static void virtio_crypto_dataq_akcipher_callback(struct virtio_crypto_request *
 }
 
 static int virtio_crypto_alg_akcipher_init_session(struct virtio_crypto_akcipher_ctx *ctx,
-		struct virtio_crypto_ctrl_header *header, void *para,
+		struct virtio_crypto_ctrl_header *header,
+		struct virtio_crypto_akcipher_session_para *para,
 		const uint8_t *key, unsigned int keylen)
 {
 	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
 
 	ctrl = &vc_ctrl_req->ctrl;
 	memcpy(&ctrl->header, header, sizeof(ctrl->header));
-	memcpy(&ctrl->u, para, sizeof(ctrl->u));
+	memcpy(&ctrl->u.akcipher_create_session.para, para, sizeof(*para));
 	input = &vc_ctrl_req->input;
 	input->status = cpu_to_le32(VIRTIO_CRYPTO_ERR);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] crypto: virtio/akcipher - Fix stack overflow on memcpy
  2024-01-30 11:27 [PATCH] crypto: virtio/akcipher - Fix stack overflow on memcpy zhenwei pi
@ 2024-01-31 19:10 ` Nathan Chancellor
  2024-01-31 22:36 ` Michael S. Tsirkin
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Nathan Chancellor @ 2024-01-31 19:10 UTC (permalink / raw)
  To: zhenwei pi
  Cc: arei.gonglei, mst, jasowang, herbert, xuanzhuo, virtualization,
	linux-crypto, linux-kernel, davem

On Tue, Jan 30, 2024 at 07:27:40PM +0800, zhenwei pi wrote:
> 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: 59ca6c93387d ("virtio-crypto: implement RSA algorithm")
> Link: https://lore.kernel.org/all/0a194a79-e3a3-45e7-be98-83abd3e1cb7e@roeck-us.net/
> Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>

I can confirm this resolves the warning for me as well.

Tested-by: Nathan Chancellor <nathan@kernel.org> # build

I suspect Guenter should have a formal Reported-by tag. Should this be
CC'd for stable@ as well?

Cheers,
Nathan

> ---
>  drivers/crypto/virtio/virtio_crypto_akcipher_algs.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> index 2621ff8a9376..de53eddf6796 100644
> --- a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> +++ b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> @@ -104,7 +104,8 @@ static void virtio_crypto_dataq_akcipher_callback(struct virtio_crypto_request *
>  }
>  
>  static int virtio_crypto_alg_akcipher_init_session(struct virtio_crypto_akcipher_ctx *ctx,
> -		struct virtio_crypto_ctrl_header *header, void *para,
> +		struct virtio_crypto_ctrl_header *header,
> +		struct virtio_crypto_akcipher_session_para *para,
>  		const uint8_t *key, unsigned int keylen)
>  {
>  	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
>  
>  	ctrl = &vc_ctrl_req->ctrl;
>  	memcpy(&ctrl->header, header, sizeof(ctrl->header));
> -	memcpy(&ctrl->u, para, sizeof(ctrl->u));
> +	memcpy(&ctrl->u.akcipher_create_session.para, para, sizeof(*para));
>  	input = &vc_ctrl_req->input;
>  	input->status = cpu_to_le32(VIRTIO_CRYPTO_ERR);
>  
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] crypto: virtio/akcipher - Fix stack overflow on memcpy
  2024-01-30 11:27 [PATCH] crypto: virtio/akcipher - Fix stack overflow on memcpy zhenwei pi
  2024-01-31 19:10 ` Nathan Chancellor
@ 2024-01-31 22:36 ` Michael S. Tsirkin
  2024-02-01  5:49 ` Jason Wang
  2024-02-09  5:00 ` Herbert Xu
  3 siblings, 0 replies; 5+ messages in thread
From: Michael S. Tsirkin @ 2024-01-31 22:36 UTC (permalink / raw)
  To: zhenwei pi
  Cc: arei.gonglei, jasowang, herbert, xuanzhuo, virtualization,
	nathan, linux-crypto, linux-kernel, davem

On Tue, Jan 30, 2024 at 07:27:40PM +0800, zhenwei pi wrote:
> 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: 59ca6c93387d ("virtio-crypto: implement RSA algorithm")
> Link: https://lore.kernel.org/all/0a194a79-e3a3-45e7-be98-83abd3e1cb7e@roeck-us.net/
> Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>

Cc: stable@vger.kernel.org
Acked-by: Michael S. Tsirkin <mst@redhat.com>



> ---
>  drivers/crypto/virtio/virtio_crypto_akcipher_algs.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> index 2621ff8a9376..de53eddf6796 100644
> --- a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> +++ b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> @@ -104,7 +104,8 @@ static void virtio_crypto_dataq_akcipher_callback(struct virtio_crypto_request *
>  }
>  
>  static int virtio_crypto_alg_akcipher_init_session(struct virtio_crypto_akcipher_ctx *ctx,
> -		struct virtio_crypto_ctrl_header *header, void *para,
> +		struct virtio_crypto_ctrl_header *header,
> +		struct virtio_crypto_akcipher_session_para *para,
>  		const uint8_t *key, unsigned int keylen)
>  {
>  	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
>  
>  	ctrl = &vc_ctrl_req->ctrl;
>  	memcpy(&ctrl->header, header, sizeof(ctrl->header));
> -	memcpy(&ctrl->u, para, sizeof(ctrl->u));
> +	memcpy(&ctrl->u.akcipher_create_session.para, para, sizeof(*para));
>  	input = &vc_ctrl_req->input;
>  	input->status = cpu_to_le32(VIRTIO_CRYPTO_ERR);
>  
> -- 
> 2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] crypto: virtio/akcipher - Fix stack overflow on memcpy
  2024-01-30 11:27 [PATCH] crypto: virtio/akcipher - Fix stack overflow on memcpy zhenwei pi
  2024-01-31 19:10 ` Nathan Chancellor
  2024-01-31 22:36 ` Michael S. Tsirkin
@ 2024-02-01  5:49 ` Jason Wang
  2024-02-09  5:00 ` Herbert Xu
  3 siblings, 0 replies; 5+ messages in thread
From: Jason Wang @ 2024-02-01  5:49 UTC (permalink / raw)
  To: zhenwei pi
  Cc: arei.gonglei, mst, herbert, xuanzhuo, virtualization, nathan,
	linux-crypto, linux-kernel, davem

On Tue, Jan 30, 2024 at 7:28 PM zhenwei pi <pizhenwei@bytedance.com> wrote:
>
> 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: 59ca6c93387d ("virtio-crypto: implement RSA algorithm")
> Link: https://lore.kernel.org/all/0a194a79-e3a3-45e7-be98-83abd3e1cb7e@roeck-us.net/
> Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>

Acked-by: Jason Wang <jasowang@redhat.com>

Thanks


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] crypto: virtio/akcipher - Fix stack overflow on memcpy
  2024-01-30 11:27 [PATCH] crypto: virtio/akcipher - Fix stack overflow on memcpy zhenwei pi
                   ` (2 preceding siblings ...)
  2024-02-01  5:49 ` Jason Wang
@ 2024-02-09  5:00 ` Herbert Xu
  3 siblings, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2024-02-09  5:00 UTC (permalink / raw)
  To: zhenwei pi
  Cc: arei.gonglei, mst, jasowang, xuanzhuo, virtualization, nathan,
	linux-crypto, linux-kernel, davem

On Tue, Jan 30, 2024 at 07:27:40PM +0800, zhenwei pi wrote:
> 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: 59ca6c93387d ("virtio-crypto: implement RSA algorithm")
> Link: https://lore.kernel.org/all/0a194a79-e3a3-45e7-be98-83abd3e1cb7e@roeck-us.net/
> Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
> ---
>  drivers/crypto/virtio/virtio_crypto_akcipher_algs.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-02-09  5:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-30 11:27 [PATCH] crypto: virtio/akcipher - Fix stack overflow on memcpy zhenwei pi
2024-01-31 19:10 ` Nathan Chancellor
2024-01-31 22:36 ` Michael S. Tsirkin
2024-02-01  5:49 ` Jason Wang
2024-02-09  5:00 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).