diff options
author | David S. Miller <davem@davemloft.net> | 2012-04-01 20:39:02 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-04-02 04:33:43 -0400 |
commit | f3756b79e8f76cb92830383c215deba146fe0a26 (patch) | |
tree | 107c0e99681a0b26b2e750b3fc7a0b01ba1404aa /net | |
parent | e549a6b3a5acff66f0427091e44f814943a26a86 (diff) |
ipv4: Stop using NLA_PUT*().
These macros contain a hidden goto, and are thus extremely error
prone and make code hard to audit.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/ipv4/devinet.c | 20 | ||||
-rw-r--r-- | net/ipv4/fib_rules.c | 16 | ||||
-rw-r--r-- | net/ipv4/fib_semantics.c | 47 | ||||
-rw-r--r-- | net/ipv4/ip_gre.c | 23 | ||||
-rw-r--r-- | net/ipv4/ipmr.c | 9 | ||||
-rw-r--r-- | net/ipv4/route.c | 45 |
6 files changed, 87 insertions, 73 deletions
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index d4fad5c77447..3ffaad0ef98f 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c | |||
@@ -1267,17 +1267,15 @@ static int inet_fill_ifaddr(struct sk_buff *skb, struct in_ifaddr *ifa, | |||
1267 | ifm->ifa_scope = ifa->ifa_scope; | 1267 | ifm->ifa_scope = ifa->ifa_scope; |
1268 | ifm->ifa_index = ifa->ifa_dev->dev->ifindex; | 1268 | ifm->ifa_index = ifa->ifa_dev->dev->ifindex; |
1269 | 1269 | ||
1270 | if (ifa->ifa_address) | 1270 | if ((ifa->ifa_address && |
1271 | NLA_PUT_BE32(skb, IFA_ADDRESS, ifa->ifa_address); | 1271 | nla_put_be32(skb, IFA_ADDRESS, ifa->ifa_address)) || |
1272 | 1272 | (ifa->ifa_local && | |
1273 | if (ifa->ifa_local) | 1273 | nla_put_be32(skb, IFA_LOCAL, ifa->ifa_local)) || |
1274 | NLA_PUT_BE32(skb, IFA_LOCAL, ifa->ifa_local); | 1274 | (ifa->ifa_broadcast && |
1275 | 1275 | nla_put_be32(skb, IFA_BROADCAST, ifa->ifa_broadcast)) || | |
1276 | if (ifa->ifa_broadcast) | 1276 | (ifa->ifa_label[0] && |
1277 | NLA_PUT_BE32(skb, IFA_BROADCAST, ifa->ifa_broadcast); | 1277 | nla_put_string(skb, IFA_LABEL, ifa->ifa_label))) |
1278 | 1278 | goto nla_put_failure; | |
1279 | if (ifa->ifa_label[0]) | ||
1280 | NLA_PUT_STRING(skb, IFA_LABEL, ifa->ifa_label); | ||
1281 | 1279 | ||
1282 | return nlmsg_end(skb, nlh); | 1280 | return nlmsg_end(skb, nlh); |
1283 | 1281 | ||
diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c index 799fc790b3cf..2d043f71ef70 100644 --- a/net/ipv4/fib_rules.c +++ b/net/ipv4/fib_rules.c | |||
@@ -221,15 +221,15 @@ static int fib4_rule_fill(struct fib_rule *rule, struct sk_buff *skb, | |||
221 | frh->src_len = rule4->src_len; | 221 | frh->src_len = rule4->src_len; |
222 | frh->tos = rule4->tos; | 222 | frh->tos = rule4->tos; |
223 | 223 | ||
224 | if (rule4->dst_len) | 224 | if ((rule4->dst_len && |
225 | NLA_PUT_BE32(skb, FRA_DST, rule4->dst); | 225 | nla_put_be32(skb, FRA_DST, rule4->dst)) || |
226 | 226 | (rule4->src_len && | |
227 | if (rule4->src_len) | 227 | nla_put_be32(skb, FRA_SRC, rule4->src))) |
228 | NLA_PUT_BE32(skb, FRA_SRC, rule4->src); | 228 | goto nla_put_failure; |
229 | |||
230 | #ifdef CONFIG_IP_ROUTE_CLASSID | 229 | #ifdef CONFIG_IP_ROUTE_CLASSID |
231 | if (rule4->tclassid) | 230 | if (rule4->tclassid && |
232 | NLA_PUT_U32(skb, FRA_FLOW, rule4->tclassid); | 231 | nla_put_u32(skb, FRA_FLOW, rule4->tclassid)) |
232 | goto nla_put_failure; | ||
233 | #endif | 233 | #endif |
234 | return 0; | 234 | return 0; |
235 | 235 | ||
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index a8c5c1d6715b..63aa48acc98a 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c | |||
@@ -932,33 +932,36 @@ int fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event, | |||
932 | rtm->rtm_table = tb_id; | 932 | rtm->rtm_table = tb_id; |
933 | else | 933 | else |
934 | rtm->rtm_table = RT_TABLE_COMPAT; | 934 | rtm->rtm_table = RT_TABLE_COMPAT; |
935 | NLA_PUT_U32(skb, RTA_TABLE, tb_id); | 935 | if (nla_put_u32(skb, RTA_TABLE, tb_id)) |
936 | goto nla_put_failure; | ||
936 | rtm->rtm_type = type; | 937 | rtm->rtm_type = type; |
937 | rtm->rtm_flags = fi->fib_flags; | 938 | rtm->rtm_flags = fi->fib_flags; |
938 | rtm->rtm_scope = fi->fib_scope; | 939 | rtm->rtm_scope = fi->fib_scope; |
939 | rtm->rtm_protocol = fi->fib_protocol; | 940 | rtm->rtm_protocol = fi->fib_protocol; |
940 | 941 | ||
941 | if (rtm->rtm_dst_len) | 942 | if (rtm->rtm_dst_len && |
942 | NLA_PUT_BE32(skb, RTA_DST, dst); | 943 | nla_put_be32(skb, RTA_DST, dst)) |
943 | 944 | goto nla_put_failure; | |
944 | if (fi->fib_priority) | 945 | if (fi->fib_priority && |
945 | NLA_PUT_U32(skb, RTA_PRIORITY, fi->fib_priority); | 946 | nla_put_u32(skb, RTA_PRIORITY, fi->fib_priority)) |
946 | 947 | goto nla_put_failure; | |
947 | if (rtnetlink_put_metrics(skb, fi->fib_metrics) < 0) | 948 | if (rtnetlink_put_metrics(skb, fi->fib_metrics) < 0) |
948 | goto nla_put_failure; | 949 | goto nla_put_failure; |
949 | 950 | ||
950 | if (fi->fib_prefsrc) | 951 | if (fi->fib_prefsrc && |
951 | NLA_PUT_BE32(skb, RTA_PREFSRC, fi->fib_prefsrc); | 952 | nla_put_be32(skb, RTA_PREFSRC, fi->fib_prefsrc)) |
952 | 953 | goto nla_put_failure; | |
953 | if (fi->fib_nhs == 1) { | 954 | if (fi->fib_nhs == 1) { |
954 | if (fi->fib_nh->nh_gw) | 955 | if (fi->fib_nh->nh_gw && |
955 | NLA_PUT_BE32(skb, RTA_GATEWAY, fi->fib_nh->nh_gw); | 956 | nla_put_be32(skb, RTA_GATEWAY, fi->fib_nh->nh_gw)) |
956 | 957 | goto nla_put_failure; | |
957 | if (fi->fib_nh->nh_oif) | 958 | if (fi->fib_nh->nh_oif && |
958 | NLA_PUT_U32(skb, RTA_OIF, fi->fib_nh->nh_oif); | 959 | nla_put_u32(skb, RTA_OIF, fi->fib_nh->nh_oif)) |
960 | goto nla_put_failure; | ||
959 | #ifdef CONFIG_IP_ROUTE_CLASSID | 961 | #ifdef CONFIG_IP_ROUTE_CLASSID |
960 | if (fi->fib_nh[0].nh_tclassid) | 962 | if (fi->fib_nh[0].nh_tclassid && |
961 | NLA_PUT_U32(skb, RTA_FLOW, fi->fib_nh[0].nh_tclassid); | 963 | nla_put_u32(skb, RTA_FLOW, fi->fib_nh[0].nh_tclassid)) |
964 | goto nla_put_failure; | ||
962 | #endif | 965 | #endif |
963 | } | 966 | } |
964 | #ifdef CONFIG_IP_ROUTE_MULTIPATH | 967 | #ifdef CONFIG_IP_ROUTE_MULTIPATH |
@@ -979,11 +982,13 @@ int fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event, | |||
979 | rtnh->rtnh_hops = nh->nh_weight - 1; | 982 | rtnh->rtnh_hops = nh->nh_weight - 1; |
980 | rtnh->rtnh_ifindex = nh->nh_oif; | 983 | rtnh->rtnh_ifindex = nh->nh_oif; |
981 | 984 | ||
982 | if (nh->nh_gw) | 985 | if (nh->nh_gw && |
983 | NLA_PUT_BE32(skb, RTA_GATEWAY, nh->nh_gw); | 986 | nla_put_be32(skb, RTA_GATEWAY, nh->nh_gw)) |
987 | goto nla_put_failure; | ||
984 | #ifdef CONFIG_IP_ROUTE_CLASSID | 988 | #ifdef CONFIG_IP_ROUTE_CLASSID |
985 | if (nh->nh_tclassid) | 989 | if (nh->nh_tclassid && |
986 | NLA_PUT_U32(skb, RTA_FLOW, nh->nh_tclassid); | 990 | nla_put_u32(skb, RTA_FLOW, nh->nh_tclassid)) |
991 | goto nla_put_failure; | ||
987 | #endif | 992 | #endif |
988 | /* length of rtnetlink header + attributes */ | 993 | /* length of rtnetlink header + attributes */ |
989 | rtnh->rtnh_len = nlmsg_get_pos(skb) - (void *) rtnh; | 994 | rtnh->rtnh_len = nlmsg_get_pos(skb) - (void *) rtnh; |
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c index b57532d4742c..02d07c6f630f 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c | |||
@@ -1654,17 +1654,18 @@ static int ipgre_fill_info(struct sk_buff *skb, const struct net_device *dev) | |||
1654 | struct ip_tunnel *t = netdev_priv(dev); | 1654 | struct ip_tunnel *t = netdev_priv(dev); |
1655 | struct ip_tunnel_parm *p = &t->parms; | 1655 | struct ip_tunnel_parm *p = &t->parms; |
1656 | 1656 | ||
1657 | NLA_PUT_U32(skb, IFLA_GRE_LINK, p->link); | 1657 | if (nla_put_u32(skb, IFLA_GRE_LINK, p->link) || |
1658 | NLA_PUT_BE16(skb, IFLA_GRE_IFLAGS, p->i_flags); | 1658 | nla_put_be16(skb, IFLA_GRE_IFLAGS, p->i_flags) || |
1659 | NLA_PUT_BE16(skb, IFLA_GRE_OFLAGS, p->o_flags); | 1659 | nla_put_be16(skb, IFLA_GRE_OFLAGS, p->o_flags) || |
1660 | NLA_PUT_BE32(skb, IFLA_GRE_IKEY, p->i_key); | 1660 | nla_put_be32(skb, IFLA_GRE_IKEY, p->i_key) || |
1661 | NLA_PUT_BE32(skb, IFLA_GRE_OKEY, p->o_key); | 1661 | nla_put_be32(skb, IFLA_GRE_OKEY, p->o_key) || |
1662 | NLA_PUT_BE32(skb, IFLA_GRE_LOCAL, p->iph.saddr); | 1662 | nla_put_be32(skb, IFLA_GRE_LOCAL, p->iph.saddr) || |
1663 | NLA_PUT_BE32(skb, IFLA_GRE_REMOTE, p->iph.daddr); | 1663 | nla_put_be32(skb, IFLA_GRE_REMOTE, p->iph.daddr) || |
1664 | NLA_PUT_U8(skb, IFLA_GRE_TTL, p->iph.ttl); | 1664 | nla_put_u8(skb, IFLA_GRE_TTL, p->iph.ttl) || |
1665 | NLA_PUT_U8(skb, IFLA_GRE_TOS, p->iph.tos); | 1665 | nla_put_u8(skb, IFLA_GRE_TOS, p->iph.tos) || |
1666 | NLA_PUT_U8(skb, IFLA_GRE_PMTUDISC, !!(p->iph.frag_off & htons(IP_DF))); | 1666 | nla_put_u8(skb, IFLA_GRE_PMTUDISC, |
1667 | 1667 | !!(p->iph.frag_off & htons(IP_DF)))) | |
1668 | goto nla_put_failure; | ||
1668 | return 0; | 1669 | return 0; |
1669 | 1670 | ||
1670 | nla_put_failure: | 1671 | nla_put_failure: |
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 0518a4fb177b..dcf4d7fe3917 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c | |||
@@ -2120,15 +2120,16 @@ static int ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb, | |||
2120 | rtm->rtm_src_len = 32; | 2120 | rtm->rtm_src_len = 32; |
2121 | rtm->rtm_tos = 0; | 2121 | rtm->rtm_tos = 0; |
2122 | rtm->rtm_table = mrt->id; | 2122 | rtm->rtm_table = mrt->id; |
2123 | NLA_PUT_U32(skb, RTA_TABLE, mrt->id); | 2123 | if (nla_put_u32(skb, RTA_TABLE, mrt->id)) |
2124 | goto nla_put_failure; | ||
2124 | rtm->rtm_type = RTN_MULTICAST; | 2125 | rtm->rtm_type = RTN_MULTICAST; |
2125 | rtm->rtm_scope = RT_SCOPE_UNIVERSE; | 2126 | rtm->rtm_scope = RT_SCOPE_UNIVERSE; |
2126 | rtm->rtm_protocol = RTPROT_UNSPEC; | 2127 | rtm->rtm_protocol = RTPROT_UNSPEC; |
2127 | rtm->rtm_flags = 0; | 2128 | rtm->rtm_flags = 0; |
2128 | 2129 | ||
2129 | NLA_PUT_BE32(skb, RTA_SRC, c->mfc_origin); | 2130 | if (nla_put_be32(skb, RTA_SRC, c->mfc_origin) || |
2130 | NLA_PUT_BE32(skb, RTA_DST, c->mfc_mcastgrp); | 2131 | nla_put_be32(skb, RTA_DST, c->mfc_mcastgrp)) |
2131 | 2132 | goto nla_put_failure; | |
2132 | if (__ipmr_fill_mroute(mrt, skb, c, rtm) < 0) | 2133 | if (__ipmr_fill_mroute(mrt, skb, c, rtm) < 0) |
2133 | goto nla_put_failure; | 2134 | goto nla_put_failure; |
2134 | 2135 | ||
diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 3b110a46362c..e5647b4e51c6 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c | |||
@@ -2973,7 +2973,8 @@ static int rt_fill_info(struct net *net, | |||
2973 | r->rtm_src_len = 0; | 2973 | r->rtm_src_len = 0; |
2974 | r->rtm_tos = rt->rt_key_tos; | 2974 | r->rtm_tos = rt->rt_key_tos; |
2975 | r->rtm_table = RT_TABLE_MAIN; | 2975 | r->rtm_table = RT_TABLE_MAIN; |
2976 | NLA_PUT_U32(skb, RTA_TABLE, RT_TABLE_MAIN); | 2976 | if (nla_put_u32(skb, RTA_TABLE, RT_TABLE_MAIN)) |
2977 | goto nla_put_failure; | ||
2977 | r->rtm_type = rt->rt_type; | 2978 | r->rtm_type = rt->rt_type; |
2978 | r->rtm_scope = RT_SCOPE_UNIVERSE; | 2979 | r->rtm_scope = RT_SCOPE_UNIVERSE; |
2979 | r->rtm_protocol = RTPROT_UNSPEC; | 2980 | r->rtm_protocol = RTPROT_UNSPEC; |
@@ -2981,31 +2982,38 @@ static int rt_fill_info(struct net *net, | |||
2981 | if (rt->rt_flags & RTCF_NOTIFY) | 2982 | if (rt->rt_flags & RTCF_NOTIFY) |
2982 | r->rtm_flags |= RTM_F_NOTIFY; | 2983 | r->rtm_flags |= RTM_F_NOTIFY; |
2983 | 2984 | ||
2984 | NLA_PUT_BE32(skb, RTA_DST, rt->rt_dst); | 2985 | if (nla_put_be32(skb, RTA_DST, rt->rt_dst)) |
2985 | 2986 | goto nla_put_failure; | |
2986 | if (rt->rt_key_src) { | 2987 | if (rt->rt_key_src) { |
2987 | r->rtm_src_len = 32; | 2988 | r->rtm_src_len = 32; |
2988 | NLA_PUT_BE32(skb, RTA_SRC, rt->rt_key_src); | 2989 | if (nla_put_be32(skb, RTA_SRC, rt->rt_key_src)) |
2990 | goto nla_put_failure; | ||
2989 | } | 2991 | } |
2990 | if (rt->dst.dev) | 2992 | if (rt->dst.dev && |
2991 | NLA_PUT_U32(skb, RTA_OIF, rt->dst.dev->ifindex); | 2993 | nla_put_u32(skb, RTA_OIF, rt->dst.dev->ifindex)) |
2994 | goto nla_put_failure; | ||
2992 | #ifdef CONFIG_IP_ROUTE_CLASSID | 2995 | #ifdef CONFIG_IP_ROUTE_CLASSID |
2993 | if (rt->dst.tclassid) | 2996 | if (rt->dst.tclassid && |
2994 | NLA_PUT_U32(skb, RTA_FLOW, rt->dst.tclassid); | 2997 | nla_put_u32(skb, RTA_FLOW, rt->dst.tclassid)) |
2998 | goto nla_put_failure; | ||
2995 | #endif | 2999 | #endif |
2996 | if (rt_is_input_route(rt)) | 3000 | if (rt_is_input_route(rt)) { |
2997 | NLA_PUT_BE32(skb, RTA_PREFSRC, rt->rt_spec_dst); | 3001 | if (nla_put_be32(skb, RTA_PREFSRC, rt->rt_spec_dst)) |
2998 | else if (rt->rt_src != rt->rt_key_src) | 3002 | goto nla_put_failure; |
2999 | NLA_PUT_BE32(skb, RTA_PREFSRC, rt->rt_src); | 3003 | } else if (rt->rt_src != rt->rt_key_src) { |
3000 | 3004 | if (nla_put_be32(skb, RTA_PREFSRC, rt->rt_src)) | |
3001 | if (rt->rt_dst != rt->rt_gateway) | 3005 | goto nla_put_failure; |
3002 | NLA_PUT_BE32(skb, RTA_GATEWAY, rt->rt_gateway); | 3006 | } |
3007 | if (rt->rt_dst != rt->rt_gateway && | ||
3008 | nla_put_be32(skb, RTA_GATEWAY, rt->rt_gateway)) | ||
3009 | goto nla_put_failure; | ||
3003 | 3010 | ||
3004 | if (rtnetlink_put_metrics(skb, dst_metrics_ptr(&rt->dst)) < 0) | 3011 | if (rtnetlink_put_metrics(skb, dst_metrics_ptr(&rt->dst)) < 0) |
3005 | goto nla_put_failure; | 3012 | goto nla_put_failure; |
3006 | 3013 | ||
3007 | if (rt->rt_mark) | 3014 | if (rt->rt_mark && |
3008 | NLA_PUT_BE32(skb, RTA_MARK, rt->rt_mark); | 3015 | nla_put_be32(skb, RTA_MARK, rt->rt_mark)) |
3016 | goto nla_put_failure; | ||
3009 | 3017 | ||
3010 | error = rt->dst.error; | 3018 | error = rt->dst.error; |
3011 | if (peer) { | 3019 | if (peer) { |
@@ -3046,7 +3054,8 @@ static int rt_fill_info(struct net *net, | |||
3046 | } | 3054 | } |
3047 | } else | 3055 | } else |
3048 | #endif | 3056 | #endif |
3049 | NLA_PUT_U32(skb, RTA_IIF, rt->rt_iif); | 3057 | if (nla_put_u32(skb, RTA_IIF, rt->rt_iif)) |
3058 | goto nla_put_failure; | ||
3050 | } | 3059 | } |
3051 | 3060 | ||
3052 | if (rtnl_put_cacheinfo(skb, &rt->dst, id, ts, tsage, | 3061 | if (rtnl_put_cacheinfo(skb, &rt->dst, id, ts, tsage, |