Skip to content

Commit 8b4c3cd

Browse files
dsaherndavem330
authored andcommitted
net: sched: Add policy validation for tc attributes
A number of TC attributes are processed without proper validation (e.g., length checks). Add a tca policy for all input attributes and use when invoking nlmsg_parse. The 2 Fixes tags below cover the latest additions. The other attributes are a string (KIND), nested attribute (OPTIONS which does seem to have validation in most cases), for dumps only or a flag. Fixes: 5bc1701 ("net: sched: introduce multichain support for filters") Fixes: d47a6b0 ("net: sched: introduce ingress/egress block index attributes for qdisc") Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent bd961c9 commit 8b4c3cd

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

net/sched/sch_api.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,18 @@ check_loop_fn(struct Qdisc *q, unsigned long cl, struct qdisc_walker *w)
13111311
* Delete/get qdisc.
13121312
*/
13131313

1314+
const struct nla_policy rtm_tca_policy[TCA_MAX + 1] = {
1315+
[TCA_KIND] = { .type = NLA_STRING },
1316+
[TCA_OPTIONS] = { .type = NLA_NESTED },
1317+
[TCA_RATE] = { .type = NLA_BINARY,
1318+
.len = sizeof(struct tc_estimator) },
1319+
[TCA_STAB] = { .type = NLA_NESTED },
1320+
[TCA_DUMP_INVISIBLE] = { .type = NLA_FLAG },
1321+
[TCA_CHAIN] = { .type = NLA_U32 },
1322+
[TCA_INGRESS_BLOCK] = { .type = NLA_U32 },
1323+
[TCA_EGRESS_BLOCK] = { .type = NLA_U32 },
1324+
};
1325+
13141326
static int tc_get_qdisc(struct sk_buff *skb, struct nlmsghdr *n,
13151327
struct netlink_ext_ack *extack)
13161328
{
@@ -1327,7 +1339,8 @@ static int tc_get_qdisc(struct sk_buff *skb, struct nlmsghdr *n,
13271339
!netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN))
13281340
return -EPERM;
13291341

1330-
err = nlmsg_parse(n, sizeof(*tcm), tca, TCA_MAX, NULL, extack);
1342+
err = nlmsg_parse(n, sizeof(*tcm), tca, TCA_MAX, rtm_tca_policy,
1343+
extack);
13311344
if (err < 0)
13321345
return err;
13331346

@@ -1411,7 +1424,8 @@ static int tc_modify_qdisc(struct sk_buff *skb, struct nlmsghdr *n,
14111424

14121425
replay:
14131426
/* Reinit, just in case something touches this. */
1414-
err = nlmsg_parse(n, sizeof(*tcm), tca, TCA_MAX, NULL, extack);
1427+
err = nlmsg_parse(n, sizeof(*tcm), tca, TCA_MAX, rtm_tca_policy,
1428+
extack);
14151429
if (err < 0)
14161430
return err;
14171431

@@ -1645,7 +1659,8 @@ static int tc_dump_qdisc(struct sk_buff *skb, struct netlink_callback *cb)
16451659
idx = 0;
16461660
ASSERT_RTNL();
16471661

1648-
err = nlmsg_parse(nlh, sizeof(struct tcmsg), tca, TCA_MAX, NULL, NULL);
1662+
err = nlmsg_parse(nlh, sizeof(struct tcmsg), tca, TCA_MAX,
1663+
rtm_tca_policy, NULL);
16491664
if (err < 0)
16501665
return err;
16511666

@@ -1864,7 +1879,8 @@ static int tc_ctl_tclass(struct sk_buff *skb, struct nlmsghdr *n,
18641879
!netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN))
18651880
return -EPERM;
18661881

1867-
err = nlmsg_parse(n, sizeof(*tcm), tca, TCA_MAX, NULL, extack);
1882+
err = nlmsg_parse(n, sizeof(*tcm), tca, TCA_MAX, rtm_tca_policy,
1883+
extack);
18681884
if (err < 0)
18691885
return err;
18701886

0 commit comments

Comments
 (0)