Skip to contentSkip to conversation

net/mlx5/core/fpga/ipsec: Fix use-after-free

PATCH Superseded Gustavo A. R. Silva 2 participants 3 messages Mar 22, 2018

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/mlx5/core/fpga/ipsec: Fix use-after-free

_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")
---
 drivers/net/ethernet/mellanox/mlx5/core/fpga/ipsec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/fpga/ipsec.c +2 -1
index 4f15685..0f5da49 100644
@@ -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;
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Gustavo A. R. Silva

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

Prefix should not be that long, a short one as this is enough.

net/mlx5: Fix use-after-free

Besides that - lgtm.

Quoted 26 lines
---
 drivers/net/ethernet/mellanox/mlx5/core/fpga/ipsec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/fpga/ipsec.c +2 -1
index 4f15685..0f5da49 100644
@@ -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;
Signature · 6 lines
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

Hi Yuval,

Quoted 12 lines · Yuval Shaia
Quoted 8 lines · Gustavo A. R. Silva

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

Prefix should not be that long, a short one as this is enough.

Yeah. Actually, I was suspicious about it.

Quoted 6 lines

net/mlx5: Fix use-after-free

Besides that - lgtm.

I'll send v2 with a short prefix and add your Reviewed-by.

Thanks for the feedback.
--
Gustavo