Skip to contentSkip to conversation

net/mlx5e: fix bpf_prog refcnt leaks in mlx5e_alloc_rq

PATCH Superseded Xin Xiong 3 participants 4 messages Jul 29, 2020

Subsystems (6)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Xin Xiong

author
#0 lore raw

PATCH 1/1 net/mlx5e: fix bpf_prog refcnt leaks in mlx5e_alloc_rq

The function invokes bpf_prog_inc(), which increases the refcount of a bpf_prog object "rq->xdp_prog" if the object isn't NULL.

The refcount leak issues take place in two error handling paths. When mlx5_wq_ll_create() or mlx5_wq_cyc_create() fails, the function simply returns the error code and forgets to drop the refcount increased earlier, causing a refcount leak of "rq->xdp_prog".

Fix this issue by jumping to the error handling path err_rq_wq_destroy when either function fails.

---
 drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +2 -2
index a836a02a2116..8e1b1ab416d8 100644
@@ -419,7 +419,7 @@ static int mlx5e_alloc_rq(struct mlx5e_channel *c,
 		err = mlx5_wq_ll_create(mdev, &rqp->wq, rqc_wq, &rq->mpwqe.wq,
 					&rq->wq_ctrl);
 		if (err)
-			return err;
+			goto err_rq_wq_destroy;
 
 		rq->mpwqe.wq.db = &rq->mpwqe.wq.db[MLX5_RCV_DBR];
 
@@ -470,7 +470,7 @@ static int mlx5e_alloc_rq(struct mlx5e_channel *c,
 		err = mlx5_wq_cyc_create(mdev, &rqp->wq, rqc_wq, &rq->wqe.wq,
 					 &rq->wq_ctrl);
 		if (err)
-			return err;
+			goto err_rq_wq_destroy;
 
 		rq->wqe.wq.db = &rq->wqe.wq.db[MLX5_RCV_DBR];
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 10 lines · Xin Xiong

The function invokes bpf_prog_inc(), which increases the refcount of a
bpf_prog object "rq->xdp_prog" if the object isn't NULL.

The refcount leak issues take place in two error handling paths. When mlx5_wq_ll_create() or mlx5_wq_cyc_create() fails, the function simply
returns the error code and forgets to drop the refcount increased earlier, causing a refcount leak of "rq->xdp_prog".

Quoted 4 lines

Fix this issue by jumping to the error handling path err_rq_wq_destroy
when either function fails.

Fixes 422d4c401edd ("net/mlx5e: RX, Split WQ objects for different RQ

types")

Quoted 35 lines
---
 drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +1 -1
index a836a02a2116..8e1b1ab416d8 100644
@@ -419,7 +419,7 @@ static int mlx5e_alloc_rq(struct mlx5e_channel
 *c,
 		err = mlx5_wq_ll_create(mdev, &rqp->wq, rqc_wq, &rq-
 >mpwqe.wq,
 					&rq->wq_ctrl);
 		if (err)
-			return err;
+			goto err_rq_wq_destroy;
 
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +1 -1
 		rq->mpwqe.wq.db = &rq->mpwqe.wq.db[MLX5_RCV_DBR];
@@ -470,7 +470,7 @@ static int mlx5e_alloc_rq(struct mlx5e_channel
 *c,
 		err = mlx5_wq_cyc_create(mdev, &rqp->wq, rqc_wq, &rq-
 >wqe.wq,
 					 &rq->wq_ctrl);
 		if (err)
-			return err;
+			goto err_rq_wq_destroy;
 

rq->wqe.wq.db = &rq->wqe.wq.db[MLX5_RCV_DBR];

maintainer
#2 lore raw

From: Saeed Mahameed <[email protected]>
Date: Wed, 29 Jul 2020 19:02:15 +0000

Quoted 11 lines · Xin Xiong
Quoted 10 lines

The function invokes bpf_prog_inc(), which increases the refcount of a
bpf_prog object "rq->xdp_prog" if the object isn't NULL.

The refcount leak issues take place in two error handling paths. When mlx5_wq_ll_create() or mlx5_wq_cyc_create() fails, the function simply
returns the error code and forgets to drop the refcount increased earlier, causing a refcount leak of "rq->xdp_prog".

Quoted 7 lines
Quoted 4 lines

Fix this issue by jumping to the error handling path err_rq_wq_destroy
when either function fails.

Fixes 422d4c401edd ("net/mlx5e: RX, Split WQ objects for different RQ

types")

Saeed, are you going to take this into your tree or would you like me to apply it directly?

Thanks.

#3 lore raw
Quoted 9 lines · David Miller

From: Saeed Mahameed <[email protected]>
Date: Wed, 29 Jul 2020 19:02:15 +0000

Quoted 6 lines
Quoted 4 lines

Fix this issue by jumping to the error handling path err_rq_wq_destroy
when either function fails.

Fixes 422d4c401edd ("net/mlx5e: RX, Split WQ objects for different
Quoted 8 lines

RQ

Quoted 1 line

types")

Saeed, are you going to take this into your tree or would you like me to
apply it directly?

Thanks.

I will take this to my tree once Xin adds the missing Fixes tag. Thanks.