Skip to content

Commit 199ce85

Browse files
congwangJakub Kicinski
authored andcommitted
net_sched: add policy validation for action attributes
Similar to commit 8b4c3cd ("net: sched: Add policy validation for tc attributes"), we need to add proper policy validation for TC action attributes too. Cc: David Ahern <[email protected]> Cc: Jamal Hadi Salim <[email protected]> Signed-off-by: Cong Wang <[email protected]> Acked-by: Jiri Pirko <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 62794fc commit 199ce85

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

net/sched/act_api.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,15 @@ static struct tc_cookie *nla_memdup_cookie(struct nlattr **tb)
831831
return c;
832832
}
833833

834+
static const struct nla_policy tcf_action_policy[TCA_ACT_MAX + 1] = {
835+
[TCA_ACT_KIND] = { .type = NLA_NUL_STRING,
836+
.len = IFNAMSIZ - 1 },
837+
[TCA_ACT_INDEX] = { .type = NLA_U32 },
838+
[TCA_ACT_COOKIE] = { .type = NLA_BINARY,
839+
.len = TC_COOKIE_MAX_SIZE },
840+
[TCA_ACT_OPTIONS] = { .type = NLA_NESTED },
841+
};
842+
834843
struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
835844
struct nlattr *nla, struct nlattr *est,
836845
char *name, int ovr, int bind,
@@ -846,8 +855,8 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
846855
int err;
847856

848857
if (name == NULL) {
849-
err = nla_parse_nested_deprecated(tb, TCA_ACT_MAX, nla, NULL,
850-
extack);
858+
err = nla_parse_nested_deprecated(tb, TCA_ACT_MAX, nla,
859+
tcf_action_policy, extack);
851860
if (err < 0)
852861
goto err_out;
853862
err = -EINVAL;
@@ -856,18 +865,9 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
856865
NL_SET_ERR_MSG(extack, "TC action kind must be specified");
857866
goto err_out;
858867
}
859-
if (nla_strlcpy(act_name, kind, IFNAMSIZ) >= IFNAMSIZ) {
860-
NL_SET_ERR_MSG(extack, "TC action name too long");
861-
goto err_out;
862-
}
863-
if (tb[TCA_ACT_COOKIE]) {
864-
int cklen = nla_len(tb[TCA_ACT_COOKIE]);
865-
866-
if (cklen > TC_COOKIE_MAX_SIZE) {
867-
NL_SET_ERR_MSG(extack, "TC cookie size above the maximum");
868-
goto err_out;
869-
}
868+
nla_strlcpy(act_name, kind, IFNAMSIZ);
870869

870+
if (tb[TCA_ACT_COOKIE]) {
871871
cookie = nla_memdup_cookie(tb);
872872
if (!cookie) {
873873
NL_SET_ERR_MSG(extack, "No memory to generate TC cookie");
@@ -1098,7 +1098,8 @@ static struct tc_action *tcf_action_get_1(struct net *net, struct nlattr *nla,
10981098
int index;
10991099
int err;
11001100

1101-
err = nla_parse_nested_deprecated(tb, TCA_ACT_MAX, nla, NULL, extack);
1101+
err = nla_parse_nested_deprecated(tb, TCA_ACT_MAX, nla,
1102+
tcf_action_policy, extack);
11021103
if (err < 0)
11031104
goto err_out;
11041105

@@ -1152,7 +1153,8 @@ static int tca_action_flush(struct net *net, struct nlattr *nla,
11521153

11531154
b = skb_tail_pointer(skb);
11541155

1155-
err = nla_parse_nested_deprecated(tb, TCA_ACT_MAX, nla, NULL, extack);
1156+
err = nla_parse_nested_deprecated(tb, TCA_ACT_MAX, nla,
1157+
tcf_action_policy, extack);
11561158
if (err < 0)
11571159
goto err_out;
11581160

@@ -1440,7 +1442,7 @@ static struct nlattr *find_dump_kind(struct nlattr **nla)
14401442

14411443
if (tb[1] == NULL)
14421444
return NULL;
1443-
if (nla_parse_nested_deprecated(tb2, TCA_ACT_MAX, tb[1], NULL, NULL) < 0)
1445+
if (nla_parse_nested_deprecated(tb2, TCA_ACT_MAX, tb[1], tcf_action_policy, NULL) < 0)
14441446
return NULL;
14451447
kind = tb2[TCA_ACT_KIND];
14461448

0 commit comments

Comments
 (0)