net: sched: fix possible refcount leak in tc_chain_tmplt_add()
Subsystems (3)
PATCH 1/1 net: sched: fix possible refcount leak in tc_chain_tmplt_add()
try_module_get can be called in tcf_proto_lookup_ops. So if ops don't implement the corresponding function we should call module_put to drop the refcount.
--- net/sched/cls_api.c | 1 + 1 file changed, 1 insertion(+)
net/sched/cls_api.c +1 -0
@@ -2952,6 +2952,7 @@ static int tc_chain_tmplt_add(struct tcf_chain *chain, struct net *net,return PTR_ERR (ops);if (!ops->tmplt_create || !ops->tmplt_destroy || !ops->tmplt_dump) {NL_SET_ERR_MSG (extack,"Chain templates are not supported with specified classifier" ); +module_put (ops->owner);return -EOPNOTSUPP ; }
Signature · 1 line
2.34.1
Quoted 3 lines · Hangyu Hua
try_module_getcan be called intcf_proto_lookup_ops. So if ops don't implement the corresponding function we should callmodule_putto drop the refcount.
Hi Hangyu Hua,
Is this correct even if try_module_get() is
not called via tcf_proto_lookup_ops() ?
Quoted 22 lines
Fixes 9f407f1768d3 ("net: sched: introduce chain templates")Signed-off-by Hangyu Hua <[email protected]>--- net/sched/cls_api.c | 1 + 1 file changed, 1 insertion(+)net/sched/cls_api.c +1
-0@@ -2952,6 +2952,7 @@ static int tc_chain_tmplt_add(struct tcf_chain *chain, struct net *net,return PTR_ERR (ops);if (!ops->tmplt_create || !ops->tmplt_destroy || !ops->tmplt_dump) {NL_SET_ERR_MSG (extack,"Chain templates are not supported with specified classifier" ); +module_put (ops->owner);return -EOPNOTSUPP ; }Signature · 1 line
2.34.1
Quoted 10 lines · Simon Horman
Quoted 3 lines · Hangyu Hua
try_module_getcan be called intcf_proto_lookup_ops. So if ops don't implement the corresponding function we should callmodule_putto drop the refcount.Hi Hangyu Hua,
Is this correct even if
try_module_get()is
not called viatcf_proto_lookup_ops()?
tcf_proto_lookup_ops will return error if try_module_get() is not called in tcf_proto_lookup_ops(). I am not sure what you mean?
Thanks,
Hangyu
Quoted 22 lines
Quoted 22 lines
Fixes 9f407f1768d3 ("net: sched: introduce chain templates")Signed-off-by Hangyu Hua <[email protected]>--- net/sched/cls_api.c | 1 + 1 file changed, 1 insertion(+)net/sched/cls_api.c +1
-0@@ -2952,6 +2952,7 @@ static int tc_chain_tmplt_add(struct tcf_chain *chain, struct net *net,return PTR_ERR (ops);if (!ops->tmplt_create || !ops->tmplt_destroy || !ops->tmplt_dump) {NL_SET_ERR_MSG (extack,"Chain templates are not supported with specified classifier" ); +module_put (ops->owner);return -EOPNOTSUPP ; }Signature · 1 line
2.34.1
Quoted 4 lines · Hangyu Hua
try_module_getcan be called intcf_proto_lookup_ops. So if ops don't implement the corresponding function we should callmodule_putto drop the refcount.
Code seems reasonable. But commit message is pretty hard to understand. Please, replace "corresponding" with "required".
Also change the first sentence, do not use "can". From what I see, successful execution of tcf_proto_lookup_ops always means we now hold reference to module.
CC me in v2, I'll give you Reviewed-by.
Quoted 22 lines
Fixes 9f407f1768d3 ("net: sched: introduce chain templates")Signed-off-by Hangyu Hua <[email protected]>--- net/sched/cls_api.c | 1 + 1 file changed, 1 insertion(+)net/sched/cls_api.c +1
-0@@ -2952,6 +2952,7 @@ static int tc_chain_tmplt_add(struct tcf_chain *chain, struct net *net,return PTR_ERR (ops);if (!ops->tmplt_create || !ops->tmplt_destroy || !ops->tmplt_dump) {NL_SET_ERR_MSG (extack,"Chain templates are not supported with specified classifier" ); +module_put (ops->owner);return -EOPNOTSUPP ; }Signature · 1 line
2.34.1
Quoted 6 lines · Hangyu Hua
Quoted 5 lines · Simon Horman
Quoted 3 lines · Hangyu Hua
try_module_getcan be called intcf_proto_lookup_ops. So if ops don't implement the corresponding function we should callmodule_putto drop the refcount.
Quoted 8 lines
Quoted 5 lines
Hi Hangyu Hua,
Is this correct even if
try_module_get()is
not called viatcf_proto_lookup_ops()?
tcf_proto_lookup_opswill return error iftry_module_get()is not called intcf_proto_lookup_ops(). I am not sure what you mean?
Thanks,
I think that answers my question.
My concern was if there is a situation where module_put() is now called, but there was not in fact a reference that should be released.
...
Jiri Pirko
maintainerQuoted 3 lines · Mon, Jun 05, 2023 at 09:01:58AM CEST, [email protected] wrote:
try_module_getcan be called intcf_proto_lookup_ops. So if ops don't implement the corresponding function we should callmodule_putto drop the refcount.
Who's "we"? Use imperative mood. Tell the codebase what to do, what to change, etc.
Code-wise, this is fine. Please fix the patch description.
Quoted 22 lines
Fixes 9f407f1768d3 ("net: sched: introduce chain templates")Signed-off-by Hangyu Hua <[email protected]>---
net/sched/cls_api.c| 1 +1 file changed, 1 insertion(+)net/sched/cls_api.c +1
-0@@ -2952,6 +2952,7 @@ static int tc_chain_tmplt_add(struct tcf_chain *chain, struct net *net,return PTR_ERR (ops);if (!ops->tmplt_create || !ops->tmplt_destroy || !ops->tmplt_dump) {NL_SET_ERR_MSG (extack,"Chain templates are not supported with specified classifier" ); +module_put (ops->owner);return -EOPNOTSUPP ; }Signature · 1 line
2.34.1
Quoted 6 lines · Larysa Zaremba
Quoted 4 lines · Hangyu Hua
try_module_getcan be called intcf_proto_lookup_ops. So if ops don't implement the corresponding function we should callmodule_putto drop the refcount.
Quoted 7 lines
Code seems reasonable. But commit message is pretty hard to understand. Please, replace "corresponding" with "required".
Also change the first sentence, do not use "can". From what I see, successful execution oftcf_proto_lookup_opsalways means we now hold reference to module.CC me in v2, I'll give you Reviewed-by.
I apologize for my incorrect English expression. I will send a v2 later.
Thanks,
Hangyu
Quoted 22 lines
Quoted 22 lines
Fixes 9f407f1768d3 ("net: sched: introduce chain templates")Signed-off-by Hangyu Hua <[email protected]>--- net/sched/cls_api.c | 1 + 1 file changed, 1 insertion(+)net/sched/cls_api.c +1
-0@@ -2952,6 +2952,7 @@ static int tc_chain_tmplt_add(struct tcf_chain *chain, struct net *net,return PTR_ERR (ops);if (!ops->tmplt_create || !ops->tmplt_destroy || !ops->tmplt_dump) {NL_SET_ERR_MSG (extack,"Chain templates are not supported with specified classifier" ); +module_put (ops->owner);return -EOPNOTSUPP ; }Signature · 1 line
2.34.1