Skip to content

Commit 5036034

Browse files
tammeladavem330
authored andcommitted
net/sched: act_pedit: use NLA_POLICY for parsing 'ex' keys
Transform two checks in the 'ex' key parsing into netlink policies removing extra if checks. Signed-off-by: Pedro Tammela <pctammela@mojatatu.com> Reviewed-by: Simon Horman <simon.horman@corigine.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 2f0f946 commit 5036034

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

net/sched/act_pedit.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ static const struct nla_policy pedit_policy[TCA_PEDIT_MAX + 1] = {
3030
};
3131

3232
static const struct nla_policy pedit_key_ex_policy[TCA_PEDIT_KEY_EX_MAX + 1] = {
33-
[TCA_PEDIT_KEY_EX_HTYPE] = { .type = NLA_U16 },
34-
[TCA_PEDIT_KEY_EX_CMD] = { .type = NLA_U16 },
33+
[TCA_PEDIT_KEY_EX_HTYPE] =
34+
NLA_POLICY_MAX(NLA_U16, TCA_PEDIT_HDR_TYPE_MAX),
35+
[TCA_PEDIT_KEY_EX_CMD] = NLA_POLICY_MAX(NLA_U16, TCA_PEDIT_CMD_MAX),
3536
};
3637

3738
static struct tcf_pedit_key_ex *tcf_pedit_keys_ex_parse(struct nlattr *nla,
@@ -81,12 +82,6 @@ static struct tcf_pedit_key_ex *tcf_pedit_keys_ex_parse(struct nlattr *nla,
8182
k->htype = nla_get_u16(tb[TCA_PEDIT_KEY_EX_HTYPE]);
8283
k->cmd = nla_get_u16(tb[TCA_PEDIT_KEY_EX_CMD]);
8384

84-
if (k->htype > TCA_PEDIT_HDR_TYPE_MAX ||
85-
k->cmd > TCA_PEDIT_CMD_MAX) {
86-
err = -EINVAL;
87-
goto err_out;
88-
}
89-
9085
k++;
9186
}
9287

0 commit comments

Comments
 (0)