Skip to content

Commit fa1b1cf

Browse files
Jamal Hadi Salimdavem330
authored andcommitted
net_cls_act: Make act_simple use of netlink policy.
Convert to netlink helpers by using netlink policy validation. As a side effect fixes a leak. Signed-off-by: Jamal Hadi Salim <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5ffc02a commit fa1b1cf

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

net/sched/act_simple.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* as published by the Free Software Foundation; either version
77
* 2 of the License, or (at your option) any later version.
88
*
9-
* Authors: Jamal Hadi Salim (2005)
9+
* Authors: Jamal Hadi Salim (2005-8)
1010
*
1111
*/
1212

@@ -34,6 +34,7 @@ static struct tcf_hashinfo simp_hash_info = {
3434
.lock = &simp_lock,
3535
};
3636

37+
#define SIMP_MAX_DATA 32
3738
static int tcf_simp(struct sk_buff *skb, struct tc_action *a, struct tcf_result *res)
3839
{
3940
struct tcf_defact *d = a->priv;
@@ -69,23 +70,24 @@ static int tcf_simp_release(struct tcf_defact *d, int bind)
6970
return ret;
7071
}
7172

72-
static int alloc_defdata(struct tcf_defact *d, u32 datalen, void *defdata)
73+
static int alloc_defdata(struct tcf_defact *d, char *defdata)
7374
{
74-
d->tcfd_defdata = kmemdup(defdata, datalen, GFP_KERNEL);
75+
d->tcfd_defdata = kstrndup(defdata, SIMP_MAX_DATA, GFP_KERNEL);
7576
if (unlikely(!d->tcfd_defdata))
7677
return -ENOMEM;
77-
d->tcfd_datalen = datalen;
78+
7879
return 0;
7980
}
8081

81-
static int realloc_defdata(struct tcf_defact *d, u32 datalen, void *defdata)
82+
static int realloc_defdata(struct tcf_defact *d, char *defdata)
8283
{
8384
kfree(d->tcfd_defdata);
84-
return alloc_defdata(d, datalen, defdata);
85+
return alloc_defdata(d, defdata);
8586
}
8687

8788
static const struct nla_policy simple_policy[TCA_DEF_MAX + 1] = {
8889
[TCA_DEF_PARMS] = { .len = sizeof(struct tc_defact) },
90+
[TCA_DEF_DATA] = { .type = NLA_STRING, .len = SIMP_MAX_DATA },
8991
};
9092

9193
static int tcf_simp_init(struct nlattr *nla, struct nlattr *est,
@@ -95,28 +97,24 @@ static int tcf_simp_init(struct nlattr *nla, struct nlattr *est,
9597
struct tc_defact *parm;
9698
struct tcf_defact *d;
9799
struct tcf_common *pc;
98-
void *defdata;
99-
u32 datalen = 0;
100+
char *defdata;
100101
int ret = 0, err;
101102

102103
if (nla == NULL)
103104
return -EINVAL;
104105

105-
err = nla_parse_nested(tb, TCA_DEF_MAX, nla, NULL);
106+
err = nla_parse_nested(tb, TCA_DEF_MAX, nla, simple_policy);
106107
if (err < 0)
107108
return err;
108109

109110
if (tb[TCA_DEF_PARMS] == NULL)
110111
return -EINVAL;
111112

112-
parm = nla_data(tb[TCA_DEF_PARMS]);
113-
defdata = nla_data(tb[TCA_DEF_DATA]);
114-
if (defdata == NULL)
113+
if (tb[TCA_DEF_DATA] == NULL)
115114
return -EINVAL;
116115

117-
datalen = nla_len(tb[TCA_DEF_DATA]);
118-
if (datalen == 0)
119-
return -EINVAL;
116+
parm = nla_data(tb[TCA_DEF_PARMS]);
117+
defdata = nla_data(tb[TCA_DEF_DATA]);
120118

121119
pc = tcf_hash_check(parm->index, a, bind, &simp_hash_info);
122120
if (!pc) {
@@ -126,7 +124,7 @@ static int tcf_simp_init(struct nlattr *nla, struct nlattr *est,
126124
return -ENOMEM;
127125

128126
d = to_defact(pc);
129-
ret = alloc_defdata(d, datalen, defdata);
127+
ret = alloc_defdata(d, defdata);
130128
if (ret < 0) {
131129
kfree(pc);
132130
return ret;
@@ -138,7 +136,7 @@ static int tcf_simp_init(struct nlattr *nla, struct nlattr *est,
138136
tcf_simp_release(d, bind);
139137
return -EEXIST;
140138
}
141-
realloc_defdata(d, datalen, defdata);
139+
realloc_defdata(d, defdata);
142140
}
143141

144142
spin_lock_bh(&d->tcf_lock);
@@ -172,7 +170,7 @@ static inline int tcf_simp_dump(struct sk_buff *skb, struct tc_action *a,
172170
opt.bindcnt = d->tcf_bindcnt - bind;
173171
opt.action = d->tcf_action;
174172
NLA_PUT(skb, TCA_DEF_PARMS, sizeof(opt), &opt);
175-
NLA_PUT(skb, TCA_DEF_DATA, d->tcfd_datalen, d->tcfd_defdata);
173+
NLA_PUT_STRING(skb, TCA_DEF_DATA, d->tcfd_defdata);
176174
t.install = jiffies_to_clock_t(jiffies - d->tcf_tm.install);
177175
t.lastuse = jiffies_to_clock_t(jiffies - d->tcf_tm.lastuse);
178176
t.expires = jiffies_to_clock_t(d->tcf_tm.expires);

0 commit comments

Comments
 (0)