]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
net_sched: add policy validation for action attributes
authorCong Wang <xiyou.wangcong@gmail.com>
Thu, 19 Sep 2019 01:44:43 +0000 (18:44 -0700)
committerKhalid Elmously <khalid.elmously@canonical.com>
Fri, 18 Oct 2019 08:25:43 +0000 (04:25 -0400)
BugLink: https://bugs.launchpad.net/bugs/1848046
[ Upstream commit 199ce850ce112315cfc68d42b694bcaa27b097b7 ]

Similar to commit 8b4c3cdd9dd8
("net: sched: Add policy validation for tc attributes"), we need
to add proper policy validation for TC action attributes too.

Cc: David Ahern <dsahern@gmail.com>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
net/sched/act_api.c

index 3397122961642f8dacc5f95a2c9e3dd4d6feddf0..2558f00f6b3eda64a87f63c32592c15b7a0a2bfe 100644 (file)
@@ -831,6 +831,15 @@ static struct tc_cookie *nla_memdup_cookie(struct nlattr **tb)
        return c;
 }
 
+static const struct nla_policy tcf_action_policy[TCA_ACT_MAX + 1] = {
+       [TCA_ACT_KIND]          = { .type = NLA_NUL_STRING,
+                                   .len = IFNAMSIZ - 1 },
+       [TCA_ACT_INDEX]         = { .type = NLA_U32 },
+       [TCA_ACT_COOKIE]        = { .type = NLA_BINARY,
+                                   .len = TC_COOKIE_MAX_SIZE },
+       [TCA_ACT_OPTIONS]       = { .type = NLA_NESTED },
+};
+
 struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
                                    struct nlattr *nla, struct nlattr *est,
                                    char *name, int ovr, int bind,
@@ -846,8 +855,8 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
        int err;
 
        if (name == NULL) {
-               err = nla_parse_nested_deprecated(tb, TCA_ACT_MAX, nla, NULL,
-                                                 extack);
+               err = nla_parse_nested_deprecated(tb, TCA_ACT_MAX, nla,
+                                                 tcf_action_policy, extack);
                if (err < 0)
                        goto err_out;
                err = -EINVAL;
@@ -856,18 +865,9 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
                        NL_SET_ERR_MSG(extack, "TC action kind must be specified");
                        goto err_out;
                }
-               if (nla_strlcpy(act_name, kind, IFNAMSIZ) >= IFNAMSIZ) {
-                       NL_SET_ERR_MSG(extack, "TC action name too long");
-                       goto err_out;
-               }
-               if (tb[TCA_ACT_COOKIE]) {
-                       int cklen = nla_len(tb[TCA_ACT_COOKIE]);
-
-                       if (cklen > TC_COOKIE_MAX_SIZE) {
-                               NL_SET_ERR_MSG(extack, "TC cookie size above the maximum");
-                               goto err_out;
-                       }
+               nla_strlcpy(act_name, kind, IFNAMSIZ);
 
+               if (tb[TCA_ACT_COOKIE]) {
                        cookie = nla_memdup_cookie(tb);
                        if (!cookie) {
                                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,
        int index;
        int err;
 
-       err = nla_parse_nested_deprecated(tb, TCA_ACT_MAX, nla, NULL, extack);
+       err = nla_parse_nested_deprecated(tb, TCA_ACT_MAX, nla,
+                                         tcf_action_policy, extack);
        if (err < 0)
                goto err_out;
 
@@ -1152,7 +1153,8 @@ static int tca_action_flush(struct net *net, struct nlattr *nla,
 
        b = skb_tail_pointer(skb);
 
-       err = nla_parse_nested_deprecated(tb, TCA_ACT_MAX, nla, NULL, extack);
+       err = nla_parse_nested_deprecated(tb, TCA_ACT_MAX, nla,
+                                         tcf_action_policy, extack);
        if (err < 0)
                goto err_out;
 
@@ -1440,7 +1442,7 @@ static struct nlattr *find_dump_kind(struct nlattr **nla)
 
        if (tb[1] == NULL)
                return NULL;
-       if (nla_parse_nested_deprecated(tb2, TCA_ACT_MAX, tb[1], NULL, NULL) < 0)
+       if (nla_parse_nested_deprecated(tb2, TCA_ACT_MAX, tb[1], tcf_action_policy, NULL) < 0)
                return NULL;
        kind = tb2[TCA_ACT_KIND];