Skip to content

Commit e331473

Browse files
dcarattidavem330
authored andcommitted
net/sched: cls_api: add missing validation of netlink attributes
Similarly to what has been done in 8b4c3cd ("net: sched: Add policy validation for tc attributes"), fix classifier code to add validation of TCA_CHAIN and TCA_KIND netlink attributes. tested with: # ./tdc.py -c filter v2: Let sch_api and cls_api share nla_policy they have in common, thanks to David Ahern. v3: Avoid EXPORT_SYMBOL(), as validation of those attributes is not done by TC modules, thanks to Cong Wang. While at it, restore the 'Delete / get qdisc' comment to its orginal position, just above tc_get_qdisc() function prototype. Fixes: 5bc1701 ("net: sched: introduce multichain support for filters") Signed-off-by: Davide Caratti <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 58f5bbe commit e331473

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

net/sched/cls_api.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include <net/pkt_sched.h>
3232
#include <net/pkt_cls.h>
3333

34+
extern const struct nla_policy rtm_tca_policy[TCA_MAX + 1];
35+
3436
/* The list of all installed classifier types */
3537
static LIST_HEAD(tcf_proto_base);
3638

@@ -1211,7 +1213,7 @@ static int tc_new_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
12111213
replay:
12121214
tp_created = 0;
12131215

1214-
err = nlmsg_parse(n, sizeof(*t), tca, TCA_MAX, NULL, extack);
1216+
err = nlmsg_parse(n, sizeof(*t), tca, TCA_MAX, rtm_tca_policy, extack);
12151217
if (err < 0)
12161218
return err;
12171219

@@ -1360,7 +1362,7 @@ static int tc_del_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
13601362
if (!netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN))
13611363
return -EPERM;
13621364

1363-
err = nlmsg_parse(n, sizeof(*t), tca, TCA_MAX, NULL, extack);
1365+
err = nlmsg_parse(n, sizeof(*t), tca, TCA_MAX, rtm_tca_policy, extack);
13641366
if (err < 0)
13651367
return err;
13661368

@@ -1475,7 +1477,7 @@ static int tc_get_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
14751477
void *fh = NULL;
14761478
int err;
14771479

1478-
err = nlmsg_parse(n, sizeof(*t), tca, TCA_MAX, NULL, extack);
1480+
err = nlmsg_parse(n, sizeof(*t), tca, TCA_MAX, rtm_tca_policy, extack);
14791481
if (err < 0)
14801482
return err;
14811483

@@ -1838,7 +1840,7 @@ static int tc_ctl_chain(struct sk_buff *skb, struct nlmsghdr *n,
18381840
return -EPERM;
18391841

18401842
replay:
1841-
err = nlmsg_parse(n, sizeof(*t), tca, TCA_MAX, NULL, extack);
1843+
err = nlmsg_parse(n, sizeof(*t), tca, TCA_MAX, rtm_tca_policy, extack);
18421844
if (err < 0)
18431845
return err;
18441846

@@ -1949,7 +1951,8 @@ static int tc_dump_chain(struct sk_buff *skb, struct netlink_callback *cb)
19491951
if (nlmsg_len(cb->nlh) < sizeof(*tcm))
19501952
return skb->len;
19511953

1952-
err = nlmsg_parse(cb->nlh, sizeof(*tcm), tca, TCA_MAX, NULL, NULL);
1954+
err = nlmsg_parse(cb->nlh, sizeof(*tcm), tca, TCA_MAX, rtm_tca_policy,
1955+
NULL);
19531956
if (err)
19541957
return err;
19551958

net/sched/sch_api.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,10 +1307,6 @@ check_loop_fn(struct Qdisc *q, unsigned long cl, struct qdisc_walker *w)
13071307
return 0;
13081308
}
13091309

1310-
/*
1311-
* Delete/get qdisc.
1312-
*/
1313-
13141310
const struct nla_policy rtm_tca_policy[TCA_MAX + 1] = {
13151311
[TCA_KIND] = { .type = NLA_STRING },
13161312
[TCA_OPTIONS] = { .type = NLA_NESTED },
@@ -1323,6 +1319,10 @@ const struct nla_policy rtm_tca_policy[TCA_MAX + 1] = {
13231319
[TCA_EGRESS_BLOCK] = { .type = NLA_U32 },
13241320
};
13251321

1322+
/*
1323+
* Delete/get qdisc.
1324+
*/
1325+
13261326
static int tc_get_qdisc(struct sk_buff *skb, struct nlmsghdr *n,
13271327
struct netlink_ext_ack *extack)
13281328
{

0 commit comments

Comments
 (0)