linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vdpa/mlx5: Fix erroneous null pointer checks
@ 2020-08-06 19:18 Alex Dewar
  2020-08-07  3:37 ` Jason Wang
  2020-08-09  5:52 ` Eli Cohen
  0 siblings, 2 replies; 6+ messages in thread
From: Alex Dewar @ 2020-08-06 19:18 UTC (permalink / raw)
  To: Michael S. Tsirkin, Jason Wang, Parav Pandit, Eli Cohen,
	Alex Dewar, virtualization, linux-kernel

In alloc_inout() in net/mlx5_vnet.c, there are a few places where memory
is allocated to *in and *out, but only the values of in and out are
null-checked (i.e. there is a missing dereference). Fix this.

Addresses-Coverity: ("CID 1496603: (REVERSE_INULL)")
Fixes: 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")
Signed-off-by: Alex Dewar <alex.dewar90@gmail.com>
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index 3ec44a4f0e45..bcb6600c2839 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -867,7 +867,7 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
 		*outlen = MLX5_ST_SZ_BYTES(qp_2rst_out);
 		*in = kzalloc(*inlen, GFP_KERNEL);
 		*out = kzalloc(*outlen, GFP_KERNEL);
-		if (!in || !out)
+		if (!*in || !*out)
 			goto outerr;
 
 		MLX5_SET(qp_2rst_in, *in, opcode, cmd);
@@ -879,7 +879,7 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
 		*outlen = MLX5_ST_SZ_BYTES(rst2init_qp_out);
 		*in = kzalloc(*inlen, GFP_KERNEL);
 		*out = kzalloc(MLX5_ST_SZ_BYTES(rst2init_qp_out), GFP_KERNEL);
-		if (!in || !out)
+		if (!*in || !*out)
 			goto outerr;
 
 		MLX5_SET(rst2init_qp_in, *in, opcode, cmd);
@@ -896,7 +896,7 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
 		*outlen = MLX5_ST_SZ_BYTES(init2rtr_qp_out);
 		*in = kzalloc(*inlen, GFP_KERNEL);
 		*out = kzalloc(MLX5_ST_SZ_BYTES(init2rtr_qp_out), GFP_KERNEL);
-		if (!in || !out)
+		if (!*in || !*out)
 			goto outerr;
 
 		MLX5_SET(init2rtr_qp_in, *in, opcode, cmd);
@@ -914,7 +914,7 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
 		*outlen = MLX5_ST_SZ_BYTES(rtr2rts_qp_out);
 		*in = kzalloc(*inlen, GFP_KERNEL);
 		*out = kzalloc(MLX5_ST_SZ_BYTES(rtr2rts_qp_out), GFP_KERNEL);
-		if (!in || !out)
+		if (!*in || !*out)
 			goto outerr;
 
 		MLX5_SET(rtr2rts_qp_in, *in, opcode, cmd);
-- 
2.28.0


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

* Re: [PATCH] vdpa/mlx5: Fix erroneous null pointer checks
  2020-08-06 19:18 [PATCH] vdpa/mlx5: Fix erroneous null pointer checks Alex Dewar
@ 2020-08-07  3:37 ` Jason Wang
  2020-08-07  3:59   ` Jason Wang
  2020-08-09  5:52 ` Eli Cohen
  1 sibling, 1 reply; 6+ messages in thread
From: Jason Wang @ 2020-08-07  3:37 UTC (permalink / raw)
  To: Alex Dewar, Michael S. Tsirkin, Parav Pandit, Eli Cohen,
	virtualization, linux-kernel


On 2020/8/7 上午3:18, Alex Dewar wrote:
> In alloc_inout() in net/mlx5_vnet.c, there are a few places where memory
> is allocated to *in and *out, but only the values of in and out are
> null-checked (i.e. there is a missing dereference). Fix this.
>
> Addresses-Coverity: ("CID 1496603: (REVERSE_INULL)")
> Fixes: 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")
> Signed-off-by: Alex Dewar <alex.dewar90@gmail.com>


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


> ---
>   drivers/vdpa/mlx5/net/mlx5_vnet.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index 3ec44a4f0e45..bcb6600c2839 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -867,7 +867,7 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
>   		*outlen = MLX5_ST_SZ_BYTES(qp_2rst_out);
>   		*in = kzalloc(*inlen, GFP_KERNEL);
>   		*out = kzalloc(*outlen, GFP_KERNEL);
> -		if (!in || !out)
> +		if (!*in || !*out)
>   			goto outerr;
>   
>   		MLX5_SET(qp_2rst_in, *in, opcode, cmd);
> @@ -879,7 +879,7 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
>   		*outlen = MLX5_ST_SZ_BYTES(rst2init_qp_out);
>   		*in = kzalloc(*inlen, GFP_KERNEL);
>   		*out = kzalloc(MLX5_ST_SZ_BYTES(rst2init_qp_out), GFP_KERNEL);
> -		if (!in || !out)
> +		if (!*in || !*out)
>   			goto outerr;
>   
>   		MLX5_SET(rst2init_qp_in, *in, opcode, cmd);
> @@ -896,7 +896,7 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
>   		*outlen = MLX5_ST_SZ_BYTES(init2rtr_qp_out);
>   		*in = kzalloc(*inlen, GFP_KERNEL);
>   		*out = kzalloc(MLX5_ST_SZ_BYTES(init2rtr_qp_out), GFP_KERNEL);
> -		if (!in || !out)
> +		if (!*in || !*out)
>   			goto outerr;
>   
>   		MLX5_SET(init2rtr_qp_in, *in, opcode, cmd);
> @@ -914,7 +914,7 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
>   		*outlen = MLX5_ST_SZ_BYTES(rtr2rts_qp_out);
>   		*in = kzalloc(*inlen, GFP_KERNEL);
>   		*out = kzalloc(MLX5_ST_SZ_BYTES(rtr2rts_qp_out), GFP_KERNEL);
> -		if (!in || !out)
> +		if (!*in || !*out)
>   			goto outerr;
>   
>   		MLX5_SET(rtr2rts_qp_in, *in, opcode, cmd);


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

* Re: [PATCH] vdpa/mlx5: Fix erroneous null pointer checks
  2020-08-07  3:37 ` Jason Wang
@ 2020-08-07  3:59   ` Jason Wang
  0 siblings, 0 replies; 6+ messages in thread
From: Jason Wang @ 2020-08-07  3:59 UTC (permalink / raw)
  To: Alex Dewar, Michael S. Tsirkin, Parav Pandit, Eli Cohen,
	virtualization, linux-kernel


On 2020/8/7 上午11:37, Jason Wang wrote:
>
> On 2020/8/7 上午3:18, Alex Dewar wrote:
>> In alloc_inout() in net/mlx5_vnet.c, there are a few places where memory
>> is allocated to *in and *out, but only the values of in and out are
>> null-checked (i.e. there is a missing dereference). Fix this.
>>
>> Addresses-Coverity: ("CID 1496603: (REVERSE_INULL)")
>> Fixes: 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 
>> devices")
>> Signed-off-by: Alex Dewar <alex.dewar90@gmail.com>
>
>
> Acked-by: Jason Wang <jasowang@redhat.com>


Colin posted something similar: [PATCH][next] vdpa/mlx5: fix memory 
allocation failure checks

And I think his fix is better since it prevent raw pointers to be freed.

Thanks


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

* Re: [PATCH] vdpa/mlx5: Fix erroneous null pointer checks
  2020-08-06 19:18 [PATCH] vdpa/mlx5: Fix erroneous null pointer checks Alex Dewar
  2020-08-07  3:37 ` Jason Wang
@ 2020-08-09  5:52 ` Eli Cohen
  2020-08-09  6:03   ` Eli Cohen
  1 sibling, 1 reply; 6+ messages in thread
From: Eli Cohen @ 2020-08-09  5:52 UTC (permalink / raw)
  To: Alex Dewar
  Cc: Michael S. Tsirkin, Jason Wang, Parav Pandit, virtualization,
	linux-kernel

Acked-by: Eli Cohen <eli@mellanox.com>
On Thu, Aug 06, 2020 at 08:18:39PM +0100, Alex Dewar wrote:
> In alloc_inout() in net/mlx5_vnet.c, there are a few places where memory
> is allocated to *in and *out, but only the values of in and out are
> null-checked (i.e. there is a missing dereference). Fix this.
> 
> Addresses-Coverity: ("CID 1496603: (REVERSE_INULL)")
> Fixes: 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")
> Signed-off-by: Alex Dewar <alex.dewar90@gmail.com>
> ---
>  drivers/vdpa/mlx5/net/mlx5_vnet.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index 3ec44a4f0e45..bcb6600c2839 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -867,7 +867,7 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
>  		*outlen = MLX5_ST_SZ_BYTES(qp_2rst_out);
>  		*in = kzalloc(*inlen, GFP_KERNEL);
>  		*out = kzalloc(*outlen, GFP_KERNEL);
> -		if (!in || !out)
> +		if (!*in || !*out)
>  			goto outerr;
>  
>  		MLX5_SET(qp_2rst_in, *in, opcode, cmd);
> @@ -879,7 +879,7 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
>  		*outlen = MLX5_ST_SZ_BYTES(rst2init_qp_out);
>  		*in = kzalloc(*inlen, GFP_KERNEL);
>  		*out = kzalloc(MLX5_ST_SZ_BYTES(rst2init_qp_out), GFP_KERNEL);
> -		if (!in || !out)
> +		if (!*in || !*out)
>  			goto outerr;
>  
>  		MLX5_SET(rst2init_qp_in, *in, opcode, cmd);
> @@ -896,7 +896,7 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
>  		*outlen = MLX5_ST_SZ_BYTES(init2rtr_qp_out);
>  		*in = kzalloc(*inlen, GFP_KERNEL);
>  		*out = kzalloc(MLX5_ST_SZ_BYTES(init2rtr_qp_out), GFP_KERNEL);
> -		if (!in || !out)
> +		if (!*in || !*out)
>  			goto outerr;
>  
>  		MLX5_SET(init2rtr_qp_in, *in, opcode, cmd);
> @@ -914,7 +914,7 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
>  		*outlen = MLX5_ST_SZ_BYTES(rtr2rts_qp_out);
>  		*in = kzalloc(*inlen, GFP_KERNEL);
>  		*out = kzalloc(MLX5_ST_SZ_BYTES(rtr2rts_qp_out), GFP_KERNEL);
> -		if (!in || !out)
> +		if (!*in || !*out)
>  			goto outerr;
>  
>  		MLX5_SET(rtr2rts_qp_in, *in, opcode, cmd);
> -- 
> 2.28.0
> 

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

* RE: [PATCH] vdpa/mlx5: Fix erroneous null pointer checks
  2020-08-09  5:52 ` Eli Cohen
@ 2020-08-09  6:03   ` Eli Cohen
  2020-08-09 16:21     ` Alex Dewar
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Cohen @ 2020-08-09  6:03 UTC (permalink / raw)
  To: Eli Cohen, Alex Dewar
  Cc: Michael S. Tsirkin, Jason Wang, Parav Pandit, virtualization,
	linux-kernel

After all this patch is not fixing it all. If we get to default of the switch statement we will free invalid pointer so removing ack-ed by me.

The previous patch by Colin King fixes it.


-----Original Message-----
From: Eli Cohen <eli@mellanox.com> 
Sent: Sunday, August 9, 2020 8:53 AM
To: Alex Dewar <alex.dewar90@gmail.com>
Cc: Michael S. Tsirkin <mst@redhat.com>; Jason Wang <jasowang@redhat.com>; Parav Pandit <parav@mellanox.com>; virtualization@lists.linux-foundation.org; linux-kernel@vger.kernel.org
Subject: Re: [PATCH] vdpa/mlx5: Fix erroneous null pointer checks

Acked-by: Eli Cohen <eli@mellanox.com>
On Thu, Aug 06, 2020 at 08:18:39PM +0100, Alex Dewar wrote:
> In alloc_inout() in net/mlx5_vnet.c, there are a few places where 
> memory is allocated to *in and *out, but only the values of in and out 
> are null-checked (i.e. there is a missing dereference). Fix this.
> 
> Addresses-Coverity: ("CID 1496603: (REVERSE_INULL)")
> Fixes: 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 
> devices")
> Signed-off-by: Alex Dewar <alex.dewar90@gmail.com>
> ---
>  drivers/vdpa/mlx5/net/mlx5_vnet.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c 
> b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index 3ec44a4f0e45..bcb6600c2839 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -867,7 +867,7 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
>  		*outlen = MLX5_ST_SZ_BYTES(qp_2rst_out);
>  		*in = kzalloc(*inlen, GFP_KERNEL);
>  		*out = kzalloc(*outlen, GFP_KERNEL);
> -		if (!in || !out)
> +		if (!*in || !*out)
>  			goto outerr;
>  
>  		MLX5_SET(qp_2rst_in, *in, opcode, cmd); @@ -879,7 +879,7 @@ static 
> void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
>  		*outlen = MLX5_ST_SZ_BYTES(rst2init_qp_out);
>  		*in = kzalloc(*inlen, GFP_KERNEL);
>  		*out = kzalloc(MLX5_ST_SZ_BYTES(rst2init_qp_out), GFP_KERNEL);
> -		if (!in || !out)
> +		if (!*in || !*out)
>  			goto outerr;
>  
>  		MLX5_SET(rst2init_qp_in, *in, opcode, cmd); @@ -896,7 +896,7 @@ 
> static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
>  		*outlen = MLX5_ST_SZ_BYTES(init2rtr_qp_out);
>  		*in = kzalloc(*inlen, GFP_KERNEL);
>  		*out = kzalloc(MLX5_ST_SZ_BYTES(init2rtr_qp_out), GFP_KERNEL);
> -		if (!in || !out)
> +		if (!*in || !*out)
>  			goto outerr;
>  
>  		MLX5_SET(init2rtr_qp_in, *in, opcode, cmd); @@ -914,7 +914,7 @@ 
> static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
>  		*outlen = MLX5_ST_SZ_BYTES(rtr2rts_qp_out);
>  		*in = kzalloc(*inlen, GFP_KERNEL);
>  		*out = kzalloc(MLX5_ST_SZ_BYTES(rtr2rts_qp_out), GFP_KERNEL);
> -		if (!in || !out)
> +		if (!*in || !*out)
>  			goto outerr;
>  
>  		MLX5_SET(rtr2rts_qp_in, *in, opcode, cmd);
> --
> 2.28.0
> 

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

* Re: [PATCH] vdpa/mlx5: Fix erroneous null pointer checks
  2020-08-09  6:03   ` Eli Cohen
@ 2020-08-09 16:21     ` Alex Dewar
  0 siblings, 0 replies; 6+ messages in thread
From: Alex Dewar @ 2020-08-09 16:21 UTC (permalink / raw)
  To: Eli Cohen
  Cc: Alex Dewar, Michael S. Tsirkin, Jason Wang, Parav Pandit,
	virtualization, linux-kernel

On Sun, Aug 09, 2020 at 06:03:00AM +0000, Eli Cohen wrote:
> After all this patch is not fixing it all. If we get to default of the switch statement we will free invalid pointer so removing ack-ed by me.
> 
> The previous patch by Colin King fixes it.

Good point, sounds sensible. Thanks for looking my patch over :-)

Alex

> 
> 
> -----Original Message-----
> From: Eli Cohen <eli@mellanox.com> 
> Sent: Sunday, August 9, 2020 8:53 AM
> To: Alex Dewar <alex.dewar90@gmail.com>
> Cc: Michael S. Tsirkin <mst@redhat.com>; Jason Wang <jasowang@redhat.com>; Parav Pandit <parav@mellanox.com>; virtualization@lists.linux-foundation.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] vdpa/mlx5: Fix erroneous null pointer checks
> 
> Acked-by: Eli Cohen <eli@mellanox.com>
> On Thu, Aug 06, 2020 at 08:18:39PM +0100, Alex Dewar wrote:
> > In alloc_inout() in net/mlx5_vnet.c, there are a few places where 
> > memory is allocated to *in and *out, but only the values of in and out 
> > are null-checked (i.e. there is a missing dereference). Fix this.
> > 
> > Addresses-Coverity: ("CID 1496603: (REVERSE_INULL)")
> > Fixes: 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 
> > devices")
> > Signed-off-by: Alex Dewar <alex.dewar90@gmail.com>
> > ---
> >  drivers/vdpa/mlx5/net/mlx5_vnet.c | 8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c 
> > b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > index 3ec44a4f0e45..bcb6600c2839 100644
> > --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > @@ -867,7 +867,7 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
> >  		*outlen = MLX5_ST_SZ_BYTES(qp_2rst_out);
> >  		*in = kzalloc(*inlen, GFP_KERNEL);
> >  		*out = kzalloc(*outlen, GFP_KERNEL);
> > -		if (!in || !out)
> > +		if (!*in || !*out)
> >  			goto outerr;
> >  
> >  		MLX5_SET(qp_2rst_in, *in, opcode, cmd); @@ -879,7 +879,7 @@ static 
> > void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
> >  		*outlen = MLX5_ST_SZ_BYTES(rst2init_qp_out);
> >  		*in = kzalloc(*inlen, GFP_KERNEL);
> >  		*out = kzalloc(MLX5_ST_SZ_BYTES(rst2init_qp_out), GFP_KERNEL);
> > -		if (!in || !out)
> > +		if (!*in || !*out)
> >  			goto outerr;
> >  
> >  		MLX5_SET(rst2init_qp_in, *in, opcode, cmd); @@ -896,7 +896,7 @@ 
> > static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
> >  		*outlen = MLX5_ST_SZ_BYTES(init2rtr_qp_out);
> >  		*in = kzalloc(*inlen, GFP_KERNEL);
> >  		*out = kzalloc(MLX5_ST_SZ_BYTES(init2rtr_qp_out), GFP_KERNEL);
> > -		if (!in || !out)
> > +		if (!*in || !*out)
> >  			goto outerr;
> >  
> >  		MLX5_SET(init2rtr_qp_in, *in, opcode, cmd); @@ -914,7 +914,7 @@ 
> > static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
> >  		*outlen = MLX5_ST_SZ_BYTES(rtr2rts_qp_out);
> >  		*in = kzalloc(*inlen, GFP_KERNEL);
> >  		*out = kzalloc(MLX5_ST_SZ_BYTES(rtr2rts_qp_out), GFP_KERNEL);
> > -		if (!in || !out)
> > +		if (!*in || !*out)
> >  			goto outerr;
> >  
> >  		MLX5_SET(rtr2rts_qp_in, *in, opcode, cmd);
> > --
> > 2.28.0
> > 

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

end of thread, other threads:[~2020-08-09 16:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-06 19:18 [PATCH] vdpa/mlx5: Fix erroneous null pointer checks Alex Dewar
2020-08-07  3:37 ` Jason Wang
2020-08-07  3:59   ` Jason Wang
2020-08-09  5:52 ` Eli Cohen
2020-08-09  6:03   ` Eli Cohen
2020-08-09 16:21     ` Alex Dewar

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).