Skip to content

Commit b3650bf

Browse files
w1ldptrdavem330
authored andcommitted
net: sched: fix err handler in tcf_action_init()
With recent changes that separated action module load from action initialization tcf_action_init() function error handling code was modified to manually release the loaded modules if loading/initialization of any further action in same batch failed. For the case when all modules successfully loaded and some of the actions were initialized before one of them failed in init handler. In this case for all previous actions the module will be released twice by the error handler: First time by the loop that manually calls module_put() for all ops, and second time by the action destroy code that puts the module after destroying the action. Reproduction: $ sudo tc actions add action simple sdata \"2\" index 2 $ sudo tc actions add action simple sdata \"1\" index 1 \ action simple sdata \"2\" index 2 RTNETLINK answers: File exists We have an error talking to the kernel $ sudo tc actions ls action simple total acts 1 action order 0: Simple <"2"> index 2 ref 1 bind 0 $ sudo tc actions flush action simple $ sudo tc actions ls action simple $ sudo tc actions add action simple sdata \"2\" index 2 Error: Failed to load TC action module. We have an error talking to the kernel $ lsmod | grep simple act_simple 20480 -1 Fix the issue by modifying module reference counting handling in action initialization code: - Get module reference in tcf_idr_create() and put it in tcf_idr_release() instead of taking over the reference held by the caller. - Modify users of tcf_action_init_1() to always release the module reference which they obtain before calling init function instead of assuming that created action takes over the reference. - Finally, modify tcf_action_init_1() to not release the module reference when overwriting existing action as this is no longer necessary since both upper and lower layers obtain and manage their own module references independently. Fixes: d349f99 ("net_sched: fix RTNL deadlock again caused by request_module()") Suggested-by: Cong Wang <[email protected]> Signed-off-by: Vlad Buslov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 87c750e commit b3650bf

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

include/net/act_api.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,7 @@ void tcf_idr_insert_many(struct tc_action *actions[]);
170170
void tcf_idr_cleanup(struct tc_action_net *tn, u32 index);
171171
int tcf_idr_check_alloc(struct tc_action_net *tn, u32 *index,
172172
struct tc_action **a, int bind);
173-
int __tcf_idr_release(struct tc_action *a, bool bind, bool strict);
174-
175-
static inline int tcf_idr_release(struct tc_action *a, bool bind)
176-
{
177-
return __tcf_idr_release(a, bind, false);
178-
}
173+
int tcf_idr_release(struct tc_action *a, bool bind);
179174

180175
int tcf_register_action(struct tc_action_ops *a, struct pernet_operations *ops);
181176
int tcf_unregister_action(struct tc_action_ops *a,

net/sched/act_api.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static int __tcf_action_put(struct tc_action *p, bool bind)
158158
return 0;
159159
}
160160

161-
int __tcf_idr_release(struct tc_action *p, bool bind, bool strict)
161+
static int __tcf_idr_release(struct tc_action *p, bool bind, bool strict)
162162
{
163163
int ret = 0;
164164

@@ -184,7 +184,18 @@ int __tcf_idr_release(struct tc_action *p, bool bind, bool strict)
184184

185185
return ret;
186186
}
187-
EXPORT_SYMBOL(__tcf_idr_release);
187+
188+
int tcf_idr_release(struct tc_action *a, bool bind)
189+
{
190+
const struct tc_action_ops *ops = a->ops;
191+
int ret;
192+
193+
ret = __tcf_idr_release(a, bind, false);
194+
if (ret == ACT_P_DELETED)
195+
module_put(ops->owner);
196+
return ret;
197+
}
198+
EXPORT_SYMBOL(tcf_idr_release);
188199

189200
static size_t tcf_action_shared_attrs_size(const struct tc_action *act)
190201
{
@@ -493,6 +504,7 @@ int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est,
493504
}
494505

495506
p->idrinfo = idrinfo;
507+
__module_get(ops->owner);
496508
p->ops = ops;
497509
*a = p;
498510
return 0;
@@ -1037,13 +1049,6 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
10371049
if (!name)
10381050
a->hw_stats = hw_stats;
10391051

1040-
/* module count goes up only when brand new policy is created
1041-
* if it exists and is only bound to in a_o->init() then
1042-
* ACT_P_CREATED is not returned (a zero is).
1043-
*/
1044-
if (err != ACT_P_CREATED)
1045-
module_put(a_o->owner);
1046-
10471052
return a;
10481053

10491054
err_out:
@@ -1103,7 +1108,8 @@ int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla,
11031108
tcf_idr_insert_many(actions);
11041109

11051110
*attr_size = tcf_action_full_attrs_size(sz);
1106-
return i - 1;
1111+
err = i - 1;
1112+
goto err_mod;
11071113

11081114
err:
11091115
tcf_action_destroy(actions, bind);

net/sched/cls_api.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3054,10 +3054,9 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb,
30543054
rate_tlv, "police", ovr,
30553055
TCA_ACT_BIND, a_o, init_res,
30563056
rtnl_held, extack);
3057-
if (IS_ERR(act)) {
3058-
module_put(a_o->owner);
3057+
module_put(a_o->owner);
3058+
if (IS_ERR(act))
30593059
return PTR_ERR(act);
3060-
}
30613060

30623061
act->type = exts->type = TCA_OLD_COMPAT;
30633062
exts->actions[0] = act;

0 commit comments

Comments
 (0)