[PATCH] net: sched: fix possible refcount leak in tc_new_tfilter()

Hangyu Hua posted 1 patch 3 years, 6 months ago
There is a newer version of this series
net/sched/cls_api.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] net: sched: fix possible refcount leak in tc_new_tfilter()
Posted by Hangyu Hua 3 years, 6 months ago
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")
Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
---
 net/sched/cls_api.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 790d6809be81..51d175f3fbcb 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -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;
-- 
2.34.1
Re: [PATCH] net: sched: fix possible refcount leak in tc_new_tfilter()
Posted by Jakub Kicinski 3 years, 6 months ago
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/

> 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.

> Fixes: 7d5509fa0d3d ("net: sched: extend proto ops with 'put' callback")
> Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
> ---
>  net/sched/cls_api.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
> index 790d6809be81..51d175f3fbcb 100644
> --- a/net/sched/cls_api.c
> +++ b/net/sched/cls_api.c
> @@ -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;
Re: [PATCH] net: sched: fix possible refcount leak in tc_new_tfilter()
Posted by Hangyu Hua 3 years, 6 months ago
On 20/9/2022 23:50, Jakub Kicinski wrote:
> 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/
> 
>> 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

>> Fixes: 7d5509fa0d3d ("net: sched: extend proto ops with 'put' callback")
>> Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
>> ---
>>   net/sched/cls_api.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
>> index 790d6809be81..51d175f3fbcb 100644
>> --- a/net/sched/cls_api.c
>> +++ b/net/sched/cls_api.c
>> @@ -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;
>
Re: [PATCH] net: sched: fix possible refcount leak in tc_new_tfilter()
Posted by Vlad Buslov 3 years, 6 months ago
On Thu 15 Sep 2022 at 16:58, Hangyu Hua <hbh25y@gmail.com> wrote:
> 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")
> Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
> ---

Thanks for fixing this!

Reviewed-by: Vlad Buslov <vladbu@nvidia.com>

>  net/sched/cls_api.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
> index 790d6809be81..51d175f3fbcb 100644
> --- a/net/sched/cls_api.c
> +++ b/net/sched/cls_api.c
> @@ -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;