Skip to content

Commit 0852e45

Browse files
congwangdavem330
authored andcommitted
net_sched: unify the init logic for act_police
Jamal reported a crash when we create a police action with a specific index, this is because the init logic is not correct, we should always create one for this case. Just unify the logic with other tc actions. Fixes: a03e6fe ("act_police: fix a crash during removal") Reported-by: Jamal Hadi Salim <jhs@mojatatu.com> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Acked-by: Jamal Hadi Salim <jhs@mojatatu.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 22dc13c commit 0852e45

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

net/sched/act_police.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ static int tcf_act_police_init(struct net *net, struct nlattr *nla,
125125
struct tcf_police *police;
126126
struct qdisc_rate_table *R_tab = NULL, *P_tab = NULL;
127127
struct tc_action_net *tn = net_generic(net, police_net_id);
128+
bool exists = false;
128129
int size;
129130

130131
if (nla == NULL)
@@ -139,24 +140,24 @@ static int tcf_act_police_init(struct net *net, struct nlattr *nla,
139140
size = nla_len(tb[TCA_POLICE_TBF]);
140141
if (size != sizeof(*parm) && size != sizeof(struct tc_police_compat))
141142
return -EINVAL;
143+
142144
parm = nla_data(tb[TCA_POLICE_TBF]);
145+
exists = tcf_hash_check(tn, parm->index, a, bind);
146+
if (exists && bind)
147+
return 0;
143148

144-
if (parm->index) {
145-
if (tcf_hash_check(tn, parm->index, a, bind)) {
146-
if (ovr)
147-
goto override;
148-
/* not replacing */
149-
return -EEXIST;
150-
}
151-
} else {
149+
if (!exists) {
152150
ret = tcf_hash_create(tn, parm->index, NULL, a,
153151
&act_police_ops, bind, false);
154152
if (ret)
155153
return ret;
156154
ret = ACT_P_CREATED;
155+
} else {
156+
tcf_hash_release(*a, bind);
157+
if (!ovr)
158+
return -EEXIST;
157159
}
158160

159-
override:
160161
police = to_police(*a);
161162
if (parm->rate.rate) {
162163
err = -ENOMEM;

0 commit comments

Comments
 (0)