]> err.no Git - linux-2.6/commitdiff
[NETLINK]: Make use of NLA_STRING/NLA_NUL_STRING attribute validation
authorThomas Graf <tgraf@suug.ch>
Sun, 27 Aug 2006 03:13:18 +0000 (20:13 -0700)
committerDavid S. Miller <davem@sunset.davemloft.net>
Fri, 22 Sep 2006 22:18:25 +0000 (15:18 -0700)
Converts existing NLA_STRING attributes to use the new
validation features, saving a couple of temporary buffers.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/fib_rules.c
net/core/rtnetlink.c
net/decnet/dn_rules.c
net/ipv4/devinet.c
net/ipv4/fib_frontend.c
net/ipv4/fib_rules.c
net/ipv6/fib6_rules.c
net/ipv6/route.c
net/netlink/genetlink.c

index 7b2e9bb1a605d2e395657230b7415e21ed2a6b1a..a99d87d82b7f1cd63a8667649650857f960db678 100644 (file)
@@ -161,9 +161,6 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
        if (err < 0)
                goto errout;
 
-       if (tb[FRA_IFNAME] && nla_len(tb[FRA_IFNAME]) > IFNAMSIZ)
-               goto errout;
-
        rule = kzalloc(ops->rule_size, GFP_KERNEL);
        if (rule == NULL) {
                err = -ENOMEM;
@@ -177,10 +174,7 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
                struct net_device *dev;
 
                rule->ifindex = -1;
-               if (nla_strlcpy(rule->ifname, tb[FRA_IFNAME],
-                               IFNAMSIZ) >= IFNAMSIZ)
-                       goto errout_free;
-
+               nla_strlcpy(rule->ifname, tb[FRA_IFNAME], IFNAMSIZ);
                dev = __dev_get_by_name(rule->ifname);
                if (dev)
                        rule->ifindex = dev->ifindex;
index 8f225499e32e12cb654b2904245877d12adbc9a2..0ebcf8488e994b225a6660a546a1f23e1119e66d 100644 (file)
@@ -371,8 +371,8 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
 }
 
 static struct nla_policy ifla_policy[IFLA_MAX+1] __read_mostly = {
-       [IFLA_IFNAME]           = { .type = NLA_STRING },
-       [IFLA_MAP]              = { .minlen = sizeof(struct rtnl_link_ifmap) },
+       [IFLA_IFNAME]           = { .type = NLA_STRING, .len = IFNAMSIZ-1 },
+       [IFLA_MAP]              = { .len = sizeof(struct rtnl_link_ifmap) },
        [IFLA_MTU]              = { .type = NLA_U32 },
        [IFLA_TXQLEN]           = { .type = NLA_U32 },
        [IFLA_WEIGHT]           = { .type = NLA_U32 },
@@ -392,9 +392,8 @@ static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
        if (err < 0)
                goto errout;
 
-       if (tb[IFLA_IFNAME] &&
-           nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ) >= IFNAMSIZ)
-               return -EINVAL;
+       if (tb[IFLA_IFNAME])
+               nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
 
        err = -EINVAL;
        ifm = nlmsg_data(nlh);
index 63ad63dfd252ceff5dbb1eebdcff9585ce3264e9..3e0c882c90bfa28a662540e21c97c333a17d4bc6 100644 (file)
@@ -112,7 +112,7 @@ errout:
 }
 
 static struct nla_policy dn_fib_rule_policy[FRA_MAX+1] __read_mostly = {
-       [FRA_IFNAME]    = { .type = NLA_STRING },
+       [FRA_IFNAME]    = { .type = NLA_STRING, .len = IFNAMSIZ - 1 },
        [FRA_PRIORITY]  = { .type = NLA_U32 },
        [FRA_SRC]       = { .type = NLA_U16 },
        [FRA_DST]       = { .type = NLA_U16 },
index 0487677729cf126cf95f1264b823f7edfd80365b..8e8d1f17d77a7c29009fbcbc760a290259d5afc2 100644 (file)
@@ -85,7 +85,7 @@ static struct nla_policy ifa_ipv4_policy[IFA_MAX+1] __read_mostly = {
        [IFA_ADDRESS]           = { .type = NLA_U32 },
        [IFA_BROADCAST]         = { .type = NLA_U32 },
        [IFA_ANYCAST]           = { .type = NLA_U32 },
-       [IFA_LABEL]             = { .type = NLA_STRING },
+       [IFA_LABEL]             = { .type = NLA_STRING, .len = IFNAMSIZ - 1 },
 };
 
 static void rtmsg_ifa(int event, struct in_ifaddr *, struct nlmsghdr *, u32);
index d0abeab16e6635b9e5f80c47d5a994460ad46cb2..cfb527c060e48e4235063591a349ae91e7bb263a 100644 (file)
@@ -462,7 +462,7 @@ struct nla_policy rtm_ipv4_policy[RTA_MAX+1] __read_mostly = {
        [RTA_PRIORITY]          = { .type = NLA_U32 },
        [RTA_PREFSRC]           = { .type = NLA_U32 },
        [RTA_METRICS]           = { .type = NLA_NESTED },
-       [RTA_MULTIPATH]         = { .minlen = sizeof(struct rtnexthop) },
+       [RTA_MULTIPATH]         = { .len = sizeof(struct rtnexthop) },
        [RTA_PROTOINFO]         = { .type = NLA_U32 },
        [RTA_FLOW]              = { .type = NLA_U32 },
        [RTA_MP_ALGO]           = { .type = NLA_U32 },
index 280f424ca9c9c414c7db971b99d9af1af1fc12c1..52b2adae4f2230ae2af02f7a51efab6ab9516615 100644 (file)
@@ -179,7 +179,7 @@ static struct fib_table *fib_empty_table(void)
 }
 
 static struct nla_policy fib4_rule_policy[FRA_MAX+1] __read_mostly = {
-       [FRA_IFNAME]    = { .type = NLA_STRING },
+       [FRA_IFNAME]    = { .type = NLA_STRING, .len = IFNAMSIZ - 1 },
        [FRA_PRIORITY]  = { .type = NLA_U32 },
        [FRA_SRC]       = { .type = NLA_U32 },
        [FRA_DST]       = { .type = NLA_U32 },
index 2fbc71d90187470fddeeb1fdcf864d85eb574d24..34f5bfaddfc293f20e890be4c9acc4db193a4fe9 100644 (file)
@@ -137,10 +137,10 @@ static int fib6_rule_match(struct fib_rule *rule, struct flowi *fl, int flags)
 }
 
 static struct nla_policy fib6_rule_policy[FRA_MAX+1] __read_mostly = {
-       [FRA_IFNAME]    = { .type = NLA_STRING },
+       [FRA_IFNAME]    = { .type = NLA_STRING, .len = IFNAMSIZ - 1 },
        [FRA_PRIORITY]  = { .type = NLA_U32 },
-       [FRA_SRC]       = { .minlen = sizeof(struct in6_addr) },
-       [FRA_DST]       = { .minlen = sizeof(struct in6_addr) },
+       [FRA_SRC]       = { .len = sizeof(struct in6_addr) },
+       [FRA_DST]       = { .len = sizeof(struct in6_addr) },
        [FRA_FWMARK]    = { .type = NLA_U32 },
        [FRA_FWMASK]    = { .type = NLA_U32 },
        [FRA_TABLE]     = { .type = NLA_U32 },
index ba1b3d11865e43c2553d352179625e9e4b4fad37..75f4bb9611cec4cd08727d011870e588dcc994d2 100644 (file)
@@ -1865,7 +1865,7 @@ void rt6_mtu_change(struct net_device *dev, unsigned mtu)
 }
 
 static struct nla_policy rtm_ipv6_policy[RTA_MAX+1] __read_mostly = {
-       [RTA_GATEWAY]           = { .minlen = sizeof(struct in6_addr) },
+       [RTA_GATEWAY]           = { .len = sizeof(struct in6_addr) },
        [RTA_OIF]               = { .type = NLA_U32 },
        [RTA_IIF]               = { .type = NLA_U32 },
        [RTA_PRIORITY]          = { .type = NLA_U32 },
index d32599116c567c429d040ce8dbb53ac3371545cf..3ac942cdb677e5c7202105acf07f037c0adc887e 100644 (file)
@@ -455,7 +455,8 @@ static struct sk_buff *ctrl_build_msg(struct genl_family *family, u32 pid,
 
 static struct nla_policy ctrl_policy[CTRL_ATTR_MAX+1] __read_mostly = {
        [CTRL_ATTR_FAMILY_ID]   = { .type = NLA_U16 },
-       [CTRL_ATTR_FAMILY_NAME] = { .type = NLA_STRING },
+       [CTRL_ATTR_FAMILY_NAME] = { .type = NLA_NUL_STRING,
+                                   .len = GENL_NAMSIZ - 1 },
 };
 
 static int ctrl_getfamily(struct sk_buff *skb, struct genl_info *info)
@@ -470,12 +471,9 @@ static int ctrl_getfamily(struct sk_buff *skb, struct genl_info *info)
        }
 
        if (info->attrs[CTRL_ATTR_FAMILY_NAME]) {
-               char name[GENL_NAMSIZ];
-
-               if (nla_strlcpy(name, info->attrs[CTRL_ATTR_FAMILY_NAME],
-                               GENL_NAMSIZ) >= GENL_NAMSIZ)
-                       goto errout;
+               char *name;
 
+               name = nla_data(info->attrs[CTRL_ATTR_FAMILY_NAME]);
                res = genl_family_find_byname(name);
        }