Skip to contentSkip to conversation

net: sched: fix possible refcount leak in tc_new_tfilter()

PATCH In review Hangyu Hua 3 participants 4 messages Sep 15, 2022 – Sep 21, 2022

Subsystems (3)
lore
Share & tools
lore

Hangyu Hua

author
#0 lore raw

PATCH 1/1 net: sched: fix possible refcount leak in tc_new_tfilter()

tfilter_put need to be called to put the refount got by tp->ops->get to avoid possible refcount leak when chain->tmplt_ops == NULL or chain->tmplt_ops != tp->ops.

Fixes 7d5509fa0d3d ("net: sched: extend proto ops with 'put' callback")
---
 net/sched/cls_api.c | 1 +
 1 file changed, 1 insertion(+)
net/sched/cls_api.c +1 -0
index 790d6809be81..51d175f3fbcb 100644
@@ -2137,6 +2137,7 @@ static int tc_new_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
 	}
 
 	if (chain->tmplt_ops && chain->tmplt_ops != tp->ops) {
+		tfilter_put(tp, fh);
 		NL_SET_ERR_MSG(extack, "Chain template is set to a different filter kind");
 		err = -EINVAL;
 		goto errout;
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Hangyu Hua

tfilter_put need to be called to put the refount got by tp->ops->get to avoid possible refcount leak when chain->tmplt_ops == NULL or chain->tmplt_ops != tp->ops.

Fixes 7d5509fa0d3d ("net: sched: extend proto ops with 'put' callback")

---

Thanks for fixing this!

Quoted 15 lines
 net/sched/cls_api.c | 1 +
 1 file changed, 1 insertion(+)
net/sched/cls_api.c +1 -0
index 790d6809be81..51d175f3fbcb 100644
@@ -2137,6 +2137,7 @@ static int tc_new_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
 	}
 
 	if (chain->tmplt_ops && chain->tmplt_ops != tp->ops) {
+		tfilter_put(tp, fh);
 		NL_SET_ERR_MSG(extack, "Chain template is set to a different filter kind");
 		err = -EINVAL;
 		goto errout;
maintainer
#2 lore raw
In reply to Hangyu Hua
Quoted 1 line · On Thu, 15 Sep 2022 16:58:04 +0800 Hangyu Hua wrote:

tfilter_put need to be called to put the refount got by tp->ops->get to

s/refount/refcount/

Quoted 2 lines

avoid possible refcount leak when chain->tmplt_ops == NULL or chain->tmplt_ops != tp->ops.

This should say:

when cain->tmplt_ops != NULL and ...

otherwise the commit message does not match the code.

Quoted 18 lines
Fixes 7d5509fa0d3d ("net: sched: extend proto ops with 'put' callback")
---
 net/sched/cls_api.c | 1 +
 1 file changed, 1 insertion(+)
net/sched/cls_api.c +1 -0
index 790d6809be81..51d175f3fbcb 100644
@@ -2137,6 +2137,7 @@ static int tc_new_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
 	}
 
 	if (chain->tmplt_ops && chain->tmplt_ops != tp->ops) {
+		tfilter_put(tp, fh);
 		NL_SET_ERR_MSG(extack, "Chain template is set to a different filter kind");
 		err = -EINVAL;
 		goto errout;
author
#3 lore raw
Quoted 5 lines · Jakub Kicinski
Quoted 1 line · On Thu, 15 Sep 2022 16:58:04 +0800 Hangyu Hua wrote:

tfilter_put need to be called to put the refount got by tp->ops->get to

s/refount/refcount/

Quoted 9 lines
Quoted 2 lines

avoid possible refcount leak when chain->tmplt_ops == NULL or chain->tmplt_ops != tp->ops.

This should say:

   when cain->tmplt_ops != NULL and ...

otherwise the commit message does not match the code.

My bad. I will submit a v2.

Thanks,
Hangyu

Quoted 19 lines
Quoted 18 lines
Fixes 7d5509fa0d3d ("net: sched: extend proto ops with 'put' callback")
---
  net/sched/cls_api.c | 1 +
  1 file changed, 1 insertion(+)
net/sched/cls_api.c +1 -0
index 790d6809be81..51d175f3fbcb 100644
@@ -2137,6 +2137,7 @@ static int tc_new_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
  	}
 
  	if (chain->tmplt_ops && chain->tmplt_ops != tp->ops) {
+		tfilter_put(tp, fh);
  		NL_SET_ERR_MSG(extack, "Chain template is set to a different filter kind");
  		err = -EINVAL;
  		goto errout;