]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
net/sched: act_pedit: use NLA_POLICY for parsing 'ex' keys
authorPedro Tammela <pctammela@mojatatu.com>
Fri, 21 Apr 2023 21:25:13 +0000 (18:25 -0300)
committerDavid S. Miller <davem@davemloft.net>
Sun, 23 Apr 2023 17:35:26 +0000 (18:35 +0100)
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>
net/sched/act_pedit.c

index 4559a1507ea5a6a5a36d899fe404f4f85b1a9549..45201f75e8964feae070fc002a562962662403f9 100644 (file)
@@ -30,8 +30,9 @@ static const struct nla_policy pedit_policy[TCA_PEDIT_MAX + 1] = {
 };
 
 static const struct nla_policy pedit_key_ex_policy[TCA_PEDIT_KEY_EX_MAX + 1] = {
-       [TCA_PEDIT_KEY_EX_HTYPE]  = { .type = NLA_U16 },
-       [TCA_PEDIT_KEY_EX_CMD]    = { .type = NLA_U16 },
+       [TCA_PEDIT_KEY_EX_HTYPE] =
+               NLA_POLICY_MAX(NLA_U16, TCA_PEDIT_HDR_TYPE_MAX),
+       [TCA_PEDIT_KEY_EX_CMD] = NLA_POLICY_MAX(NLA_U16, TCA_PEDIT_CMD_MAX),
 };
 
 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,
                k->htype = nla_get_u16(tb[TCA_PEDIT_KEY_EX_HTYPE]);
                k->cmd = nla_get_u16(tb[TCA_PEDIT_KEY_EX_CMD]);
 
-               if (k->htype > TCA_PEDIT_HDR_TYPE_MAX ||
-                   k->cmd > TCA_PEDIT_CMD_MAX) {
-                       err = -EINVAL;
-                       goto err_out;
-               }
-
                k++;
        }