aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2012-04-01 20:06:28 -0400
committerDavid S. Miller <davem@davemloft.net>2012-04-02 04:33:42 -0400
commit9a6308d74edb791c05d0e292e6263efc69640942 (patch)
tree34b27ca32b37fa5f25f508d4e1938d125b73ad80
parent1eb4c977778b5ab8e8fba9022687f0a5941d681a (diff)
neighbour: 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>
-rw-r--r--net/core/neighbour.c75
1 files changed, 40 insertions, 35 deletions
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 0a68045782d1..ac71765d6fd0 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -1768,29 +1768,29 @@ static int neightbl_fill_parms(struct sk_buff *skb, struct neigh_parms *parms)
1768 if (nest == NULL) 1768 if (nest == NULL)
1769 return -ENOBUFS; 1769 return -ENOBUFS;
1770 1770
1771 if (parms->dev) 1771 if ((parms->dev &&
1772 NLA_PUT_U32(skb, NDTPA_IFINDEX, parms->dev->ifindex); 1772 nla_put_u32(skb, NDTPA_IFINDEX, parms->dev->ifindex)) ||
1773 1773 nla_put_u32(skb, NDTPA_REFCNT, atomic_read(&parms->refcnt)) ||
1774 NLA_PUT_U32(skb, NDTPA_REFCNT, atomic_read(&parms->refcnt)); 1774 nla_put_u32(skb, NDTPA_QUEUE_LENBYTES, parms->queue_len_bytes) ||
1775 NLA_PUT_U32(skb, NDTPA_QUEUE_LENBYTES, parms->queue_len_bytes); 1775 /* approximative value for deprecated QUEUE_LEN (in packets) */
1776 /* approximative value for deprecated QUEUE_LEN (in packets) */ 1776 nla_put_u32(skb, NDTPA_QUEUE_LEN,
1777 NLA_PUT_U32(skb, NDTPA_QUEUE_LEN, 1777 DIV_ROUND_UP(parms->queue_len_bytes,
1778 DIV_ROUND_UP(parms->queue_len_bytes, 1778 SKB_TRUESIZE(ETH_FRAME_LEN))) ||
1779 SKB_TRUESIZE(ETH_FRAME_LEN))); 1779 nla_put_u32(skb, NDTPA_PROXY_QLEN, parms->proxy_qlen) ||
1780 NLA_PUT_U32(skb, NDTPA_PROXY_QLEN, parms->proxy_qlen); 1780 nla_put_u32(skb, NDTPA_APP_PROBES, parms->app_probes) ||
1781 NLA_PUT_U32(skb, NDTPA_APP_PROBES, parms->app_probes); 1781 nla_put_u32(skb, NDTPA_UCAST_PROBES, parms->ucast_probes) ||
1782 NLA_PUT_U32(skb, NDTPA_UCAST_PROBES, parms->ucast_probes); 1782 nla_put_u32(skb, NDTPA_MCAST_PROBES, parms->mcast_probes) ||
1783 NLA_PUT_U32(skb, NDTPA_MCAST_PROBES, parms->mcast_probes); 1783 nla_put_msecs(skb, NDTPA_REACHABLE_TIME, parms->reachable_time) ||
1784 NLA_PUT_MSECS(skb, NDTPA_REACHABLE_TIME, parms->reachable_time); 1784 nla_put_msecs(skb, NDTPA_BASE_REACHABLE_TIME,
1785 NLA_PUT_MSECS(skb, NDTPA_BASE_REACHABLE_TIME, 1785 parms->base_reachable_time) ||
1786 parms->base_reachable_time); 1786 nla_put_msecs(skb, NDTPA_GC_STALETIME, parms->gc_staletime) ||
1787 NLA_PUT_MSECS(skb, NDTPA_GC_STALETIME, parms->gc_staletime); 1787 nla_put_msecs(skb, NDTPA_DELAY_PROBE_TIME,
1788 NLA_PUT_MSECS(skb, NDTPA_DELAY_PROBE_TIME, parms->delay_probe_time); 1788 parms->delay_probe_time) ||
1789 NLA_PUT_MSECS(skb, NDTPA_RETRANS_TIME, parms->retrans_time); 1789 nla_put_msecs(skb, NDTPA_RETRANS_TIME, parms->retrans_time) ||
1790 NLA_PUT_MSECS(skb, NDTPA_ANYCAST_DELAY, parms->anycast_delay); 1790 nla_put_msecs(skb, NDTPA_ANYCAST_DELAY, parms->anycast_delay) ||
1791 NLA_PUT_MSECS(skb, NDTPA_PROXY_DELAY, parms->proxy_delay); 1791 nla_put_msecs(skb, NDTPA_PROXY_DELAY, parms->proxy_delay) ||
1792 NLA_PUT_MSECS(skb, NDTPA_LOCKTIME, parms->locktime); 1792 nla_put_msecs(skb, NDTPA_LOCKTIME, parms->locktime))
1793 1793 goto nla_put_failure;
1794 return nla_nest_end(skb, nest); 1794 return nla_nest_end(skb, nest);
1795 1795
1796nla_put_failure: 1796nla_put_failure:
@@ -1815,12 +1815,12 @@ static int neightbl_fill_info(struct sk_buff *skb, struct neigh_table *tbl,
1815 ndtmsg->ndtm_pad1 = 0; 1815 ndtmsg->ndtm_pad1 = 0;
1816 ndtmsg->ndtm_pad2 = 0; 1816 ndtmsg->ndtm_pad2 = 0;
1817 1817
1818 NLA_PUT_STRING(skb, NDTA_NAME, tbl->id); 1818 if (nla_put_string(skb, NDTA_NAME, tbl->id) ||
1819 NLA_PUT_MSECS(skb, NDTA_GC_INTERVAL, tbl->gc_interval); 1819 nla_put_msecs(skb, NDTA_GC_INTERVAL, tbl->gc_interval) ||
1820 NLA_PUT_U32(skb, NDTA_THRESH1, tbl->gc_thresh1); 1820 nla_put_u32(skb, NDTA_THRESH1, tbl->gc_thresh1) ||
1821 NLA_PUT_U32(skb, NDTA_THRESH2, tbl->gc_thresh2); 1821 nla_put_u32(skb, NDTA_THRESH2, tbl->gc_thresh2) ||
1822 NLA_PUT_U32(skb, NDTA_THRESH3, tbl->gc_thresh3); 1822 nla_put_u32(skb, NDTA_THRESH3, tbl->gc_thresh3))
1823 1823 goto nla_put_failure;
1824 { 1824 {
1825 unsigned long now = jiffies; 1825 unsigned long now = jiffies;
1826 unsigned int flush_delta = now - tbl->last_flush; 1826 unsigned int flush_delta = now - tbl->last_flush;
@@ -1841,7 +1841,8 @@ static int neightbl_fill_info(struct sk_buff *skb, struct neigh_table *tbl,
1841 ndc.ndtc_hash_mask = ((1 << nht->hash_shift) - 1); 1841 ndc.ndtc_hash_mask = ((1 << nht->hash_shift) - 1);
1842 rcu_read_unlock_bh(); 1842 rcu_read_unlock_bh();
1843 1843
1844 NLA_PUT(skb, NDTA_CONFIG, sizeof(ndc), &ndc); 1844 if (nla_put(skb, NDTA_CONFIG, sizeof(ndc), &ndc))
1845 goto nla_put_failure;
1845 } 1846 }
1846 1847
1847 { 1848 {
@@ -1866,7 +1867,8 @@ static int neightbl_fill_info(struct sk_buff *skb, struct neigh_table *tbl,
1866 ndst.ndts_forced_gc_runs += st->forced_gc_runs; 1867 ndst.ndts_forced_gc_runs += st->forced_gc_runs;
1867 } 1868 }
1868 1869
1869 NLA_PUT(skb, NDTA_STATS, sizeof(ndst), &ndst); 1870 if (nla_put(skb, NDTA_STATS, sizeof(ndst), &ndst))
1871 goto nla_put_failure;
1870 } 1872 }
1871 1873
1872 BUG_ON(tbl->parms.dev); 1874 BUG_ON(tbl->parms.dev);
@@ -2137,7 +2139,8 @@ static int neigh_fill_info(struct sk_buff *skb, struct neighbour *neigh,
2137 ndm->ndm_type = neigh->type; 2139 ndm->ndm_type = neigh->type;
2138 ndm->ndm_ifindex = neigh->dev->ifindex; 2140 ndm->ndm_ifindex = neigh->dev->ifindex;
2139 2141
2140 NLA_PUT(skb, NDA_DST, neigh->tbl->key_len, neigh->primary_key); 2142 if (nla_put(skb, NDA_DST, neigh->tbl->key_len, neigh->primary_key))
2143 goto nla_put_failure;
2141 2144
2142 read_lock_bh(&neigh->lock); 2145 read_lock_bh(&neigh->lock);
2143 ndm->ndm_state = neigh->nud_state; 2146 ndm->ndm_state = neigh->nud_state;
@@ -2157,8 +2160,9 @@ static int neigh_fill_info(struct sk_buff *skb, struct neighbour *neigh,
2157 ci.ndm_refcnt = atomic_read(&neigh->refcnt) - 1; 2160 ci.ndm_refcnt = atomic_read(&neigh->refcnt) - 1;
2158 read_unlock_bh(&neigh->lock); 2161 read_unlock_bh(&neigh->lock);
2159 2162
2160 NLA_PUT_U32(skb, NDA_PROBES, atomic_read(&neigh->probes)); 2163 if (nla_put_u32(skb, NDA_PROBES, atomic_read(&neigh->probes)) ||
2161 NLA_PUT(skb, NDA_CACHEINFO, sizeof(ci), &ci); 2164 nla_put(skb, NDA_CACHEINFO, sizeof(ci), &ci))
2165 goto nla_put_failure;
2162 2166
2163 return nlmsg_end(skb, nlh); 2167 return nlmsg_end(skb, nlh);
2164 2168
@@ -2187,7 +2191,8 @@ static int pneigh_fill_info(struct sk_buff *skb, struct pneigh_entry *pn,
2187 ndm->ndm_ifindex = pn->dev->ifindex; 2191 ndm->ndm_ifindex = pn->dev->ifindex;
2188 ndm->ndm_state = NUD_NONE; 2192 ndm->ndm_state = NUD_NONE;
2189 2193
2190 NLA_PUT(skb, NDA_DST, tbl->key_len, pn->key); 2194 if (nla_put(skb, NDA_DST, tbl->key_len, pn->key))
2195 goto nla_put_failure;
2191 2196
2192 return nlmsg_end(skb, nlh); 2197 return nlmsg_end(skb, nlh);
2193 2198