crypto: fix asymmetric private session variable size

Message ID 20220218125752.579335-1-ciara.power@intel.com (mailing list archive)
State Accepted, archived
Delegated to: akhil goyal
Headers
Series crypto: fix asymmetric private session variable size |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS

Commit Message

Power, Ciara Feb. 18, 2022, 12:57 p.m. UTC
  When creating the asymmetric session mempool, the maximum private
session size of all devices is used when creating the mempool
object size.
The return value for ``rte_cryptodev_asym_get_private_session_size``
is unsigned int, whereas the variable was uint8_t, leading to a
possible overflow issue.

To fix this, the variable for private session size is now changed to
unsigned int to match the function return type.

Fixes: 1f1e4b7cbaad ("cryptodev: use single mempool for asymmetric session")
Reported-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>

Signed-off-by: Ciara Power <ciara.power@intel.com>
---
 lib/cryptodev/rte_cryptodev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Fan Zhang Feb. 18, 2022, 1:39 p.m. UTC | #1
Hi Ciara,

> -----Original Message-----
> From: Power, Ciara <ciara.power@intel.com>
> Sent: Friday, February 18, 2022 12:58 PM
> To: dev@dpdk.org
> Cc: Zhang, Roy Fan <roy.fan.zhang@intel.com>; gakhil@marvell.com; Kusztal,
> ArkadiuszX <arkadiuszx.kusztal@intel.com>; Power, Ciara
> <ciara.power@intel.com>
> Subject: [PATCH] crypto: fix asymmetric private session variable size
> 
> When creating the asymmetric session mempool, the maximum private
> session size of all devices is used when creating the mempool
> object size.
> The return value for ``rte_cryptodev_asym_get_private_session_size``
> is unsigned int, whereas the variable was uint8_t, leading to a
> possible overflow issue.
> 
> To fix this, the variable for private session size is now changed to
> unsigned int to match the function return type.
> 
> Fixes: 1f1e4b7cbaad ("cryptodev: use single mempool for asymmetric
> session")
> Reported-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
> 
> Signed-off-by: Ciara Power <ciara.power@intel.com>
> ---
>  lib/cryptodev/rte_cryptodev.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
> index 727d271fb9..d262ae6ffa 100644
> --- a/lib/cryptodev/rte_cryptodev.c
> +++ b/lib/cryptodev/rte_cryptodev.c
> @@ -1810,7 +1810,8 @@ rte_cryptodev_asym_session_pool_create(const
> char *name, uint32_t nb_elts,
>  	struct rte_mempool *mp;
>  	struct rte_cryptodev_asym_session_pool_private_data *pool_priv;
>  	uint32_t obj_sz, obj_sz_aligned;
> -	uint8_t dev_id, priv_sz, max_priv_sz = 0;
> +	uint8_t dev_id;
> +	unsigned int priv_sz, max_priv_sz = 0;

I guess it is better to use uint32_t instead of unsigned int? I know they are most likely the same thing but probably better to use consistent type.

> 
>  	for (dev_id = 0; dev_id < RTE_CRYPTO_MAX_DEVS; dev_id++)
>  		if (rte_cryptodev_is_valid_dev(dev_id)) {
> --
> 2.25.1

Regards,
Fan
  
Fan Zhang Feb. 18, 2022, 2:08 p.m. UTC | #2
> -----Original Message-----
> From: Power, Ciara <ciara.power@intel.com>
> Sent: Friday, February 18, 2022 12:58 PM
> To: dev@dpdk.org
> Cc: Zhang, Roy Fan <roy.fan.zhang@intel.com>; gakhil@marvell.com; Kusztal,
> ArkadiuszX <arkadiuszx.kusztal@intel.com>; Power, Ciara
> <ciara.power@intel.com>
> Subject: [PATCH] crypto: fix asymmetric private session variable size
> 
> When creating the asymmetric session mempool, the maximum private
> session size of all devices is used when creating the mempool
> object size.
> The return value for ``rte_cryptodev_asym_get_private_session_size``
> is unsigned int, whereas the variable was uint8_t, leading to a
> possible overflow issue.
> 
> To fix this, the variable for private session size is now changed to
> unsigned int to match the function return type.
> 
> Fixes: 1f1e4b7cbaad ("cryptodev: use single mempool for asymmetric
> session")
> Reported-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
> 
> Signed-off-by: Ciara Power <ciara.power@intel.com>
> ---
>  lib/cryptodev/rte_cryptodev.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
> index 727d271fb9..d262ae6ffa 100644
> --- a/lib/cryptodev/rte_cryptodev.c
> +++ b/lib/cryptodev/rte_cryptodev.c
> @@ -1810,7 +1810,8 @@ rte_cryptodev_asym_session_pool_create(const
> char *name, uint32_t nb_elts,
>  	struct rte_mempool *mp;
>  	struct rte_cryptodev_asym_session_pool_private_data *pool_priv;
>  	uint32_t obj_sz, obj_sz_aligned;
> -	uint8_t dev_id, priv_sz, max_priv_sz = 0;
> +	uint8_t dev_id;
> +	unsigned int priv_sz, max_priv_sz = 0;
> 
>  	for (dev_id = 0; dev_id < RTE_CRYPTO_MAX_DEVS; dev_id++)
>  		if (rte_cryptodev_is_valid_dev(dev_id)) {
> --
> 2.25.1
Looks like the variable type of unsigned int is match the return type. So
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
  
Arkadiusz Kusztal Feb. 21, 2022, 10:38 a.m. UTC | #3
> -----Original Message-----
> From: Zhang, Roy Fan <roy.fan.zhang@intel.com>
> Sent: Friday, February 18, 2022 3:08 PM
> To: Power, Ciara <ciara.power@intel.com>; dev@dpdk.org
> Cc: gakhil@marvell.com; Kusztal, ArkadiuszX <arkadiuszx.kusztal@intel.com>
> Subject: RE: [PATCH] crypto: fix asymmetric private session variable size
> 
> > -----Original Message-----
> > From: Power, Ciara <ciara.power@intel.com>
> > Sent: Friday, February 18, 2022 12:58 PM
> > To: dev@dpdk.org
> > Cc: Zhang, Roy Fan <roy.fan.zhang@intel.com>; gakhil@marvell.com;
> > Kusztal, ArkadiuszX <arkadiuszx.kusztal@intel.com>; Power, Ciara
> > <ciara.power@intel.com>
> > Subject: [PATCH] crypto: fix asymmetric private session variable size
> >
> > When creating the asymmetric session mempool, the maximum private
> > session size of all devices is used when creating the mempool object
> > size.
> > The return value for ``rte_cryptodev_asym_get_private_session_size``
> > is unsigned int, whereas the variable was uint8_t, leading to a
> > possible overflow issue.
> >
> > To fix this, the variable for private session size is now changed to
> > unsigned int to match the function return type.
> >
> > Fixes: 1f1e4b7cbaad ("cryptodev: use single mempool for asymmetric
> > session")
> > Reported-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
> >
> > Signed-off-by: Ciara Power <ciara.power@intel.com>
> > ---
> >  lib/cryptodev/rte_cryptodev.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/cryptodev/rte_cryptodev.c
> > b/lib/cryptodev/rte_cryptodev.c index 727d271fb9..d262ae6ffa 100644
> > --- a/lib/cryptodev/rte_cryptodev.c
> > +++ b/lib/cryptodev/rte_cryptodev.c
> > @@ -1810,7 +1810,8 @@ rte_cryptodev_asym_session_pool_create(const
> > char *name, uint32_t nb_elts,
> >  	struct rte_mempool *mp;
> >  	struct rte_cryptodev_asym_session_pool_private_data *pool_priv;
> >  	uint32_t obj_sz, obj_sz_aligned;
> > -	uint8_t dev_id, priv_sz, max_priv_sz = 0;
> > +	uint8_t dev_id;
> > +	unsigned int priv_sz, max_priv_sz = 0;
> >
> >  	for (dev_id = 0; dev_id < RTE_CRYPTO_MAX_DEVS; dev_id++)
> >  		if (rte_cryptodev_is_valid_dev(dev_id)) {
> > --
> > 2.25.1
> Looks like the variable type of unsigned int is match the return type. So
> Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
Acked-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
  
Akhil Goyal Feb. 22, 2022, 7:02 p.m. UTC | #4
> > > When creating the asymmetric session mempool, the maximum private
> > > session size of all devices is used when creating the mempool object
> > > size.
> > > The return value for ``rte_cryptodev_asym_get_private_session_size``
> > > is unsigned int, whereas the variable was uint8_t, leading to a
> > > possible overflow issue.
> > >
> > > To fix this, the variable for private session size is now changed to
> > > unsigned int to match the function return type.
> > >
> > > Fixes: 1f1e4b7cbaad ("cryptodev: use single mempool for asymmetric
> > > session")
> > > Reported-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
> > >
> > > Signed-off-by: Ciara Power <ciara.power@intel.com>
> > > ---
> > Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
> Acked-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
Applied to dpdk-next-crypto

Thanks.
  

Patch

diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
index 727d271fb9..d262ae6ffa 100644
--- a/lib/cryptodev/rte_cryptodev.c
+++ b/lib/cryptodev/rte_cryptodev.c
@@ -1810,7 +1810,8 @@  rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
 	struct rte_mempool *mp;
 	struct rte_cryptodev_asym_session_pool_private_data *pool_priv;
 	uint32_t obj_sz, obj_sz_aligned;
-	uint8_t dev_id, priv_sz, max_priv_sz = 0;
+	uint8_t dev_id;
+	unsigned int priv_sz, max_priv_sz = 0;
 
 	for (dev_id = 0; dev_id < RTE_CRYPTO_MAX_DEVS; dev_id++)
 		if (rte_cryptodev_is_valid_dev(dev_id)) {