Skip to contentSkip to conversation

vdpa/mlx5: Fix erroneous null pointer checks

PATCH In review Alex Dewar 3 participants 6 messages Aug 6, 2020 – Aug 9, 2020

Subsystems (2)
lore
Share & tools
lore

Alex Dewar

author
#0 lore raw

PATCH 1/1 vdpa/mlx5: Fix erroneous null pointer checks

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")
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +4 -4
index 3ec44a4f0e45..bcb6600c2839 100644
@@ -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);
Signature · 1 line
2.28.0
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Alex Dewar

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")
Quoted 44 lines
---
  drivers/vdpa/mlx5/net/mlx5_vnet.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +4 -4
index 3ec44a4f0e45..bcb6600c2839 100644
@@ -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 lore raw
Quoted 6 lines · Jason Wang
Quoted 4 lines · Alex Dewar

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.

Quoted 6 lines
Quoted 3 lines

Addresses-Coverity: ("CID 1496603: (REVERSE_INULL)")

Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")

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

Acked-by on v1 1/1
#3 lore raw
In reply to Alex Dewar
Quoted 54 lines · Alex Dewar

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")
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +4 -4
index 3ec44a4f0e45..bcb6600c2839 100644
@@ -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);
Signature · 1 line
2.28.0
Acked-by
#4 lore raw

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 <[email protected]>
Sent: Sunday, August 9, 2020 8:53 AM
To: Alex Dewar <[email protected]>
Cc: Michael S. Tsirkin <[email protected]>; Jason Wang <[email protected]>; Parav Pandit <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] vdpa/mlx5: Fix erroneous null pointer checks

Quoted 56 lines · Alex Dewar

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

---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -1
index 3ec44a4f0e45..bcb6600c2839 100644
@@ -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

drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -1
 		*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

drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -1
 		*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

drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -2
 		*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

author
#5 lore raw
Quoted 3 lines · Eli Cohen

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

Quoted 67 lines

-----Original Message-----
From: Eli Cohen <[email protected]>
Sent: Sunday, August 9, 2020 8:53 AM
To: Alex Dewar <[email protected]>
Cc: Michael S. Tsirkin <[email protected]>; Jason Wang <[email protected]>; Parav Pandit <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] vdpa/mlx5: Fix erroneous null pointer checks

Quoted 56 lines · Alex Dewar

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

---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -1
index 3ec44a4f0e45..bcb6600c2839 100644
@@ -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

drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -1
 		*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

drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -1
 		*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

drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -2
 		*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