diff mbox

[v2] net/mlx5: Fix use-after-free

Message ID 20180322184456.GA22259@embeddedgus (mailing list archive)
State Not Applicable
Headers show

Commit Message

Gustavo A. R. Silva March 22, 2018, 6:44 p.m. UTC
_rule_ is being freed and then dereferenced by accessing rule->ctx

Fix this by copying the value returned by PTR_ERR(rule->ctx) into a local
variable for its safe use after freeing _rule_

Addresses-Coverity-ID: 1466041 ("Read from pointer after free")
Fixes: 05564d0ae075 ("net/mlx5: Add flow-steering commands for FPGA IPSec implementation")
Reviewed-by: Yuval Shaia <yuval.shaia@oracle.com>
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
Changes in v2:
 - Use a short subject prefix as suggested by Yuval Shaia.
 - Add Yuval's Reviewed-by.

 drivers/net/ethernet/mellanox/mlx5/core/fpga/ipsec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Saeed Mahameed March 22, 2018, 10:08 p.m. UTC | #1
On Thu, 2018-03-22 at 13:44 -0500, Gustavo A. R. Silva wrote:
> _rule_ is being freed and then dereferenced by accessing rule->ctx

> 

> Fix this by copying the value returned by PTR_ERR(rule->ctx) into a

> local

> variable for its safe use after freeing _rule_

> 

> Addresses-Coverity-ID: 1466041 ("Read from pointer after free")

> Fixes: 05564d0ae075 ("net/mlx5: Add flow-steering commands for FPGA

> IPSec implementation")

> Reviewed-by: Yuval Shaia <yuval.shaia@oracle.com>

> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>


Acked-by: Saeed Mahameed <saeedm@mellanox.com>


> ---

> Changes in v2:

>  - Use a short subject prefix as suggested by Yuval Shaia.

>  - Add Yuval's Reviewed-by.

> 

>  drivers/net/ethernet/mellanox/mlx5/core/fpga/ipsec.c | 3 ++-

>  1 file changed, 2 insertions(+), 1 deletion(-)

> 

> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fpga/ipsec.c

> b/drivers/net/ethernet/mellanox/mlx5/core/fpga/ipsec.c

> index 4f15685..0f5da49 100644

> --- a/drivers/net/ethernet/mellanox/mlx5/core/fpga/ipsec.c

> +++ b/drivers/net/ethernet/mellanox/mlx5/core/fpga/ipsec.c

> @@ -1061,8 +1061,9 @@ static int fpga_ipsec_fs_create_fte(struct

> mlx5_core_dev *dev,

>  

>  	rule->ctx = mlx5_fpga_ipsec_fs_create_sa_ctx(dev, fte,

> is_egress);

>  	if (IS_ERR(rule->ctx)) {

> +		int err = PTR_ERR(rule->ctx);

>  		kfree(rule);

> -		return PTR_ERR(rule->ctx);

> +		return err;

>  	}

>  

>  	rule->fte = fte;
David Miller March 23, 2018, 5:06 p.m. UTC | #2
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
Date: Thu, 22 Mar 2018 13:44:56 -0500

> _rule_ is being freed and then dereferenced by accessing rule->ctx
> 
> Fix this by copying the value returned by PTR_ERR(rule->ctx) into a local
> variable for its safe use after freeing _rule_
> 
> Addresses-Coverity-ID: 1466041 ("Read from pointer after free")
> Fixes: 05564d0ae075 ("net/mlx5: Add flow-steering commands for FPGA IPSec implementation")
> Reviewed-by: Yuval Shaia <yuval.shaia@oracle.com>
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
> Changes in v2:
>  - Use a short subject prefix as suggested by Yuval Shaia.
>  - Add Yuval's Reviewed-by.

Applied to net-next.

Thank you.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fpga/ipsec.c b/drivers/net/ethernet/mellanox/mlx5/core/fpga/ipsec.c
index 4f15685..0f5da49 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/fpga/ipsec.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fpga/ipsec.c
@@ -1061,8 +1061,9 @@  static int fpga_ipsec_fs_create_fte(struct mlx5_core_dev *dev,
 
 	rule->ctx = mlx5_fpga_ipsec_fs_create_sa_ctx(dev, fte, is_egress);
 	if (IS_ERR(rule->ctx)) {
+		int err = PTR_ERR(rule->ctx);
 		kfree(rule);
-		return PTR_ERR(rule->ctx);
+		return err;
 	}
 
 	rule->fte = fte;