Get rid of NLA_PUT*()
Subsystems (22)
David S. Miller
maintainercover Get rid of NLA_PUT*()
This patch series gets rid of all uses of NLA_PUT*() and then kills the definitions of those macros from netlink.h
For the most part, I've tried to do just a straight conversion of:
NLA_PUT*(...);
to
if (nla_put*(...)) goto nla_put_failure;
However in several cases I've tried to make things look more reasonable, for example:
if (val) NLA_PUT*();
becomes:
if (val && nla_put*()) goto nla_put_failure;
multiple consequetive puts get combined into one if() statement, like:
if (nla_put_u32(...) || nla_put_string(...)) goto nla_put_failure;
One thing I have not done is try to get rid of the nla_put_failure label, even in the really simply cases. That's another cleanup altogether, but I will not that some cases can be reduced down to nothing more than:
return nla_put*(...);
Throughout the series, as new (lowercase) nla_put*() intefaces were needed, I added them, right before the first commit to make use of them.
Examples are nla_put_be*(), nlaa_put_net*(), and nla_put_le*().
These are the first commits that will show up in net-next when I open it up.
David S. Miller
maintainerPATCH 1/51 xfrm_user: Stop using NLA_PUT*().
From: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/xfrm/xfrm_user.c | 105 +++++++++++++++++++++++++++++-------------------- 1 files changed, 62 insertions(+), 43 deletions(-)
net/xfrm/xfrm_user.c +62 -43
@@ -756,40 +756,50 @@ static int copy_to_user_state_extra(struct xfrm_state *x, {copy_to_user_state (x, p); -if (x->coaddr) -NLA_PUT (skb,XFRMA_COADDR ,sizeof (*x->coaddr), x->coaddr); +if (x->coaddr && +nla_put (skb,XFRMA_COADDR ,sizeof (*x->coaddr), x->coaddr)) + goto nla_put_failure; -if (x->lastused) -NLA_PUT_U64 (skb,XFRMA_LASTUSED , x->lastused); +if (x->lastused && +nla_put_u64 (skb,XFRMA_LASTUSED , x->lastused)) + goto nla_put_failure; -if (x->aead) -NLA_PUT (skb,XFRMA_ALG_AEAD ,aead_len (x->aead), x->aead); -if (x->aalg) { -if (copy_to_user_auth (x->aalg, skb)) - goto nla_put_failure; +if (x->aead && +nla_put (skb,XFRMA_ALG_AEAD ,aead_len (x->aead), x->aead)) + goto nla_put_failure; -NLA_PUT (skb,XFRMA_ALG_AUTH_TRUNC , -xfrm_alg_auth_len (x->aalg), x->aalg); - } -if (x->ealg) -NLA_PUT (skb,XFRMA_ALG_CRYPT ,xfrm_alg_len (x->ealg), x->ealg); -if (x->calg) -NLA_PUT (skb,XFRMA_ALG_COMP ,sizeof (*(x->calg)), x->calg); +if (x->aalg && + (copy_to_user_auth (x->aalg, skb) || +nla_put (skb,XFRMA_ALG_AUTH_TRUNC , +xfrm_alg_auth_len (x->aalg), x->aalg))) + goto nla_put_failure; -if (x->encap) -NLA_PUT (skb,XFRMA_ENCAP ,sizeof (*x->encap), x->encap); +if (x->ealg && +nla_put (skb,XFRMA_ALG_CRYPT ,xfrm_alg_len (x->ealg), x->ealg)) + goto nla_put_failure; -if (x->tfcpad) -NLA_PUT_U32 (skb,XFRMA_TFCPAD , x->tfcpad); +if (x->calg && +nla_put (skb,XFRMA_ALG_COMP ,sizeof (*(x->calg)), x->calg)) + goto nla_put_failure; + +if (x->encap && +nla_put (skb,XFRMA_ENCAP ,sizeof (*x->encap), x->encap)) + goto nla_put_failure; + +if (x->tfcpad && +nla_put_u32 (skb,XFRMA_TFCPAD , x->tfcpad)) + goto nla_put_failure;if (xfrm_mark_put (skb, &x->mark)) goto nla_put_failure; -if (x->replay_esn) -NLA_PUT (skb,XFRMA_REPLAY_ESN_VAL , -xfrm_replay_state_esn_len (x->replay_esn), x->replay_esn); +if (x->replay_esn && +nla_put (skb,XFRMA_REPLAY_ESN_VAL , +xfrm_replay_state_esn_len (x->replay_esn), + x->replay_esn)) + goto nla_put_failure; -if (x->security &©_sec_ctx (x->security, skb) <0 ) +if (x->security &©_sec_ctx (x->security, skb)) goto nla_put_failure;return 0 ;
@@ -912,8 +922,9 @@ static int build_spdinfo(struct sk_buff *skb, struct net *net, sph.spdhcnt = si.spdhcnt; sph.spdhmcnt = si.spdhmcnt; -NLA_PUT (skb,XFRMA_SPD_INFO ,sizeof (spc), &spc); -NLA_PUT (skb,XFRMA_SPD_HINFO ,sizeof (sph), &sph); +if (nla_put (skb,XFRMA_SPD_INFO ,sizeof (spc), &spc) || +nla_put (skb,XFRMA_SPD_HINFO ,sizeof (sph), &sph)) + goto nla_put_failure;return nlmsg_end (skb, nlh);
@@ -967,8 +978,9 @@ static int build_sadinfo(struct sk_buff *skb, struct net *net, sh.sadhmcnt = si.sadhmcnt; sh.sadhcnt = si.sadhcnt; -NLA_PUT_U32 (skb,XFRMA_SAD_CNT , si.sadcnt); -NLA_PUT (skb,XFRMA_SAD_HINFO ,sizeof (sh), &sh); +if (nla_put_u32 (skb,XFRMA_SAD_CNT , si.sadcnt) || +nla_put (skb,XFRMA_SAD_HINFO ,sizeof (sh), &sh)) + goto nla_put_failure;return nlmsg_end (skb, nlh);
@@ -1690,21 +1702,27 @@ static int build_aevent(struct sk_buff *skb, struct xfrm_state *x, const struct id->reqid = x->props.reqid; id->flags = c->data.aevent; -if (x->replay_esn) -NLA_PUT (skb,XFRMA_REPLAY_ESN_VAL , -xfrm_replay_state_esn_len (x->replay_esn), - x->replay_esn); -else -NLA_PUT (skb,XFRMA_REPLAY_VAL ,sizeof (x->replay), &x->replay); - -NLA_PUT (skb,XFRMA_LTIME_VAL ,sizeof (x->curlft), &x->curlft); +if (x->replay_esn) { +if (nla_put (skb,XFRMA_REPLAY_ESN_VAL , +xfrm_replay_state_esn_len (x->replay_esn), + x->replay_esn)) + goto nla_put_failure; + }else { +if (nla_put (skb,XFRMA_REPLAY_VAL ,sizeof (x->replay), + &x->replay)) + goto nla_put_failure; + } +if (nla_put (skb,XFRMA_LTIME_VAL ,sizeof (x->curlft), &x->curlft)) + goto nla_put_failure; -if (id->flags &XFRM_AE_RTHR ) -NLA_PUT_U32 (skb,XFRMA_REPLAY_THRESH , x->replay_maxdiff); +if ((id->flags &XFRM_AE_RTHR ) && +nla_put_u32 (skb,XFRMA_REPLAY_THRESH , x->replay_maxdiff)) + goto nla_put_failure; -if (id->flags &XFRM_AE_ETHR ) -NLA_PUT_U32 (skb,XFRMA_ETIMER_THRESH , - x->replay_maxage *10 /HZ ); +if ((id->flags &XFRM_AE_ETHR ) && +nla_put_u32 (skb,XFRMA_ETIMER_THRESH , + x->replay_maxage *10 /HZ )) + goto nla_put_failure;if (xfrm_mark_put (skb, &x->mark)) goto nla_put_failure;
@@ -2835,8 +2853,9 @@ static int build_report(struct sk_buff *skb, u8 proto, ur->proto = proto;memcpy (&ur->sel, sel,sizeof (ur->sel)); -if (addr) -NLA_PUT (skb,XFRMA_COADDR ,sizeof (*addr), addr); +if (addr && +nla_put (skb,XFRMA_COADDR ,sizeof (*addr), addr)) + goto nla_put_failure;return nlmsg_end (skb, nlh);
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 2/51 wireless: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/wireless/nl80211.c | 1204 +++++++++++++++++++++++++--------------------- net/wireless/wext-core.c | 3 +- 2 files changed, 662 insertions(+), 545 deletions(-)
net/wireless/nl80211.c +660 -544
@@ -356,20 +356,26 @@ static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,static int nl80211_msg_put_channel (struct sk_buff *msg,struct ieee80211_channel *chan) { -NLA_PUT_U32 (msg,NL80211_FREQUENCY_ATTR_FREQ , - chan->center_freq); +if (nla_put_u32 (msg,NL80211_FREQUENCY_ATTR_FREQ , + chan->center_freq)) + goto nla_put_failure; -if (chan->flags &IEEE80211_CHAN_DISABLED ) -NLA_PUT_FLAG (msg,NL80211_FREQUENCY_ATTR_DISABLED ); -if (chan->flags &IEEE80211_CHAN_PASSIVE_SCAN ) -NLA_PUT_FLAG (msg,NL80211_FREQUENCY_ATTR_PASSIVE_SCAN ); -if (chan->flags &IEEE80211_CHAN_NO_IBSS ) -NLA_PUT_FLAG (msg,NL80211_FREQUENCY_ATTR_NO_IBSS ); -if (chan->flags &IEEE80211_CHAN_RADAR ) -NLA_PUT_FLAG (msg,NL80211_FREQUENCY_ATTR_RADAR ); +if ((chan->flags &IEEE80211_CHAN_DISABLED ) && +nla_put_flag (msg,NL80211_FREQUENCY_ATTR_DISABLED )) + goto nla_put_failure; +if ((chan->flags &IEEE80211_CHAN_PASSIVE_SCAN ) && +nla_put_flag (msg,NL80211_FREQUENCY_ATTR_PASSIVE_SCAN )) + goto nla_put_failure; +if ((chan->flags &IEEE80211_CHAN_NO_IBSS ) && +nla_put_flag (msg,NL80211_FREQUENCY_ATTR_NO_IBSS )) + goto nla_put_failure; +if ((chan->flags &IEEE80211_CHAN_RADAR ) && +nla_put_flag (msg,NL80211_FREQUENCY_ATTR_RADAR )) + goto nla_put_failure; -NLA_PUT_U32 (msg,NL80211_FREQUENCY_ATTR_MAX_TX_POWER , -DBM_TO_MBM (chan->max_power)); +if (nla_put_u32 (msg,NL80211_FREQUENCY_ATTR_MAX_TX_POWER , +DBM_TO_MBM (chan->max_power))) + goto nla_put_failure;return 0 ;
@@ -621,8 +627,8 @@ static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) i =0 ;while (ifmodes) { -if (ifmodes &1 ) -NLA_PUT_FLAG (msg, i); +if ((ifmodes &1 ) &&nla_put_flag (msg, i)) + goto nla_put_failure; ifmodes >>=1 ; i++; }
@@ -665,8 +671,9 @@ static int nl80211_put_iface_combinations(struct wiphy *wiphy, nl_limit =nla_nest_start (msg, j +1 );if (!nl_limit) goto nla_put_failure; -NLA_PUT_U32 (msg,NL80211_IFACE_LIMIT_MAX , - c->limits[j].max); +if (nla_put_u32 (msg,NL80211_IFACE_LIMIT_MAX , + c->limits[j].max)) + goto nla_put_failure;if (nl80211_put_iftypes (msg,NL80211_IFACE_LIMIT_TYPES , c->limits[j].types)) goto nla_put_failure;
@@ -675,13 +682,14 @@ static int nl80211_put_iface_combinations(struct wiphy *wiphy,nla_nest_end (msg, nl_limits); -if (c->beacon_int_infra_match) -NLA_PUT_FLAG (msg, -NL80211_IFACE_COMB_STA_AP_BI_MATCH ); -NLA_PUT_U32 (msg,NL80211_IFACE_COMB_NUM_CHANNELS , - c->num_different_channels); -NLA_PUT_U32 (msg,NL80211_IFACE_COMB_MAXNUM , - c->max_interfaces); +if (c->beacon_int_infra_match && +nla_put_flag (msg,NL80211_IFACE_COMB_STA_AP_BI_MATCH )) + goto nla_put_failure; +if (nla_put_u32 (msg,NL80211_IFACE_COMB_NUM_CHANNELS , + c->num_different_channels) || +nla_put_u32 (msg,NL80211_IFACE_COMB_MAXNUM , + c->max_interfaces)) + goto nla_put_failure;nla_nest_end (msg, nl_combi); }
@@ -712,64 +720,74 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,if (!hdr)return -1 ; -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , dev->wiphy_idx); -NLA_PUT_STRING (msg,NL80211_ATTR_WIPHY_NAME ,wiphy_name (&dev->wiphy)); - -NLA_PUT_U32 (msg,NL80211_ATTR_GENERATION , - cfg80211_rdev_list_generation); - -NLA_PUT_U8 (msg,NL80211_ATTR_WIPHY_RETRY_SHORT , - dev->wiphy.retry_short); -NLA_PUT_U8 (msg,NL80211_ATTR_WIPHY_RETRY_LONG , - dev->wiphy.retry_long); -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY_FRAG_THRESHOLD , - dev->wiphy.frag_threshold); -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY_RTS_THRESHOLD , - dev->wiphy.rts_threshold); -NLA_PUT_U8 (msg,NL80211_ATTR_WIPHY_COVERAGE_CLASS , - dev->wiphy.coverage_class); -NLA_PUT_U8 (msg,NL80211_ATTR_MAX_NUM_SCAN_SSIDS , - dev->wiphy.max_scan_ssids); -NLA_PUT_U8 (msg,NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS , - dev->wiphy.max_sched_scan_ssids); -NLA_PUT_U16 (msg,NL80211_ATTR_MAX_SCAN_IE_LEN , - dev->wiphy.max_scan_ie_len); -NLA_PUT_U16 (msg,NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN , - dev->wiphy.max_sched_scan_ie_len); -NLA_PUT_U8 (msg,NL80211_ATTR_MAX_MATCH_SETS , - dev->wiphy.max_match_sets); - -if (dev->wiphy.flags &WIPHY_FLAG_IBSS_RSN ) -NLA_PUT_FLAG (msg,NL80211_ATTR_SUPPORT_IBSS_RSN ); -if (dev->wiphy.flags &WIPHY_FLAG_MESH_AUTH ) -NLA_PUT_FLAG (msg,NL80211_ATTR_SUPPORT_MESH_AUTH ); -if (dev->wiphy.flags &WIPHY_FLAG_AP_UAPSD ) -NLA_PUT_FLAG (msg,NL80211_ATTR_SUPPORT_AP_UAPSD ); -if (dev->wiphy.flags &WIPHY_FLAG_SUPPORTS_FW_ROAM ) -NLA_PUT_FLAG (msg,NL80211_ATTR_ROAM_SUPPORT ); -if (dev->wiphy.flags &WIPHY_FLAG_SUPPORTS_TDLS ) -NLA_PUT_FLAG (msg,NL80211_ATTR_TDLS_SUPPORT ); -if (dev->wiphy.flags &WIPHY_FLAG_TDLS_EXTERNAL_SETUP ) -NLA_PUT_FLAG (msg,NL80211_ATTR_TDLS_EXTERNAL_SETUP ); - -NLA_PUT (msg,NL80211_ATTR_CIPHER_SUITES , -sizeof (u32) * dev->wiphy.n_cipher_suites, - dev->wiphy.cipher_suites); - -NLA_PUT_U8 (msg,NL80211_ATTR_MAX_NUM_PMKIDS , - dev->wiphy.max_num_pmkids); - -if (dev->wiphy.flags &WIPHY_FLAG_CONTROL_PORT_PROTOCOL ) -NLA_PUT_FLAG (msg,NL80211_ATTR_CONTROL_PORT_ETHERTYPE ); - -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX , - dev->wiphy.available_antennas_tx); -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX , - dev->wiphy.available_antennas_rx); - -if (dev->wiphy.flags &WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD ) -NLA_PUT_U32 (msg,NL80211_ATTR_PROBE_RESP_OFFLOAD , - dev->wiphy.probe_resp_offload); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY , dev->wiphy_idx) || +nla_put_string (msg,NL80211_ATTR_WIPHY_NAME ,wiphy_name (&dev->wiphy)) || +nla_put_u32 (msg,NL80211_ATTR_GENERATION , + cfg80211_rdev_list_generation) || +nla_put_u8 (msg,NL80211_ATTR_WIPHY_RETRY_SHORT , + dev->wiphy.retry_short) || +nla_put_u8 (msg,NL80211_ATTR_WIPHY_RETRY_LONG , + dev->wiphy.retry_long) || +nla_put_u32 (msg,NL80211_ATTR_WIPHY_FRAG_THRESHOLD , + dev->wiphy.frag_threshold) || +nla_put_u32 (msg,NL80211_ATTR_WIPHY_RTS_THRESHOLD , + dev->wiphy.rts_threshold) || +nla_put_u8 (msg,NL80211_ATTR_WIPHY_COVERAGE_CLASS , + dev->wiphy.coverage_class) || +nla_put_u8 (msg,NL80211_ATTR_MAX_NUM_SCAN_SSIDS , + dev->wiphy.max_scan_ssids) || +nla_put_u8 (msg,NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS , + dev->wiphy.max_sched_scan_ssids) || +nla_put_u16 (msg,NL80211_ATTR_MAX_SCAN_IE_LEN , + dev->wiphy.max_scan_ie_len) || +nla_put_u16 (msg,NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN , + dev->wiphy.max_sched_scan_ie_len) || +nla_put_u8 (msg,NL80211_ATTR_MAX_MATCH_SETS , + dev->wiphy.max_match_sets)) + goto nla_put_failure; + +if ((dev->wiphy.flags &WIPHY_FLAG_IBSS_RSN ) && +nla_put_flag (msg,NL80211_ATTR_SUPPORT_IBSS_RSN )) + goto nla_put_failure; +if ((dev->wiphy.flags &WIPHY_FLAG_MESH_AUTH ) && +nla_put_flag (msg,NL80211_ATTR_SUPPORT_MESH_AUTH )) + goto nla_put_failure; +if ((dev->wiphy.flags &WIPHY_FLAG_AP_UAPSD ) && +nla_put_flag (msg,NL80211_ATTR_SUPPORT_AP_UAPSD )) + goto nla_put_failure; +if ((dev->wiphy.flags &WIPHY_FLAG_SUPPORTS_FW_ROAM ) && +nla_put_flag (msg,NL80211_ATTR_ROAM_SUPPORT )) + goto nla_put_failure; +if ((dev->wiphy.flags &WIPHY_FLAG_SUPPORTS_TDLS ) && +nla_put_flag (msg,NL80211_ATTR_TDLS_SUPPORT )) + goto nla_put_failure; +if ((dev->wiphy.flags &WIPHY_FLAG_TDLS_EXTERNAL_SETUP ) && +nla_put_flag (msg,NL80211_ATTR_TDLS_EXTERNAL_SETUP )) + goto nla_put_failure; + +if (nla_put (msg,NL80211_ATTR_CIPHER_SUITES , +sizeof (u32) * dev->wiphy.n_cipher_suites, + dev->wiphy.cipher_suites)) + goto nla_put_failure; + +if (nla_put_u8 (msg,NL80211_ATTR_MAX_NUM_PMKIDS , + dev->wiphy.max_num_pmkids)) + goto nla_put_failure; + +if ((dev->wiphy.flags &WIPHY_FLAG_CONTROL_PORT_PROTOCOL ) && +nla_put_flag (msg,NL80211_ATTR_CONTROL_PORT_ETHERTYPE )) + goto nla_put_failure; + +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX , + dev->wiphy.available_antennas_tx) || +nla_put_u32 (msg,NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX , + dev->wiphy.available_antennas_rx)) + goto nla_put_failure; + +if ((dev->wiphy.flags &WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD ) && +nla_put_u32 (msg,NL80211_ATTR_PROBE_RESP_OFFLOAD , + dev->wiphy.probe_resp_offload)) + goto nla_put_failure;if ((dev->wiphy.available_antennas_tx || dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
@@ -777,8 +795,11 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,int res; res = dev->ops->get_antenna (&dev->wiphy, &tx_ant, &rx_ant);if (!res) { -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY_ANTENNA_TX , tx_ant); -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY_ANTENNA_RX , rx_ant); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY_ANTENNA_TX , + tx_ant) || +nla_put_u32 (msg,NL80211_ATTR_WIPHY_ANTENNA_RX , + rx_ant)) + goto nla_put_failure; } }
@@ -799,17 +820,17 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, goto nla_put_failure;/* add HT info */ -if (dev->wiphy.bands[band]->ht_cap.ht_supported) { -NLA_PUT (msg,NL80211_BAND_ATTR_HT_MCS_SET , -sizeof (dev->wiphy.bands[band]->ht_cap.mcs), - &dev->wiphy.bands[band]->ht_cap.mcs); -NLA_PUT_U16 (msg,NL80211_BAND_ATTR_HT_CAPA , - dev->wiphy.bands[band]->ht_cap.cap); -NLA_PUT_U8 (msg,NL80211_BAND_ATTR_HT_AMPDU_FACTOR , - dev->wiphy.bands[band]->ht_cap.ampdu_factor); -NLA_PUT_U8 (msg,NL80211_BAND_ATTR_HT_AMPDU_DENSITY , - dev->wiphy.bands[band]->ht_cap.ampdu_density); - } +if (dev->wiphy.bands[band]->ht_cap.ht_supported && + (nla_put (msg,NL80211_BAND_ATTR_HT_MCS_SET , +sizeof (dev->wiphy.bands[band]->ht_cap.mcs), + &dev->wiphy.bands[band]->ht_cap.mcs) || +nla_put_u16 (msg,NL80211_BAND_ATTR_HT_CAPA , + dev->wiphy.bands[band]->ht_cap.cap) || +nla_put_u8 (msg,NL80211_BAND_ATTR_HT_AMPDU_FACTOR , + dev->wiphy.bands[band]->ht_cap.ampdu_factor) || +nla_put_u8 (msg,NL80211_BAND_ATTR_HT_AMPDU_DENSITY , + dev->wiphy.bands[band]->ht_cap.ampdu_density))) + goto nla_put_failure;/* add frequencies */ nl_freqs =nla_nest_start (msg,NL80211_BAND_ATTR_FREQS );
@@ -842,11 +863,13 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, goto nla_put_failure; rate = &dev->wiphy.bands[band]->bitrates[i]; -NLA_PUT_U32 (msg,NL80211_BITRATE_ATTR_RATE , - rate->bitrate); -if (rate->flags &IEEE80211_RATE_SHORT_PREAMBLE ) -NLA_PUT_FLAG (msg, -NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE ); +if (nla_put_u32 (msg,NL80211_BITRATE_ATTR_RATE , + rate->bitrate)) + goto nla_put_failure; +if ((rate->flags &IEEE80211_RATE_SHORT_PREAMBLE ) && +nla_put_flag (msg, +NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE )) + goto nla_put_failure;nla_nest_end (msg, nl_rate); }
@@ -866,7 +889,8 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,do { \if (dev->ops->op) { \ i++; \ - NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ + if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ + goto nla_put_failure; \ } \ }while (0 )
@@ -894,7 +918,8 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,CMD (mgmt_tx_cancel_wait,FRAME_WAIT_CANCEL );if (dev->wiphy.flags &WIPHY_FLAG_NETNS_OK ) { i++; -NLA_PUT_U32 (msg, i,NL80211_CMD_SET_WIPHY_NETNS ); +if (nla_put_u32 (msg, i,NL80211_CMD_SET_WIPHY_NETNS )) + goto nla_put_failure; }CMD (set_channel,SET_CHANNEL );CMD (set_wds_peer,SET_WDS_PEER );
@@ -908,7 +933,8 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,CMD (set_noack_map,SET_NOACK_MAP );if (dev->wiphy.flags &WIPHY_FLAG_REPORTS_OBSS ) { i++; -NLA_PUT_U32 (msg, i,NL80211_CMD_REGISTER_BEACONS ); +if (nla_put_u32 (msg, i,NL80211_CMD_REGISTER_BEACONS )) + goto nla_put_failure; }#ifdef CONFIG_NL80211_TESTMODE
@@ -919,23 +945,27 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,if (dev->ops->connect || dev->ops->auth) { i++; -NLA_PUT_U32 (msg, i,NL80211_CMD_CONNECT ); +if (nla_put_u32 (msg, i,NL80211_CMD_CONNECT )) + goto nla_put_failure; }if (dev->ops->disconnect || dev->ops->deauth) { i++; -NLA_PUT_U32 (msg, i,NL80211_CMD_DISCONNECT ); +if (nla_put_u32 (msg, i,NL80211_CMD_DISCONNECT )) + goto nla_put_failure; }nla_nest_end (msg, nl_cmds);if (dev->ops->remain_on_channel && - dev->wiphy.flags &WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL ) -NLA_PUT_U32 (msg,NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION , - dev->wiphy.max_remain_on_channel_duration); + (dev->wiphy.flags &WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL ) && +nla_put_u32 (msg,NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION , + dev->wiphy.max_remain_on_channel_duration)) + goto nla_put_failure; -if (dev->wiphy.flags &WIPHY_FLAG_OFFCHAN_TX ) -NLA_PUT_FLAG (msg,NL80211_ATTR_OFFCHANNEL_TX_OK ); +if ((dev->wiphy.flags &WIPHY_FLAG_OFFCHAN_TX ) && +nla_put_flag (msg,NL80211_ATTR_OFFCHANNEL_TX_OK )) + goto nla_put_failure;if (mgmt_stypes) {u16 stypes;
@@ -953,9 +983,10 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, i =0 ; stypes = mgmt_stypes[ift].tx;while (stypes) { -if (stypes &1 ) -NLA_PUT_U16 (msg,NL80211_ATTR_FRAME_TYPE , - (i <<4 ) |IEEE80211_FTYPE_MGMT ); +if ((stypes &1 ) && +nla_put_u16 (msg,NL80211_ATTR_FRAME_TYPE , + (i <<4 ) |IEEE80211_FTYPE_MGMT )) + goto nla_put_failure; stypes >>=1 ; i++; }
@@ -975,9 +1006,10 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, i =0 ; stypes = mgmt_stypes[ift].rx;while (stypes) { -if (stypes &1 ) -NLA_PUT_U16 (msg,NL80211_ATTR_FRAME_TYPE , - (i <<4 ) |IEEE80211_FTYPE_MGMT ); +if ((stypes &1 ) && +nla_put_u16 (msg,NL80211_ATTR_FRAME_TYPE , + (i <<4 ) |IEEE80211_FTYPE_MGMT )) + goto nla_put_failure; stypes >>=1 ; i++; }
@@ -994,22 +1026,23 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,if (!nl_wowlan) goto nla_put_failure; -if (dev->wiphy.wowlan.flags &WIPHY_WOWLAN_ANY ) -NLA_PUT_FLAG (msg,NL80211_WOWLAN_TRIG_ANY ); -if (dev->wiphy.wowlan.flags &WIPHY_WOWLAN_DISCONNECT ) -NLA_PUT_FLAG (msg,NL80211_WOWLAN_TRIG_DISCONNECT ); -if (dev->wiphy.wowlan.flags &WIPHY_WOWLAN_MAGIC_PKT ) -NLA_PUT_FLAG (msg,NL80211_WOWLAN_TRIG_MAGIC_PKT ); -if (dev->wiphy.wowlan.flags &WIPHY_WOWLAN_SUPPORTS_GTK_REKEY ) -NLA_PUT_FLAG (msg,NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED ); -if (dev->wiphy.wowlan.flags &WIPHY_WOWLAN_GTK_REKEY_FAILURE ) -NLA_PUT_FLAG (msg,NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE ); -if (dev->wiphy.wowlan.flags &WIPHY_WOWLAN_EAP_IDENTITY_REQ ) -NLA_PUT_FLAG (msg,NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST ); -if (dev->wiphy.wowlan.flags &WIPHY_WOWLAN_4WAY_HANDSHAKE ) -NLA_PUT_FLAG (msg,NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE ); -if (dev->wiphy.wowlan.flags &WIPHY_WOWLAN_RFKILL_RELEASE ) -NLA_PUT_FLAG (msg,NL80211_WOWLAN_TRIG_RFKILL_RELEASE ); +if (((dev->wiphy.wowlan.flags &WIPHY_WOWLAN_ANY ) && +nla_put_flag (msg,NL80211_WOWLAN_TRIG_ANY )) || + ((dev->wiphy.wowlan.flags &WIPHY_WOWLAN_DISCONNECT ) && +nla_put_flag (msg,NL80211_WOWLAN_TRIG_DISCONNECT )) || + ((dev->wiphy.wowlan.flags &WIPHY_WOWLAN_MAGIC_PKT ) && +nla_put_flag (msg,NL80211_WOWLAN_TRIG_MAGIC_PKT )) || + ((dev->wiphy.wowlan.flags &WIPHY_WOWLAN_SUPPORTS_GTK_REKEY ) && +nla_put_flag (msg,NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED )) || + ((dev->wiphy.wowlan.flags &WIPHY_WOWLAN_GTK_REKEY_FAILURE ) && +nla_put_flag (msg,NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE )) || + ((dev->wiphy.wowlan.flags &WIPHY_WOWLAN_EAP_IDENTITY_REQ ) && +nla_put_flag (msg,NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST )) || + ((dev->wiphy.wowlan.flags &WIPHY_WOWLAN_4WAY_HANDSHAKE ) && +nla_put_flag (msg,NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE )) || + ((dev->wiphy.wowlan.flags &WIPHY_WOWLAN_RFKILL_RELEASE ) && +nla_put_flag (msg,NL80211_WOWLAN_TRIG_RFKILL_RELEASE ))) + goto nla_put_failure;if (dev->wiphy.wowlan.n_patterns) {struct nl80211_wowlan_pattern_support pat = { .max_patterns = dev->wiphy.wowlan.n_patterns,
@@ -1018,8 +1051,9 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, .max_pattern_len = dev->wiphy.wowlan.pattern_max_len, }; -NLA_PUT (msg,NL80211_WOWLAN_TRIG_PKT_PATTERN , -sizeof (pat), &pat); +if (nla_put (msg,NL80211_WOWLAN_TRIG_PKT_PATTERN , +sizeof (pat), &pat)) + goto nla_put_failure; }nla_nest_end (msg, nl_wowlan);
@@ -1032,16 +1066,20 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,if (nl80211_put_iface_combinations (&dev->wiphy, msg)) goto nla_put_failure; -if (dev->wiphy.flags &WIPHY_FLAG_HAVE_AP_SME ) -NLA_PUT_U32 (msg,NL80211_ATTR_DEVICE_AP_SME , - dev->wiphy.ap_sme_capa); +if ((dev->wiphy.flags &WIPHY_FLAG_HAVE_AP_SME ) && +nla_put_u32 (msg,NL80211_ATTR_DEVICE_AP_SME , + dev->wiphy.ap_sme_capa)) + goto nla_put_failure; -NLA_PUT_U32 (msg,NL80211_ATTR_FEATURE_FLAGS , dev->wiphy.features); +if (nla_put_u32 (msg,NL80211_ATTR_FEATURE_FLAGS , + dev->wiphy.features)) + goto nla_put_failure; -if (dev->wiphy.ht_capa_mod_mask) -NLA_PUT (msg,NL80211_ATTR_HT_CAPABILITY_MASK , -sizeof (*dev->wiphy.ht_capa_mod_mask), - dev->wiphy.ht_capa_mod_mask); +if (dev->wiphy.ht_capa_mod_mask && +nla_put (msg,NL80211_ATTR_HT_CAPABILITY_MASK , +sizeof (*dev->wiphy.ht_capa_mod_mask), + dev->wiphy.ht_capa_mod_mask)) + goto nla_put_failure;return genlmsg_end (msg, hdr);
@@ -1484,14 +1522,15 @@ static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,if (!hdr)return -1 ; -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , dev->ifindex); -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx); -NLA_PUT_STRING (msg,NL80211_ATTR_IFNAME , dev->name); -NLA_PUT_U32 (msg,NL80211_ATTR_IFTYPE , dev->ieee80211_ptr->iftype); - -NLA_PUT_U32 (msg,NL80211_ATTR_GENERATION , - rdev->devlist_generation ^ - (cfg80211_rdev_list_generation <<2 )); +if (nla_put_u32 (msg,NL80211_ATTR_IFINDEX , dev->ifindex) || +nla_put_u32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx) || +nla_put_string (msg,NL80211_ATTR_IFNAME , dev->name) || +nla_put_u32 (msg,NL80211_ATTR_IFTYPE , + dev->ieee80211_ptr->iftype) || +nla_put_u32 (msg,NL80211_ATTR_GENERATION , + rdev->devlist_generation ^ + (cfg80211_rdev_list_generation <<2 ))) + goto nla_put_failure;return genlmsg_end (msg, hdr);
@@ -1789,35 +1828,34 @@ static void get_key_callback(void *c, struct key_params *params)struct nlattr *key;struct get_key_cookie *cookie = c; -if (params->key) -NLA_PUT (cookie->msg,NL80211_ATTR_KEY_DATA , - params->key_len, params->key); - -if (params->seq) -NLA_PUT (cookie->msg,NL80211_ATTR_KEY_SEQ , - params->seq_len, params->seq); - -if (params->cipher) -NLA_PUT_U32 (cookie->msg,NL80211_ATTR_KEY_CIPHER , - params->cipher); +if ((params->key && +nla_put (cookie->msg,NL80211_ATTR_KEY_DATA , + params->key_len, params->key)) || + (params->seq && +nla_put (cookie->msg,NL80211_ATTR_KEY_SEQ , + params->seq_len, params->seq)) || + (params->cipher && +nla_put_u32 (cookie->msg,NL80211_ATTR_KEY_CIPHER , + params->cipher))) + goto nla_put_failure; key =nla_nest_start (cookie->msg,NL80211_ATTR_KEY );if (!key) goto nla_put_failure; -if (params->key) -NLA_PUT (cookie->msg,NL80211_KEY_DATA , - params->key_len, params->key); - -if (params->seq) -NLA_PUT (cookie->msg,NL80211_KEY_SEQ , - params->seq_len, params->seq); - -if (params->cipher) -NLA_PUT_U32 (cookie->msg,NL80211_KEY_CIPHER , - params->cipher); +if ((params->key && +nla_put (cookie->msg,NL80211_KEY_DATA , + params->key_len, params->key)) || + (params->seq && +nla_put (cookie->msg,NL80211_KEY_SEQ , + params->seq_len, params->seq)) || + (params->cipher && +nla_put_u32 (cookie->msg,NL80211_KEY_CIPHER , + params->cipher))) + goto nla_put_failure; -NLA_PUT_U8 (cookie->msg,NL80211_ATTR_KEY_IDX , cookie->idx); +if (nla_put_u8 (cookie->msg,NL80211_ATTR_KEY_IDX , cookie->idx)) + goto nla_put_failure;nla_nest_end (cookie->msg, key);
@@ -1875,10 +1913,12 @@ static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) cookie.msg = msg; cookie.idx = key_idx; -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , dev->ifindex); -NLA_PUT_U8 (msg,NL80211_ATTR_KEY_IDX , key_idx); -if (mac_addr) -NLA_PUT (msg,NL80211_ATTR_MAC ,ETH_ALEN , mac_addr); +if (nla_put_u32 (msg,NL80211_ATTR_IFINDEX , dev->ifindex) || +nla_put_u8 (msg,NL80211_ATTR_KEY_IDX , key_idx)) + goto nla_put_failure; +if (mac_addr && +nla_put (msg,NL80211_ATTR_MAC ,ETH_ALEN , mac_addr)) + goto nla_put_failure;if (pairwise && mac_addr && !(rdev->wiphy.flags &WIPHY_FLAG_IBSS_RSN ))
@@ -2368,15 +2408,15 @@ static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,/* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ bitrate =cfg80211_calculate_bitrate (info); -if (bitrate >0 ) -NLA_PUT_U16 (msg,NL80211_RATE_INFO_BITRATE , bitrate); - -if (info->flags &RATE_INFO_FLAGS_MCS ) -NLA_PUT_U8 (msg,NL80211_RATE_INFO_MCS , info->mcs); -if (info->flags &RATE_INFO_FLAGS_40_MHZ_WIDTH ) -NLA_PUT_FLAG (msg,NL80211_RATE_INFO_40_MHZ_WIDTH ); -if (info->flags &RATE_INFO_FLAGS_SHORT_GI ) -NLA_PUT_FLAG (msg,NL80211_RATE_INFO_SHORT_GI ); +if ((bitrate >0 && +nla_put_u16 (msg,NL80211_RATE_INFO_BITRATE , bitrate)) || + ((info->flags &RATE_INFO_FLAGS_MCS ) && +nla_put_u8 (msg,NL80211_RATE_INFO_MCS , info->mcs)) || + ((info->flags &RATE_INFO_FLAGS_40_MHZ_WIDTH ) && +nla_put_flag (msg,NL80211_RATE_INFO_40_MHZ_WIDTH )) || + ((info->flags &RATE_INFO_FLAGS_SHORT_GI ) && +nla_put_flag (msg,NL80211_RATE_INFO_SHORT_GI ))) + goto nla_put_failure;nla_nest_end (msg, rate);return true;
@@ -2398,43 +2438,50 @@ static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,if (!hdr)return -1 ; -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , dev->ifindex); -NLA_PUT (msg,NL80211_ATTR_MAC ,ETH_ALEN , mac_addr); - -NLA_PUT_U32 (msg,NL80211_ATTR_GENERATION , sinfo->generation); +if (nla_put_u32 (msg,NL80211_ATTR_IFINDEX , dev->ifindex) || +nla_put (msg,NL80211_ATTR_MAC ,ETH_ALEN , mac_addr) || +nla_put_u32 (msg,NL80211_ATTR_GENERATION , sinfo->generation)) + goto nla_put_failure; sinfoattr =nla_nest_start (msg,NL80211_ATTR_STA_INFO );if (!sinfoattr) goto nla_put_failure; -if (sinfo->filled &STATION_INFO_CONNECTED_TIME ) -NLA_PUT_U32 (msg,NL80211_STA_INFO_CONNECTED_TIME , - sinfo->connected_time); -if (sinfo->filled &STATION_INFO_INACTIVE_TIME ) -NLA_PUT_U32 (msg,NL80211_STA_INFO_INACTIVE_TIME , - sinfo->inactive_time); -if (sinfo->filled &STATION_INFO_RX_BYTES ) -NLA_PUT_U32 (msg,NL80211_STA_INFO_RX_BYTES , - sinfo->rx_bytes); -if (sinfo->filled &STATION_INFO_TX_BYTES ) -NLA_PUT_U32 (msg,NL80211_STA_INFO_TX_BYTES , - sinfo->tx_bytes); -if (sinfo->filled &STATION_INFO_LLID ) -NLA_PUT_U16 (msg,NL80211_STA_INFO_LLID , - sinfo->llid); -if (sinfo->filled &STATION_INFO_PLID ) -NLA_PUT_U16 (msg,NL80211_STA_INFO_PLID , - sinfo->plid); -if (sinfo->filled &STATION_INFO_PLINK_STATE ) -NLA_PUT_U8 (msg,NL80211_STA_INFO_PLINK_STATE , - sinfo->plink_state); +if ((sinfo->filled &STATION_INFO_CONNECTED_TIME ) && +nla_put_u32 (msg,NL80211_STA_INFO_CONNECTED_TIME , + sinfo->connected_time)) + goto nla_put_failure; +if ((sinfo->filled &STATION_INFO_INACTIVE_TIME ) && +nla_put_u32 (msg,NL80211_STA_INFO_INACTIVE_TIME , + sinfo->inactive_time)) + goto nla_put_failure; +if ((sinfo->filled &STATION_INFO_RX_BYTES ) && +nla_put_u32 (msg,NL80211_STA_INFO_RX_BYTES , + sinfo->rx_bytes)) + goto nla_put_failure; +if ((sinfo->filled &STATION_INFO_TX_BYTES ) && +nla_put_u32 (msg,NL80211_STA_INFO_TX_BYTES , + sinfo->tx_bytes)) + goto nla_put_failure; +if ((sinfo->filled &STATION_INFO_LLID ) && +nla_put_u16 (msg,NL80211_STA_INFO_LLID , sinfo->llid)) + goto nla_put_failure; +if ((sinfo->filled &STATION_INFO_PLID ) && +nla_put_u16 (msg,NL80211_STA_INFO_PLID , sinfo->plid)) + goto nla_put_failure; +if ((sinfo->filled &STATION_INFO_PLINK_STATE ) && +nla_put_u8 (msg,NL80211_STA_INFO_PLINK_STATE , + sinfo->plink_state)) + goto nla_put_failure;switch (rdev->wiphy.signal_type) {case CFG80211_SIGNAL_TYPE_MBM : -if (sinfo->filled &STATION_INFO_SIGNAL ) -NLA_PUT_U8 (msg,NL80211_STA_INFO_SIGNAL , - sinfo->signal); -if (sinfo->filled &STATION_INFO_SIGNAL_AVG ) -NLA_PUT_U8 (msg,NL80211_STA_INFO_SIGNAL_AVG , - sinfo->signal_avg); +if ((sinfo->filled &STATION_INFO_SIGNAL ) && +nla_put_u8 (msg,NL80211_STA_INFO_SIGNAL , + sinfo->signal)) + goto nla_put_failure; +if ((sinfo->filled &STATION_INFO_SIGNAL_AVG ) && +nla_put_u8 (msg,NL80211_STA_INFO_SIGNAL_AVG , + sinfo->signal_avg)) + goto nla_put_failure;break ;default :break ;
@@ -2449,49 +2496,56 @@ static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, NL80211_STA_INFO_RX_BITRATE)) goto nla_put_failure; } -if (sinfo->filled &STATION_INFO_RX_PACKETS ) -NLA_PUT_U32 (msg,NL80211_STA_INFO_RX_PACKETS , - sinfo->rx_packets); -if (sinfo->filled &STATION_INFO_TX_PACKETS ) -NLA_PUT_U32 (msg,NL80211_STA_INFO_TX_PACKETS , - sinfo->tx_packets); -if (sinfo->filled &STATION_INFO_TX_RETRIES ) -NLA_PUT_U32 (msg,NL80211_STA_INFO_TX_RETRIES , - sinfo->tx_retries); -if (sinfo->filled &STATION_INFO_TX_FAILED ) -NLA_PUT_U32 (msg,NL80211_STA_INFO_TX_FAILED , - sinfo->tx_failed); -if (sinfo->filled &STATION_INFO_BEACON_LOSS_COUNT ) -NLA_PUT_U32 (msg,NL80211_STA_INFO_BEACON_LOSS , - sinfo->beacon_loss_count); +if ((sinfo->filled &STATION_INFO_RX_PACKETS ) && +nla_put_u32 (msg,NL80211_STA_INFO_RX_PACKETS , + sinfo->rx_packets)) + goto nla_put_failure; +if ((sinfo->filled &STATION_INFO_TX_PACKETS ) && +nla_put_u32 (msg,NL80211_STA_INFO_TX_PACKETS , + sinfo->tx_packets)) + goto nla_put_failure; +if ((sinfo->filled &STATION_INFO_TX_RETRIES ) && +nla_put_u32 (msg,NL80211_STA_INFO_TX_RETRIES , + sinfo->tx_retries)) + goto nla_put_failure; +if ((sinfo->filled &STATION_INFO_TX_FAILED ) && +nla_put_u32 (msg,NL80211_STA_INFO_TX_FAILED , + sinfo->tx_failed)) + goto nla_put_failure; +if ((sinfo->filled &STATION_INFO_BEACON_LOSS_COUNT ) && +nla_put_u32 (msg,NL80211_STA_INFO_BEACON_LOSS , + sinfo->beacon_loss_count)) + goto nla_put_failure;if (sinfo->filled &STATION_INFO_BSS_PARAM ) { bss_param =nla_nest_start (msg,NL80211_STA_INFO_BSS_PARAM );if (!bss_param) goto nla_put_failure; -if (sinfo->bss_param.flags &BSS_PARAM_FLAGS_CTS_PROT ) -NLA_PUT_FLAG (msg,NL80211_STA_BSS_PARAM_CTS_PROT ); -if (sinfo->bss_param.flags &BSS_PARAM_FLAGS_SHORT_PREAMBLE ) -NLA_PUT_FLAG (msg,NL80211_STA_BSS_PARAM_SHORT_PREAMBLE ); -if (sinfo->bss_param.flags &BSS_PARAM_FLAGS_SHORT_SLOT_TIME ) -NLA_PUT_FLAG (msg, -NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME ); -NLA_PUT_U8 (msg,NL80211_STA_BSS_PARAM_DTIM_PERIOD , - sinfo->bss_param.dtim_period); -NLA_PUT_U16 (msg,NL80211_STA_BSS_PARAM_BEACON_INTERVAL , - sinfo->bss_param.beacon_interval); +if (((sinfo->bss_param.flags &BSS_PARAM_FLAGS_CTS_PROT ) && +nla_put_flag (msg,NL80211_STA_BSS_PARAM_CTS_PROT )) || + ((sinfo->bss_param.flags &BSS_PARAM_FLAGS_SHORT_PREAMBLE ) && +nla_put_flag (msg,NL80211_STA_BSS_PARAM_SHORT_PREAMBLE )) || + ((sinfo->bss_param.flags &BSS_PARAM_FLAGS_SHORT_SLOT_TIME ) && +nla_put_flag (msg,NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME )) || +nla_put_u8 (msg,NL80211_STA_BSS_PARAM_DTIM_PERIOD , + sinfo->bss_param.dtim_period) || +nla_put_u16 (msg,NL80211_STA_BSS_PARAM_BEACON_INTERVAL , + sinfo->bss_param.beacon_interval)) + goto nla_put_failure;nla_nest_end (msg, bss_param); } -if (sinfo->filled &STATION_INFO_STA_FLAGS ) -NLA_PUT (msg,NL80211_STA_INFO_STA_FLAGS , -sizeof (struct nl80211_sta_flag_update ), - &sinfo->sta_flags); +if ((sinfo->filled &STATION_INFO_STA_FLAGS ) && +nla_put (msg,NL80211_STA_INFO_STA_FLAGS , +sizeof (struct nl80211_sta_flag_update ), + &sinfo->sta_flags)) + goto nla_put_failure;nla_nest_end (msg, sinfoattr); -if (sinfo->filled &STATION_INFO_ASSOC_REQ_IES ) -NLA_PUT (msg,NL80211_ATTR_IE , sinfo->assoc_req_ies_len, - sinfo->assoc_req_ies); +if ((sinfo->filled &STATION_INFO_ASSOC_REQ_IES ) && +nla_put (msg,NL80211_ATTR_IE , sinfo->assoc_req_ies_len, + sinfo->assoc_req_ies)) + goto nla_put_failure;return genlmsg_end (msg, hdr);
@@ -2913,36 +2967,37 @@ static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,if (!hdr)return -1 ; -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , dev->ifindex); -NLA_PUT (msg,NL80211_ATTR_MAC ,ETH_ALEN , dst); -NLA_PUT (msg,NL80211_ATTR_MPATH_NEXT_HOP ,ETH_ALEN , next_hop); - -NLA_PUT_U32 (msg,NL80211_ATTR_GENERATION , pinfo->generation); +if (nla_put_u32 (msg,NL80211_ATTR_IFINDEX , dev->ifindex) || +nla_put (msg,NL80211_ATTR_MAC ,ETH_ALEN , dst) || +nla_put (msg,NL80211_ATTR_MPATH_NEXT_HOP ,ETH_ALEN , next_hop) || +nla_put_u32 (msg,NL80211_ATTR_GENERATION , pinfo->generation)) + goto nla_put_failure; pinfoattr =nla_nest_start (msg,NL80211_ATTR_MPATH_INFO );if (!pinfoattr) goto nla_put_failure; -if (pinfo->filled &MPATH_INFO_FRAME_QLEN ) -NLA_PUT_U32 (msg,NL80211_MPATH_INFO_FRAME_QLEN , - pinfo->frame_qlen); -if (pinfo->filled &MPATH_INFO_SN ) -NLA_PUT_U32 (msg,NL80211_MPATH_INFO_SN , - pinfo->sn); -if (pinfo->filled &MPATH_INFO_METRIC ) -NLA_PUT_U32 (msg,NL80211_MPATH_INFO_METRIC , - pinfo->metric); -if (pinfo->filled &MPATH_INFO_EXPTIME ) -NLA_PUT_U32 (msg,NL80211_MPATH_INFO_EXPTIME , - pinfo->exptime); -if (pinfo->filled &MPATH_INFO_FLAGS ) -NLA_PUT_U8 (msg,NL80211_MPATH_INFO_FLAGS , - pinfo->flags); -if (pinfo->filled &MPATH_INFO_DISCOVERY_TIMEOUT ) -NLA_PUT_U32 (msg,NL80211_MPATH_INFO_DISCOVERY_TIMEOUT , - pinfo->discovery_timeout); -if (pinfo->filled &MPATH_INFO_DISCOVERY_RETRIES ) -NLA_PUT_U8 (msg,NL80211_MPATH_INFO_DISCOVERY_RETRIES , - pinfo->discovery_retries); +if ((pinfo->filled &MPATH_INFO_FRAME_QLEN ) && +nla_put_u32 (msg,NL80211_MPATH_INFO_FRAME_QLEN , + pinfo->frame_qlen)) + goto nla_put_failure; +if (((pinfo->filled &MPATH_INFO_SN ) && +nla_put_u32 (msg,NL80211_MPATH_INFO_SN , pinfo->sn)) || + ((pinfo->filled &MPATH_INFO_METRIC ) && +nla_put_u32 (msg,NL80211_MPATH_INFO_METRIC , + pinfo->metric)) || + ((pinfo->filled &MPATH_INFO_EXPTIME ) && +nla_put_u32 (msg,NL80211_MPATH_INFO_EXPTIME , + pinfo->exptime)) || + ((pinfo->filled &MPATH_INFO_FLAGS ) && +nla_put_u8 (msg,NL80211_MPATH_INFO_FLAGS , + pinfo->flags)) || + ((pinfo->filled &MPATH_INFO_DISCOVERY_TIMEOUT ) && +nla_put_u32 (msg,NL80211_MPATH_INFO_DISCOVERY_TIMEOUT , + pinfo->discovery_timeout)) || + ((pinfo->filled &MPATH_INFO_DISCOVERY_RETRIES ) && +nla_put_u8 (msg,NL80211_MPATH_INFO_DISCOVERY_RETRIES , + pinfo->discovery_retries))) + goto nla_put_failure;nla_nest_end (msg, pinfoattr);
@@ -3268,47 +3323,48 @@ static int nl80211_get_mesh_config(struct sk_buff *skb, pinfoattr =nla_nest_start (msg,NL80211_ATTR_MESH_CONFIG );if (!pinfoattr) goto nla_put_failure; -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , dev->ifindex); -NLA_PUT_U16 (msg,NL80211_MESHCONF_RETRY_TIMEOUT , - cur_params.dot11MeshRetryTimeout); -NLA_PUT_U16 (msg,NL80211_MESHCONF_CONFIRM_TIMEOUT , - cur_params.dot11MeshConfirmTimeout); -NLA_PUT_U16 (msg,NL80211_MESHCONF_HOLDING_TIMEOUT , - cur_params.dot11MeshHoldingTimeout); -NLA_PUT_U16 (msg,NL80211_MESHCONF_MAX_PEER_LINKS , - cur_params.dot11MeshMaxPeerLinks); -NLA_PUT_U8 (msg,NL80211_MESHCONF_MAX_RETRIES , - cur_params.dot11MeshMaxRetries); -NLA_PUT_U8 (msg,NL80211_MESHCONF_TTL , - cur_params.dot11MeshTTL); -NLA_PUT_U8 (msg,NL80211_MESHCONF_ELEMENT_TTL , - cur_params.element_ttl); -NLA_PUT_U8 (msg,NL80211_MESHCONF_AUTO_OPEN_PLINKS , - cur_params.auto_open_plinks); -NLA_PUT_U8 (msg,NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES , - cur_params.dot11MeshHWMPmaxPREQretries); -NLA_PUT_U32 (msg,NL80211_MESHCONF_PATH_REFRESH_TIME , - cur_params.path_refresh_time); -NLA_PUT_U16 (msg,NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT , - cur_params.min_discovery_timeout); -NLA_PUT_U32 (msg,NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT , - cur_params.dot11MeshHWMPactivePathTimeout); -NLA_PUT_U16 (msg,NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL , - cur_params.dot11MeshHWMPpreqMinInterval); -NLA_PUT_U16 (msg,NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL , - cur_params.dot11MeshHWMPperrMinInterval); -NLA_PUT_U16 (msg,NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME , - cur_params.dot11MeshHWMPnetDiameterTraversalTime); -NLA_PUT_U8 (msg,NL80211_MESHCONF_HWMP_ROOTMODE , - cur_params.dot11MeshHWMPRootMode); -NLA_PUT_U16 (msg,NL80211_MESHCONF_HWMP_RANN_INTERVAL , - cur_params.dot11MeshHWMPRannInterval); -NLA_PUT_U8 (msg,NL80211_MESHCONF_GATE_ANNOUNCEMENTS , - cur_params.dot11MeshGateAnnouncementProtocol); -NLA_PUT_U8 (msg,NL80211_MESHCONF_FORWARDING , - cur_params.dot11MeshForwarding); -NLA_PUT_U32 (msg,NL80211_MESHCONF_RSSI_THRESHOLD , - cur_params.rssi_threshold); +if (nla_put_u32 (msg,NL80211_ATTR_IFINDEX , dev->ifindex) || +nla_put_u16 (msg,NL80211_MESHCONF_RETRY_TIMEOUT , + cur_params.dot11MeshRetryTimeout) || +nla_put_u16 (msg,NL80211_MESHCONF_CONFIRM_TIMEOUT , + cur_params.dot11MeshConfirmTimeout) || +nla_put_u16 (msg,NL80211_MESHCONF_HOLDING_TIMEOUT , + cur_params.dot11MeshHoldingTimeout) || +nla_put_u16 (msg,NL80211_MESHCONF_MAX_PEER_LINKS , + cur_params.dot11MeshMaxPeerLinks) || +nla_put_u8 (msg,NL80211_MESHCONF_MAX_RETRIES , + cur_params.dot11MeshMaxRetries) || +nla_put_u8 (msg,NL80211_MESHCONF_TTL , + cur_params.dot11MeshTTL) || +nla_put_u8 (msg,NL80211_MESHCONF_ELEMENT_TTL , + cur_params.element_ttl) || +nla_put_u8 (msg,NL80211_MESHCONF_AUTO_OPEN_PLINKS , + cur_params.auto_open_plinks) || +nla_put_u8 (msg,NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES , + cur_params.dot11MeshHWMPmaxPREQretries) || +nla_put_u32 (msg,NL80211_MESHCONF_PATH_REFRESH_TIME , + cur_params.path_refresh_time) || +nla_put_u16 (msg,NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT , + cur_params.min_discovery_timeout) || +nla_put_u32 (msg,NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT , + cur_params.dot11MeshHWMPactivePathTimeout) || +nla_put_u16 (msg,NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL , + cur_params.dot11MeshHWMPpreqMinInterval) || +nla_put_u16 (msg,NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL , + cur_params.dot11MeshHWMPperrMinInterval) || +nla_put_u16 (msg,NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME , + cur_params.dot11MeshHWMPnetDiameterTraversalTime) || +nla_put_u8 (msg,NL80211_MESHCONF_HWMP_ROOTMODE , + cur_params.dot11MeshHWMPRootMode) || +nla_put_u16 (msg,NL80211_MESHCONF_HWMP_RANN_INTERVAL , + cur_params.dot11MeshHWMPRannInterval) || +nla_put_u8 (msg,NL80211_MESHCONF_GATE_ANNOUNCEMENTS , + cur_params.dot11MeshGateAnnouncementProtocol) || +nla_put_u8 (msg,NL80211_MESHCONF_FORWARDING , + cur_params.dot11MeshForwarding) || +nla_put_u32 (msg,NL80211_MESHCONF_RSSI_THRESHOLD , + cur_params.rssi_threshold)) + goto nla_put_failure;nla_nest_end (msg, pinfoattr);genlmsg_end (msg, hdr);return genlmsg_reply (msg, info);
@@ -3539,11 +3595,12 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)if (!hdr) goto put_failure; -NLA_PUT_STRING (msg,NL80211_ATTR_REG_ALPHA2 , - cfg80211_regdomain->alpha2); -if (cfg80211_regdomain->dfs_region) -NLA_PUT_U8 (msg,NL80211_ATTR_DFS_REGION , - cfg80211_regdomain->dfs_region); +if (nla_put_string (msg,NL80211_ATTR_REG_ALPHA2 , + cfg80211_regdomain->alpha2) || + (cfg80211_regdomain->dfs_region && +nla_put_u8 (msg,NL80211_ATTR_DFS_REGION , + cfg80211_regdomain->dfs_region))) + goto nla_put_failure; nl_reg_rules =nla_nest_start (msg,NL80211_ATTR_REG_RULES );if (!nl_reg_rules)
@@ -3563,18 +3620,19 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)if (!nl_reg_rule) goto nla_put_failure; -NLA_PUT_U32 (msg,NL80211_ATTR_REG_RULE_FLAGS , - reg_rule->flags); -NLA_PUT_U32 (msg,NL80211_ATTR_FREQ_RANGE_START , - freq_range->start_freq_khz); -NLA_PUT_U32 (msg,NL80211_ATTR_FREQ_RANGE_END , - freq_range->end_freq_khz); -NLA_PUT_U32 (msg,NL80211_ATTR_FREQ_RANGE_MAX_BW , - freq_range->max_bandwidth_khz); -NLA_PUT_U32 (msg,NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN , - power_rule->max_antenna_gain); -NLA_PUT_U32 (msg,NL80211_ATTR_POWER_RULE_MAX_EIRP , - power_rule->max_eirp); +if (nla_put_u32 (msg,NL80211_ATTR_REG_RULE_FLAGS , + reg_rule->flags) || +nla_put_u32 (msg,NL80211_ATTR_FREQ_RANGE_START , + freq_range->start_freq_khz) || +nla_put_u32 (msg,NL80211_ATTR_FREQ_RANGE_END , + freq_range->end_freq_khz) || +nla_put_u32 (msg,NL80211_ATTR_FREQ_RANGE_MAX_BW , + freq_range->max_bandwidth_khz) || +nla_put_u32 (msg,NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN , + power_rule->max_antenna_gain) || +nla_put_u32 (msg,NL80211_ATTR_POWER_RULE_MAX_EIRP , + power_rule->max_eirp)) + goto nla_put_failure;nla_nest_end (msg, nl_reg_rule); }
@@ -4145,37 +4203,44 @@ static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,genl_dump_check_consistent (cb, hdr, &nl80211_fam); -NLA_PUT_U32 (msg,NL80211_ATTR_GENERATION , rdev->bss_generation); -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , wdev->netdev->ifindex); +if (nla_put_u32 (msg,NL80211_ATTR_GENERATION , rdev->bss_generation) || +nla_put_u32 (msg,NL80211_ATTR_IFINDEX , wdev->netdev->ifindex)) + goto nla_put_failure; bss =nla_nest_start (msg,NL80211_ATTR_BSS );if (!bss) goto nla_put_failure; -if (!is_zero_ether_addr (res->bssid)) -NLA_PUT (msg,NL80211_BSS_BSSID ,ETH_ALEN , res->bssid); -if (res->information_elements && res->len_information_elements) -NLA_PUT (msg,NL80211_BSS_INFORMATION_ELEMENTS , - res->len_information_elements, - res->information_elements); -if (res->beacon_ies && res->len_beacon_ies && - res->beacon_ies != res->information_elements) -NLA_PUT (msg,NL80211_BSS_BEACON_IES , - res->len_beacon_ies, res->beacon_ies); -if (res->tsf) -NLA_PUT_U64 (msg,NL80211_BSS_TSF , res->tsf); -if (res->beacon_interval) -NLA_PUT_U16 (msg,NL80211_BSS_BEACON_INTERVAL , res->beacon_interval); -NLA_PUT_U16 (msg,NL80211_BSS_CAPABILITY , res->capability); -NLA_PUT_U32 (msg,NL80211_BSS_FREQUENCY , res->channel->center_freq); -NLA_PUT_U32 (msg,NL80211_BSS_SEEN_MS_AGO , -jiffies_to_msecs (jiffies - intbss->ts)); +if ((!is_zero_ether_addr (res->bssid) && +nla_put (msg,NL80211_BSS_BSSID ,ETH_ALEN , res->bssid)) || + (res->information_elements && res->len_information_elements && +nla_put (msg,NL80211_BSS_INFORMATION_ELEMENTS , + res->len_information_elements, + res->information_elements)) || + (res->beacon_ies && res->len_beacon_ies && + res->beacon_ies != res->information_elements && +nla_put (msg,NL80211_BSS_BEACON_IES , + res->len_beacon_ies, res->beacon_ies))) + goto nla_put_failure; +if (res->tsf && +nla_put_u64 (msg,NL80211_BSS_TSF , res->tsf)) + goto nla_put_failure; +if (res->beacon_interval && +nla_put_u16 (msg,NL80211_BSS_BEACON_INTERVAL , res->beacon_interval)) + goto nla_put_failure; +if (nla_put_u16 (msg,NL80211_BSS_CAPABILITY , res->capability) || +nla_put_u32 (msg,NL80211_BSS_FREQUENCY , res->channel->center_freq) || +nla_put_u32 (msg,NL80211_BSS_SEEN_MS_AGO , +jiffies_to_msecs (jiffies - intbss->ts))) + goto nla_put_failure;switch (rdev->wiphy.signal_type) {case CFG80211_SIGNAL_TYPE_MBM : -NLA_PUT_U32 (msg,NL80211_BSS_SIGNAL_MBM , res->signal); +if (nla_put_u32 (msg,NL80211_BSS_SIGNAL_MBM , res->signal)) + goto nla_put_failure;break ;case CFG80211_SIGNAL_TYPE_UNSPEC : -NLA_PUT_U8 (msg,NL80211_BSS_SIGNAL_UNSPEC , res->signal); +if (nla_put_u8 (msg,NL80211_BSS_SIGNAL_UNSPEC , res->signal)) + goto nla_put_failure;break ;default :break ;
@@ -4184,14 +4249,16 @@ static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,switch (wdev->iftype) {case NL80211_IFTYPE_P2P_CLIENT :case NL80211_IFTYPE_STATION : -if (intbss == wdev->current_bss) -NLA_PUT_U32 (msg,NL80211_BSS_STATUS , -NL80211_BSS_STATUS_ASSOCIATED ); +if (intbss == wdev->current_bss && +nla_put_u32 (msg,NL80211_BSS_STATUS , +NL80211_BSS_STATUS_ASSOCIATED )) + goto nla_put_failure;break ;case NL80211_IFTYPE_ADHOC : -if (intbss == wdev->current_bss) -NLA_PUT_U32 (msg,NL80211_BSS_STATUS , -NL80211_BSS_STATUS_IBSS_JOINED ); +if (intbss == wdev->current_bss && +nla_put_u32 (msg,NL80211_BSS_STATUS , +NL80211_BSS_STATUS_IBSS_JOINED )) + goto nla_put_failure;break ;default :break ;
@@ -4260,34 +4327,43 @@ static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,if (!hdr)return -ENOMEM ; -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , dev->ifindex); +if (nla_put_u32 (msg,NL80211_ATTR_IFINDEX , dev->ifindex)) + goto nla_put_failure; infoattr =nla_nest_start (msg,NL80211_ATTR_SURVEY_INFO );if (!infoattr) goto nla_put_failure; -NLA_PUT_U32 (msg,NL80211_SURVEY_INFO_FREQUENCY , - survey->channel->center_freq); -if (survey->filled &SURVEY_INFO_NOISE_DBM ) -NLA_PUT_U8 (msg,NL80211_SURVEY_INFO_NOISE , - survey->noise); -if (survey->filled &SURVEY_INFO_IN_USE ) -NLA_PUT_FLAG (msg,NL80211_SURVEY_INFO_IN_USE ); -if (survey->filled &SURVEY_INFO_CHANNEL_TIME ) -NLA_PUT_U64 (msg,NL80211_SURVEY_INFO_CHANNEL_TIME , - survey->channel_time); -if (survey->filled &SURVEY_INFO_CHANNEL_TIME_BUSY ) -NLA_PUT_U64 (msg,NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY , - survey->channel_time_busy); -if (survey->filled &SURVEY_INFO_CHANNEL_TIME_EXT_BUSY ) -NLA_PUT_U64 (msg,NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY , - survey->channel_time_ext_busy); -if (survey->filled &SURVEY_INFO_CHANNEL_TIME_RX ) -NLA_PUT_U64 (msg,NL80211_SURVEY_INFO_CHANNEL_TIME_RX , - survey->channel_time_rx); -if (survey->filled &SURVEY_INFO_CHANNEL_TIME_TX ) -NLA_PUT_U64 (msg,NL80211_SURVEY_INFO_CHANNEL_TIME_TX , - survey->channel_time_tx); +if (nla_put_u32 (msg,NL80211_SURVEY_INFO_FREQUENCY , + survey->channel->center_freq)) + goto nla_put_failure; + +if ((survey->filled &SURVEY_INFO_NOISE_DBM ) && +nla_put_u8 (msg,NL80211_SURVEY_INFO_NOISE , survey->noise)) + goto nla_put_failure; +if ((survey->filled &SURVEY_INFO_IN_USE ) && +nla_put_flag (msg,NL80211_SURVEY_INFO_IN_USE )) + goto nla_put_failure; +if ((survey->filled &SURVEY_INFO_CHANNEL_TIME ) && +nla_put_u64 (msg,NL80211_SURVEY_INFO_CHANNEL_TIME , + survey->channel_time)) + goto nla_put_failure; +if ((survey->filled &SURVEY_INFO_CHANNEL_TIME_BUSY ) && +nla_put_u64 (msg,NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY , + survey->channel_time_busy)) + goto nla_put_failure; +if ((survey->filled &SURVEY_INFO_CHANNEL_TIME_EXT_BUSY ) && +nla_put_u64 (msg,NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY , + survey->channel_time_ext_busy)) + goto nla_put_failure; +if ((survey->filled &SURVEY_INFO_CHANNEL_TIME_RX ) && +nla_put_u64 (msg,NL80211_SURVEY_INFO_CHANNEL_TIME_RX , + survey->channel_time_rx)) + goto nla_put_failure; +if ((survey->filled &SURVEY_INFO_CHANNEL_TIME_TX ) && +nla_put_u64 (msg,NL80211_SURVEY_INFO_CHANNEL_TIME_TX , + survey->channel_time_tx)) + goto nla_put_failure;nla_nest_end (msg, infoattr);
@@ -4968,7 +5044,7 @@ static int nl80211_testmode_dump(struct sk_buff *skb, NL80211_CMD_TESTMODE);struct nlattr *tmdata; -if (nla_put_u32 (skb,NL80211_ATTR_WIPHY , phy_idx) <0 ) { +if (nla_put_u32 (skb,NL80211_ATTR_WIPHY , phy_idx)) {genlmsg_cancel (skb, hdr);break ; }
@@ -5019,7 +5095,8 @@ __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,return NULL ; } -NLA_PUT_U32 (skb,NL80211_ATTR_WIPHY , rdev->wiphy_idx); +if (nla_put_u32 (skb,NL80211_ATTR_WIPHY , rdev->wiphy_idx)) + goto nla_put_failure; data =nla_nest_start (skb,NL80211_ATTR_TESTDATA ); ((void **)skb->cb)[0 ] = rdev;
@@ -5398,7 +5475,8 @@ static int nl80211_remain_on_channel(struct sk_buff *skb,if (err) goto free_msg; -NLA_PUT_U64 (msg,NL80211_ATTR_COOKIE , cookie); +if (nla_put_u64 (msg,NL80211_ATTR_COOKIE , cookie)) + goto nla_put_failure;genlmsg_end (msg, hdr);
@@ -5685,7 +5763,8 @@ static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) goto free_msg;if (msg) { -NLA_PUT_U64 (msg,NL80211_ATTR_COOKIE , cookie); +if (nla_put_u64 (msg,NL80211_ATTR_COOKIE , cookie)) + goto nla_put_failure;genlmsg_end (msg, hdr);return genlmsg_reply (msg, info);
@@ -5790,7 +5869,8 @@ static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)else ps_state =NL80211_PS_DISABLED ; -NLA_PUT_U32 (msg,NL80211_ATTR_PS_STATE , ps_state); +if (nla_put_u32 (msg,NL80211_ATTR_PS_STATE , ps_state)) + goto nla_put_failure;genlmsg_end (msg, hdr);return genlmsg_reply (msg, info);
@@ -5937,20 +6017,21 @@ static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)if (!nl_wowlan) goto nla_put_failure; -if (rdev->wowlan->any) -NLA_PUT_FLAG (msg,NL80211_WOWLAN_TRIG_ANY ); -if (rdev->wowlan->disconnect) -NLA_PUT_FLAG (msg,NL80211_WOWLAN_TRIG_DISCONNECT ); -if (rdev->wowlan->magic_pkt) -NLA_PUT_FLAG (msg,NL80211_WOWLAN_TRIG_MAGIC_PKT ); -if (rdev->wowlan->gtk_rekey_failure) -NLA_PUT_FLAG (msg,NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE ); -if (rdev->wowlan->eap_identity_req) -NLA_PUT_FLAG (msg,NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST ); -if (rdev->wowlan->four_way_handshake) -NLA_PUT_FLAG (msg,NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE ); -if (rdev->wowlan->rfkill_release) -NLA_PUT_FLAG (msg,NL80211_WOWLAN_TRIG_RFKILL_RELEASE ); +if ((rdev->wowlan->any && +nla_put_flag (msg,NL80211_WOWLAN_TRIG_ANY )) || + (rdev->wowlan->disconnect && +nla_put_flag (msg,NL80211_WOWLAN_TRIG_DISCONNECT )) || + (rdev->wowlan->magic_pkt && +nla_put_flag (msg,NL80211_WOWLAN_TRIG_MAGIC_PKT )) || + (rdev->wowlan->gtk_rekey_failure && +nla_put_flag (msg,NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE )) || + (rdev->wowlan->eap_identity_req && +nla_put_flag (msg,NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST )) || + (rdev->wowlan->four_way_handshake && +nla_put_flag (msg,NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE )) || + (rdev->wowlan->rfkill_release && +nla_put_flag (msg,NL80211_WOWLAN_TRIG_RFKILL_RELEASE ))) + goto nla_put_failure;if (rdev->wowlan->n_patterns) {struct nlattr *nl_pats, *nl_pat;int i, pat_len;
@@ -5965,12 +6046,13 @@ static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)if (!nl_pat) goto nla_put_failure; pat_len = rdev->wowlan->patterns[i].pattern_len; -NLA_PUT (msg,NL80211_WOWLAN_PKTPAT_MASK , -DIV_ROUND_UP (pat_len,8 ), - rdev->wowlan->patterns[i].mask); -NLA_PUT (msg,NL80211_WOWLAN_PKTPAT_PATTERN , - pat_len, - rdev->wowlan->patterns[i].pattern); +if (nla_put (msg,NL80211_WOWLAN_PKTPAT_MASK , +DIV_ROUND_UP (pat_len,8 ), + rdev->wowlan->patterns[i].mask) || +nla_put (msg,NL80211_WOWLAN_PKTPAT_PATTERN , + pat_len, + rdev->wowlan->patterns[i].pattern)) + goto nla_put_failure;nla_nest_end (msg, nl_pat); }nla_nest_end (msg, nl_pats);
@@ -6243,7 +6325,8 @@ static int nl80211_probe_client(struct sk_buff *skb,if (err) goto free_msg; -NLA_PUT_U64 (msg,NL80211_ATTR_COOKIE , cookie); +if (nla_put_u64 (msg,NL80211_ATTR_COOKIE , cookie)) + goto nla_put_failure;genlmsg_end (msg, hdr);
@@ -6911,19 +6994,24 @@ static int nl80211_add_scan_req(struct sk_buff *msg, nest =nla_nest_start (msg,NL80211_ATTR_SCAN_SSIDS );if (!nest) goto nla_put_failure; -for (i =0 ; i < req->n_ssids; i++) -NLA_PUT (msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); +for (i =0 ; i < req->n_ssids; i++) { +if (nla_put (msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) + goto nla_put_failure; + }nla_nest_end (msg, nest); nest =nla_nest_start (msg,NL80211_ATTR_SCAN_FREQUENCIES );if (!nest) goto nla_put_failure; -for (i =0 ; i < req->n_channels; i++) -NLA_PUT_U32 (msg, i, req->channels[i]->center_freq); +for (i =0 ; i < req->n_channels; i++) { +if (nla_put_u32 (msg, i, req->channels[i]->center_freq)) + goto nla_put_failure; + }nla_nest_end (msg, nest); -if (req->ie) -NLA_PUT (msg,NL80211_ATTR_IE , req->ie_len, req->ie); +if (req->ie && +nla_put (msg,NL80211_ATTR_IE , req->ie_len, req->ie)) + goto nla_put_failure;return 0 ; nla_put_failure:
@@ -6942,8 +7030,9 @@ static int nl80211_send_scan_msg(struct sk_buff *msg,if (!hdr)return -1 ; -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx); -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx) || +nla_put_u32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex)) + goto nla_put_failure;/* ignore errors and send incomplete event anyway */ nl80211_add_scan_req (msg, rdev);
@@ -6967,8 +7056,9 @@ nl80211_send_sched_scan_msg(struct sk_buff *msg,if (!hdr)return -1 ; -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx); -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx) || +nla_put_u32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex)) + goto nla_put_failure;return genlmsg_end (msg, hdr);
@@ -7091,26 +7181,33 @@ void nl80211_send_reg_change_event(struct regulatory_request *request) }/* Userspace can always count this one always being set */ -NLA_PUT_U8 (msg,NL80211_ATTR_REG_INITIATOR , request->initiator); - -if (request->alpha2[0 ] =='0' && request->alpha2[1 ] =='0' ) -NLA_PUT_U8 (msg,NL80211_ATTR_REG_TYPE , -NL80211_REGDOM_TYPE_WORLD ); -else if (request->alpha2[0 ] =='9' && request->alpha2[1 ] =='9' ) -NLA_PUT_U8 (msg,NL80211_ATTR_REG_TYPE , -NL80211_REGDOM_TYPE_CUSTOM_WORLD ); -else if ((request->alpha2[0 ] =='9' && request->alpha2[1 ] =='8' ) || - request->intersect) -NLA_PUT_U8 (msg,NL80211_ATTR_REG_TYPE , -NL80211_REGDOM_TYPE_INTERSECTION ); -else { -NLA_PUT_U8 (msg,NL80211_ATTR_REG_TYPE , -NL80211_REGDOM_TYPE_COUNTRY ); -NLA_PUT_STRING (msg,NL80211_ATTR_REG_ALPHA2 , request->alpha2); - } - -if (wiphy_idx_valid (request->wiphy_idx)) -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , request->wiphy_idx); +if (nla_put_u8 (msg,NL80211_ATTR_REG_INITIATOR , request->initiator)) + goto nla_put_failure; + +if (request->alpha2[0 ] =='0' && request->alpha2[1 ] =='0' ) { +if (nla_put_u8 (msg,NL80211_ATTR_REG_TYPE , +NL80211_REGDOM_TYPE_WORLD )) + goto nla_put_failure; + }else if (request->alpha2[0 ] =='9' && request->alpha2[1 ] =='9' ) { +if (nla_put_u8 (msg,NL80211_ATTR_REG_TYPE , +NL80211_REGDOM_TYPE_CUSTOM_WORLD )) + goto nla_put_failure; + }else if ((request->alpha2[0 ] =='9' && request->alpha2[1 ] =='8' ) || + request->intersect) { +if (nla_put_u8 (msg,NL80211_ATTR_REG_TYPE , +NL80211_REGDOM_TYPE_INTERSECTION )) + goto nla_put_failure; + }else { +if (nla_put_u8 (msg,NL80211_ATTR_REG_TYPE , +NL80211_REGDOM_TYPE_COUNTRY ) || +nla_put_string (msg,NL80211_ATTR_REG_ALPHA2 , + request->alpha2)) + goto nla_put_failure; + } + +if (wiphy_idx_valid (request->wiphy_idx) && +nla_put_u32 (msg,NL80211_ATTR_WIPHY , request->wiphy_idx)) + goto nla_put_failure;genlmsg_end (msg, hdr);
@@ -7144,9 +7241,10 @@ static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,return ; } -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx); -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex); -NLA_PUT (msg,NL80211_ATTR_FRAME , len, buf); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx) || +nla_put_u32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex) || +nla_put (msg,NL80211_ATTR_FRAME , len, buf)) + goto nla_put_failure;genlmsg_end (msg, hdr);
@@ -7224,10 +7322,11 @@ static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,return ; } -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx); -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex); -NLA_PUT_FLAG (msg,NL80211_ATTR_TIMED_OUT ); -NLA_PUT (msg,NL80211_ATTR_MAC ,ETH_ALEN , addr); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx) || +nla_put_u32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex) || +nla_put_flag (msg,NL80211_ATTR_TIMED_OUT ) || +nla_put (msg,NL80211_ATTR_MAC ,ETH_ALEN , addr)) + goto nla_put_failure;genlmsg_end (msg, hdr);
@@ -7275,15 +7374,15 @@ void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,return ; } -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx); -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex); -if (bssid) -NLA_PUT (msg,NL80211_ATTR_MAC ,ETH_ALEN , bssid); -NLA_PUT_U16 (msg,NL80211_ATTR_STATUS_CODE , status); -if (req_ie) -NLA_PUT (msg,NL80211_ATTR_REQ_IE , req_ie_len, req_ie); -if (resp_ie) -NLA_PUT (msg,NL80211_ATTR_RESP_IE , resp_ie_len, resp_ie); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx) || +nla_put_u32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex) || + (bssid &&nla_put (msg,NL80211_ATTR_MAC ,ETH_ALEN , bssid)) || +nla_put_u16 (msg,NL80211_ATTR_STATUS_CODE , status) || + (req_ie && +nla_put (msg,NL80211_ATTR_REQ_IE , req_ie_len, req_ie)) || + (resp_ie && +nla_put (msg,NL80211_ATTR_RESP_IE , resp_ie_len, resp_ie))) + goto nla_put_failure;genlmsg_end (msg, hdr);
@@ -7315,13 +7414,14 @@ void nl80211_send_roamed(struct cfg80211_registered_device *rdev,return ; } -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx); -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex); -NLA_PUT (msg,NL80211_ATTR_MAC ,ETH_ALEN , bssid); -if (req_ie) -NLA_PUT (msg,NL80211_ATTR_REQ_IE , req_ie_len, req_ie); -if (resp_ie) -NLA_PUT (msg,NL80211_ATTR_RESP_IE , resp_ie_len, resp_ie); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx) || +nla_put_u32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex) || +nla_put (msg,NL80211_ATTR_MAC ,ETH_ALEN , bssid) || + (req_ie && +nla_put (msg,NL80211_ATTR_REQ_IE , req_ie_len, req_ie)) || + (resp_ie && +nla_put (msg,NL80211_ATTR_RESP_IE , resp_ie_len, resp_ie))) + goto nla_put_failure;genlmsg_end (msg, hdr);
@@ -7352,14 +7452,14 @@ void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,return ; } -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx); -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex); -if (from_ap && reason) -NLA_PUT_U16 (msg,NL80211_ATTR_REASON_CODE , reason); -if (from_ap) -NLA_PUT_FLAG (msg,NL80211_ATTR_DISCONNECTED_BY_AP ); -if (ie) -NLA_PUT (msg,NL80211_ATTR_IE , ie_len, ie); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx) || +nla_put_u32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex) || + (from_ap && reason && +nla_put_u16 (msg,NL80211_ATTR_REASON_CODE , reason)) || + (from_ap && +nla_put_flag (msg,NL80211_ATTR_DISCONNECTED_BY_AP )) || + (ie &&nla_put (msg,NL80211_ATTR_IE , ie_len, ie))) + goto nla_put_failure;genlmsg_end (msg, hdr);
@@ -7390,9 +7490,10 @@ void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,return ; } -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx); -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex); -NLA_PUT (msg,NL80211_ATTR_MAC ,ETH_ALEN , bssid); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx) || +nla_put_u32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex) || +nla_put (msg,NL80211_ATTR_MAC ,ETH_ALEN , bssid)) + goto nla_put_failure;genlmsg_end (msg, hdr);
@@ -7423,11 +7524,12 @@ void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,return ; } -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx); -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex); -NLA_PUT (msg,NL80211_ATTR_MAC ,ETH_ALEN , macaddr); -if (ie_len && ie) -NLA_PUT (msg,NL80211_ATTR_IE , ie_len , ie); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx) || +nla_put_u32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex) || +nla_put (msg,NL80211_ATTR_MAC ,ETH_ALEN , macaddr) || + (ie_len && ie && +nla_put (msg,NL80211_ATTR_IE , ie_len , ie))) + goto nla_put_failure;genlmsg_end (msg, hdr);
@@ -7458,15 +7560,14 @@ void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,return ; } -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx); -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex); -if (addr) -NLA_PUT (msg,NL80211_ATTR_MAC ,ETH_ALEN , addr); -NLA_PUT_U32 (msg,NL80211_ATTR_KEY_TYPE , key_type); -if (key_id !=-1 ) -NLA_PUT_U8 (msg,NL80211_ATTR_KEY_IDX , key_id); -if (tsc) -NLA_PUT (msg,NL80211_ATTR_KEY_SEQ ,6 , tsc); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx) || +nla_put_u32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex) || + (addr &&nla_put (msg,NL80211_ATTR_MAC ,ETH_ALEN , addr)) || +nla_put_u32 (msg,NL80211_ATTR_KEY_TYPE , key_type) || + (key_id !=-1 && +nla_put_u8 (msg,NL80211_ATTR_KEY_IDX , key_id)) || + (tsc &&nla_put (msg,NL80211_ATTR_KEY_SEQ ,6 , tsc))) + goto nla_put_failure;genlmsg_end (msg, hdr);
@@ -7501,7 +7602,8 @@ void nl80211_send_beacon_hint_event(struct wiphy *wiphy,* Since we are applying the beacon hint to a wiphy we know its * wiphy_idx is valid */ -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY ,get_wiphy_idx (wiphy)); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY ,get_wiphy_idx (wiphy))) + goto nla_put_failure;/* Before */ nl_freq =nla_nest_start (msg,NL80211_ATTR_FREQ_BEFORE );
@@ -7553,14 +7655,16 @@ static void nl80211_send_remain_on_chan_event(return ; } -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx); -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex); -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY_FREQ , chan->center_freq); -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY_CHANNEL_TYPE , channel_type); -NLA_PUT_U64 (msg,NL80211_ATTR_COOKIE , cookie); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx) || +nla_put_u32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex) || +nla_put_u32 (msg,NL80211_ATTR_WIPHY_FREQ , chan->center_freq) || +nla_put_u32 (msg,NL80211_ATTR_WIPHY_CHANNEL_TYPE , channel_type) || +nla_put_u64 (msg,NL80211_ATTR_COOKIE , cookie)) + goto nla_put_failure; -if (cmd ==NL80211_CMD_REMAIN_ON_CHANNEL ) -NLA_PUT_U32 (msg,NL80211_ATTR_DURATION , duration); +if (cmd ==NL80211_CMD_REMAIN_ON_CHANNEL && +nla_put_u32 (msg,NL80211_ATTR_DURATION , duration)) + goto nla_put_failure;genlmsg_end (msg, hdr);
@@ -7631,8 +7735,9 @@ void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,return ; } -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , dev->ifindex); -NLA_PUT (msg,NL80211_ATTR_MAC ,ETH_ALEN , mac_addr); +if (nla_put_u32 (msg,NL80211_ATTR_IFINDEX , dev->ifindex) || +nla_put (msg,NL80211_ATTR_MAC ,ETH_ALEN , mac_addr)) + goto nla_put_failure;genlmsg_end (msg, hdr);
@@ -7668,9 +7773,10 @@ static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,return true; } -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx); -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , dev->ifindex); -NLA_PUT (msg,NL80211_ATTR_MAC ,ETH_ALEN , addr); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx) || +nla_put_u32 (msg,NL80211_ATTR_IFINDEX , dev->ifindex) || +nla_put (msg,NL80211_ATTR_MAC ,ETH_ALEN , addr)) + goto nla_put_failure; err =genlmsg_end (msg, hdr);if (err <0 ) {
@@ -7719,12 +7825,13 @@ int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,return -ENOMEM ; } -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx); -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex); -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY_FREQ , freq); -if (sig_dbm) -NLA_PUT_U32 (msg,NL80211_ATTR_RX_SIGNAL_DBM , sig_dbm); -NLA_PUT (msg,NL80211_ATTR_FRAME , len, buf); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx) || +nla_put_u32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex) || +nla_put_u32 (msg,NL80211_ATTR_WIPHY_FREQ , freq) || + (sig_dbm && +nla_put_u32 (msg,NL80211_ATTR_RX_SIGNAL_DBM , sig_dbm)) || +nla_put (msg,NL80211_ATTR_FRAME , len, buf)) + goto nla_put_failure;genlmsg_end (msg, hdr);
@@ -7754,12 +7861,12 @@ void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,return ; } -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx); -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex); -NLA_PUT (msg,NL80211_ATTR_FRAME , len, buf); -NLA_PUT_U64 (msg,NL80211_ATTR_COOKIE , cookie); -if (ack) -NLA_PUT_FLAG (msg,NL80211_ATTR_ACK ); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx) || +nla_put_u32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex) || +nla_put (msg,NL80211_ATTR_FRAME , len, buf) || +nla_put_u64 (msg,NL80211_ATTR_COOKIE , cookie) || + (ack &&nla_put_flag (msg,NL80211_ATTR_ACK ))) + goto nla_put_failure;genlmsg_end (msg, hdr);
@@ -7791,15 +7898,17 @@ nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,return ; } -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx); -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx) || +nla_put_u32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex)) + goto nla_put_failure; pinfoattr =nla_nest_start (msg,NL80211_ATTR_CQM );if (!pinfoattr) goto nla_put_failure; -NLA_PUT_U32 (msg,NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT , - rssi_event); +if (nla_put_u32 (msg,NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT , + rssi_event)) + goto nla_put_failure;nla_nest_end (msg, pinfoattr);
@@ -7832,16 +7941,18 @@ void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,return ; } -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx); -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex); -NLA_PUT (msg,NL80211_ATTR_MAC ,ETH_ALEN , bssid); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx) || +nla_put_u32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex) || +nla_put (msg,NL80211_ATTR_MAC ,ETH_ALEN , bssid)) + goto nla_put_failure; rekey_attr =nla_nest_start (msg,NL80211_ATTR_REKEY_DATA );if (!rekey_attr) goto nla_put_failure; -NLA_PUT (msg,NL80211_REKEY_DATA_REPLAY_CTR , -NL80211_REPLAY_CTR_LEN , replay_ctr); +if (nla_put (msg,NL80211_REKEY_DATA_REPLAY_CTR , +NL80211_REPLAY_CTR_LEN , replay_ctr)) + goto nla_put_failure;nla_nest_end (msg, rekey_attr);
@@ -7874,17 +7985,19 @@ void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,return ; } -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx); -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx) || +nla_put_u32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex)) + goto nla_put_failure; attr =nla_nest_start (msg,NL80211_ATTR_PMKSA_CANDIDATE );if (!attr) goto nla_put_failure; -NLA_PUT_U32 (msg,NL80211_PMKSA_CANDIDATE_INDEX , index); -NLA_PUT (msg,NL80211_PMKSA_CANDIDATE_BSSID ,ETH_ALEN , bssid); -if (preauth) -NLA_PUT_FLAG (msg,NL80211_PMKSA_CANDIDATE_PREAUTH ); +if (nla_put_u32 (msg,NL80211_PMKSA_CANDIDATE_INDEX , index) || +nla_put (msg,NL80211_PMKSA_CANDIDATE_BSSID ,ETH_ALEN , bssid) || + (preauth && +nla_put_flag (msg,NL80211_PMKSA_CANDIDATE_PREAUTH ))) + goto nla_put_failure;nla_nest_end (msg, attr);
@@ -7918,15 +8031,17 @@ nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,return ; } -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx); -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex); -NLA_PUT (msg,NL80211_ATTR_MAC ,ETH_ALEN , peer); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx) || +nla_put_u32 (msg,NL80211_ATTR_IFINDEX , netdev->ifindex) || +nla_put (msg,NL80211_ATTR_MAC ,ETH_ALEN , peer)) + goto nla_put_failure; pinfoattr =nla_nest_start (msg,NL80211_ATTR_CQM );if (!pinfoattr) goto nla_put_failure; -NLA_PUT_U32 (msg,NL80211_ATTR_CQM_PKT_LOSS_EVENT , num_packets); +if (nla_put_u32 (msg,NL80211_ATTR_CQM_PKT_LOSS_EVENT , num_packets)) + goto nla_put_failure;nla_nest_end (msg, pinfoattr);
@@ -7960,12 +8075,12 @@ void cfg80211_probe_status(struct net_device *dev, const u8 *addr,return ; } -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx); -NLA_PUT_U32 (msg,NL80211_ATTR_IFINDEX , dev->ifindex); -NLA_PUT (msg,NL80211_ATTR_MAC ,ETH_ALEN , addr); -NLA_PUT_U64 (msg,NL80211_ATTR_COOKIE , cookie); -if (acked) -NLA_PUT_FLAG (msg,NL80211_ATTR_ACK ); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx) || +nla_put_u32 (msg,NL80211_ATTR_IFINDEX , dev->ifindex) || +nla_put (msg,NL80211_ATTR_MAC ,ETH_ALEN , addr) || +nla_put_u64 (msg,NL80211_ATTR_COOKIE , cookie) || + (acked &&nla_put_flag (msg,NL80211_ATTR_ACK ))) + goto nla_put_failure; err =genlmsg_end (msg, hdr);if (err <0 ) {
@@ -8005,12 +8120,13 @@ void cfg80211_report_obss_beacon(struct wiphy *wiphy,return ; } -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx); -if (freq) -NLA_PUT_U32 (msg,NL80211_ATTR_WIPHY_FREQ , freq); -if (sig_dbm) -NLA_PUT_U32 (msg,NL80211_ATTR_RX_SIGNAL_DBM , sig_dbm); -NLA_PUT (msg,NL80211_ATTR_FRAME , len, frame); +if (nla_put_u32 (msg,NL80211_ATTR_WIPHY , rdev->wiphy_idx) || + (freq && +nla_put_u32 (msg,NL80211_ATTR_WIPHY_FREQ , freq)) || + (sig_dbm && +nla_put_u32 (msg,NL80211_ATTR_RX_SIGNAL_DBM , sig_dbm)) || +nla_put (msg,NL80211_ATTR_FRAME , len, frame)) + goto nla_put_failure;genlmsg_end (msg, hdr);
net/wireless/wext-core.c +2 -1
@@ -402,7 +402,8 @@ static struct nlmsghdr *rtnetlink_ifinfo_prep(struct net_device *dev, r->ifi_flags =dev_get_flags (dev); r->ifi_change =0 ;/* Wireless changes don't affect those flags */ -NLA_PUT_STRING (skb,IFLA_IFNAME , dev->name); +if (nla_put_string (skb,IFLA_IFNAME , dev->name)) + goto nla_put_failure;return nlh; nla_put_failure:
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 3/51 pkt_sched: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/sched/act_api.c | 9 ++++++--- net/sched/act_csum.c | 6 ++++-- net/sched/act_gact.c | 9 ++++++--- net/sched/act_ipt.c | 14 ++++++++------ net/sched/act_mirred.c | 6 ++++-- net/sched/act_nat.c | 6 ++++-- net/sched/act_pedit.c | 6 ++++-- net/sched/act_police.c | 13 ++++++++----- net/sched/act_simple.c | 8 +++++--- net/sched/act_skbedit.c | 27 ++++++++++++++++----------- net/sched/cls_api.c | 3 ++- net/sched/cls_basic.c | 5 +++-- net/sched/cls_flow.c | 35 +++++++++++++++++++++-------------- net/sched/cls_fw.c | 15 +++++++++------ net/sched/cls_route.c | 16 ++++++++++------ net/sched/cls_rsvp.h | 16 ++++++++++------ net/sched/cls_tcindex.c | 14 ++++++++------ net/sched/cls_u32.c | 40 ++++++++++++++++++++++++---------------- net/sched/em_meta.c | 19 ++++++++++++------- net/sched/ematch.c | 6 ++++-- net/sched/sch_api.c | 9 ++++++--- net/sched/sch_atm.c | 21 +++++++++++++-------- net/sched/sch_cbq.c | 18 ++++++++++++------ net/sched/sch_choke.c | 5 +++-- net/sched/sch_drr.c | 3 ++- net/sched/sch_dsmark.c | 18 +++++++++++------- net/sched/sch_fifo.c | 3 ++- net/sched/sch_generic.c | 3 ++- net/sched/sch_gred.c | 6 ++++-- net/sched/sch_hfsc.c | 6 ++++-- net/sched/sch_htb.c | 6 ++++-- net/sched/sch_mqprio.c | 3 ++- net/sched/sch_multiq.c | 3 ++- net/sched/sch_netem.c | 21 ++++++++++++++------- net/sched/sch_prio.c | 3 ++- net/sched/sch_qfq.c | 5 +++-- net/sched/sch_red.c | 5 +++-- net/sched/sch_sfb.c | 3 ++- net/sched/sch_sfq.c | 3 ++- net/sched/sch_tbf.c | 3 ++- 40 files changed, 263 insertions(+), 157 deletions(-)
net/sched/act_api.c +6 -3
@@ -127,7 +127,8 @@ static int tcf_del_walker(struct sk_buff *skb, struct tc_action *a, nest =nla_nest_start (skb, a->order);if (nest ==NULL ) goto nla_put_failure; -NLA_PUT_STRING (skb,TCA_KIND , a->ops->kind); +if (nla_put_string (skb,TCA_KIND , a->ops->kind)) + goto nla_put_failure;for (i =0 ; i < (hinfo->hmask +1 ); i++) { p = hinfo->htab[tcf_hash (i, hinfo->hmask)];
@@ -139,7 +140,8 @@ static int tcf_del_walker(struct sk_buff *skb, struct tc_action *a, p = s_p; } } -NLA_PUT_U32 (skb,TCA_FCNT , n_i); +if (nla_put_u32 (skb,TCA_FCNT , n_i)) + goto nla_put_failure;nla_nest_end (skb, nest);return n_i;
@@ -437,7 +439,8 @@ tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int bind, int ref)if (a->ops ==NULL || a->ops->dump ==NULL )return err; -NLA_PUT_STRING (skb,TCA_KIND , a->ops->kind); +if (nla_put_string (skb,TCA_KIND , a->ops->kind)) + goto nla_put_failure;if (tcf_action_copy_stats (skb, a,0 )) goto nla_put_failure; nest =nla_nest_start (skb,TCA_OPTIONS );
net/sched/act_csum.c +4 -2
@@ -550,11 +550,13 @@ static int tcf_csum_dump(struct sk_buff *skb, };struct tcf_t t; -NLA_PUT (skb,TCA_CSUM_PARMS ,sizeof (opt), &opt); +if (nla_put (skb,TCA_CSUM_PARMS ,sizeof (opt), &opt)) + goto nla_put_failure; t.install =jiffies_to_clock_t (jiffies - p->tcf_tm.install); t.lastuse =jiffies_to_clock_t (jiffies - p->tcf_tm.lastuse); t.expires =jiffies_to_clock_t (p->tcf_tm.expires); -NLA_PUT (skb,TCA_CSUM_TM ,sizeof (t), &t); +if (nla_put (skb,TCA_CSUM_TM ,sizeof (t), &t)) + goto nla_put_failure;return skb->len;
net/sched/act_gact.c +6 -3
@@ -162,7 +162,8 @@ static int tcf_gact_dump(struct sk_buff *skb, struct tc_action *a, int bind, int };struct tcf_t t; -NLA_PUT (skb,TCA_GACT_PARMS ,sizeof (opt), &opt); +if (nla_put (skb,TCA_GACT_PARMS ,sizeof (opt), &opt)) + goto nla_put_failure; #ifdef CONFIG_GACT_PROB if (gact->tcfg_ptype) { struct tc_gact_p p_opt = {
@@ -171,13 +172,15 @@ static int tcf_gact_dump(struct sk_buff *skb, struct tc_action *a, int bind, int .ptype = gact->tcfg_ptype, }; -NLA_PUT (skb,TCA_GACT_PROB ,sizeof (p_opt), &p_opt); +if (nla_put (skb,TCA_GACT_PROB ,sizeof (p_opt), &p_opt)) + goto nla_put_failure; }#endif t.install =jiffies_to_clock_t (jiffies - gact->tcf_tm.install); t.lastuse =jiffies_to_clock_t (jiffies - gact->tcf_tm.lastuse); t.expires =jiffies_to_clock_t (gact->tcf_tm.expires); -NLA_PUT (skb,TCA_GACT_TM ,sizeof (t), &t); +if (nla_put (skb,TCA_GACT_TM ,sizeof (t), &t)) + goto nla_put_failure;return skb->len; nla_put_failure:
net/sched/act_ipt.c +8 -6
@@ -267,15 +267,17 @@ static int tcf_ipt_dump(struct sk_buff *skb, struct tc_action *a, int bind, int c.refcnt = ipt->tcf_refcnt - ref;strcpy (t->u.user.name, ipt->tcfi_t->u.kernel.target->name); -NLA_PUT (skb,TCA_IPT_TARG , ipt->tcfi_t->u.user.target_size, t); -NLA_PUT_U32 (skb,TCA_IPT_INDEX , ipt->tcf_index); -NLA_PUT_U32 (skb,TCA_IPT_HOOK , ipt->tcfi_hook); -NLA_PUT (skb,TCA_IPT_CNT ,sizeof (struct tc_cnt ), &c); -NLA_PUT_STRING (skb,TCA_IPT_TABLE , ipt->tcfi_tname); +if (nla_put (skb,TCA_IPT_TARG , ipt->tcfi_t->u.user.target_size, t) || +nla_put_u32 (skb,TCA_IPT_INDEX , ipt->tcf_index) || +nla_put_u32 (skb,TCA_IPT_HOOK , ipt->tcfi_hook) || +nla_put (skb,TCA_IPT_CNT ,sizeof (struct tc_cnt ), &c) || +nla_put_string (skb,TCA_IPT_TABLE , ipt->tcfi_tname)) + goto nla_put_failure; tm.install =jiffies_to_clock_t (jiffies - ipt->tcf_tm.install); tm.lastuse =jiffies_to_clock_t (jiffies - ipt->tcf_tm.lastuse); tm.expires =jiffies_to_clock_t (ipt->tcf_tm.expires); -NLA_PUT (skb,TCA_IPT_TM ,sizeof (tm), &tm); +if (nla_put (skb,TCA_IPT_TM ,sizeof (tm), &tm)) + goto nla_put_failure;kfree (t);return skb->len;
net/sched/act_mirred.c +4 -2
@@ -227,11 +227,13 @@ static int tcf_mirred_dump(struct sk_buff *skb, struct tc_action *a, int bind, i };struct tcf_t t; -NLA_PUT (skb,TCA_MIRRED_PARMS ,sizeof (opt), &opt); +if (nla_put (skb,TCA_MIRRED_PARMS ,sizeof (opt), &opt)) + goto nla_put_failure; t.install =jiffies_to_clock_t (jiffies - m->tcf_tm.install); t.lastuse =jiffies_to_clock_t (jiffies - m->tcf_tm.lastuse); t.expires =jiffies_to_clock_t (m->tcf_tm.expires); -NLA_PUT (skb,TCA_MIRRED_TM ,sizeof (t), &t); +if (nla_put (skb,TCA_MIRRED_TM ,sizeof (t), &t)) + goto nla_put_failure;return skb->len; nla_put_failure:
net/sched/act_nat.c +4 -2
@@ -284,11 +284,13 @@ static int tcf_nat_dump(struct sk_buff *skb, struct tc_action *a, };struct tcf_t t; -NLA_PUT (skb,TCA_NAT_PARMS ,sizeof (opt), &opt); +if (nla_put (skb,TCA_NAT_PARMS ,sizeof (opt), &opt)) + goto nla_put_failure; t.install =jiffies_to_clock_t (jiffies - p->tcf_tm.install); t.lastuse =jiffies_to_clock_t (jiffies - p->tcf_tm.lastuse); t.expires =jiffies_to_clock_t (p->tcf_tm.expires); -NLA_PUT (skb,TCA_NAT_TM ,sizeof (t), &t); +if (nla_put (skb,TCA_NAT_TM ,sizeof (t), &t)) + goto nla_put_failure;return skb->len;
net/sched/act_pedit.c +4 -2
@@ -215,11 +215,13 @@ static int tcf_pedit_dump(struct sk_buff *skb, struct tc_action *a, opt->refcnt = p->tcf_refcnt - ref; opt->bindcnt = p->tcf_bindcnt - bind; -NLA_PUT (skb,TCA_PEDIT_PARMS , s, opt); +if (nla_put (skb,TCA_PEDIT_PARMS , s, opt)) + goto nla_put_failure; t.install =jiffies_to_clock_t (jiffies - p->tcf_tm.install); t.lastuse =jiffies_to_clock_t (jiffies - p->tcf_tm.lastuse); t.expires =jiffies_to_clock_t (p->tcf_tm.expires); -NLA_PUT (skb,TCA_PEDIT_TM ,sizeof (t), &t); +if (nla_put (skb,TCA_PEDIT_TM ,sizeof (t), &t)) + goto nla_put_failure;kfree (opt);return skb->len;
net/sched/act_police.c +8 -5
@@ -356,11 +356,14 @@ tcf_act_police_dump(struct sk_buff *skb, struct tc_action *a, int bind, int ref) opt.rate = police->tcfp_R_tab->rate;if (police->tcfp_P_tab) opt.peakrate = police->tcfp_P_tab->rate; -NLA_PUT (skb,TCA_POLICE_TBF ,sizeof (opt), &opt); -if (police->tcfp_result) -NLA_PUT_U32 (skb,TCA_POLICE_RESULT , police->tcfp_result); -if (police->tcfp_ewma_rate) -NLA_PUT_U32 (skb,TCA_POLICE_AVRATE , police->tcfp_ewma_rate); +if (nla_put (skb,TCA_POLICE_TBF ,sizeof (opt), &opt)) + goto nla_put_failure; +if (police->tcfp_result && +nla_put_u32 (skb,TCA_POLICE_RESULT , police->tcfp_result)) + goto nla_put_failure; +if (police->tcfp_ewma_rate && +nla_put_u32 (skb,TCA_POLICE_AVRATE , police->tcfp_ewma_rate)) + goto nla_put_failure;return skb->len; nla_put_failure:
net/sched/act_simple.c +5 -3
@@ -172,12 +172,14 @@ static int tcf_simp_dump(struct sk_buff *skb, struct tc_action *a, };struct tcf_t t; -NLA_PUT (skb,TCA_DEF_PARMS ,sizeof (opt), &opt); -NLA_PUT_STRING (skb,TCA_DEF_DATA , d->tcfd_defdata); +if (nla_put (skb,TCA_DEF_PARMS ,sizeof (opt), &opt) || +nla_put_string (skb,TCA_DEF_DATA , d->tcfd_defdata)) + goto nla_put_failure; t.install =jiffies_to_clock_t (jiffies - d->tcf_tm.install); t.lastuse =jiffies_to_clock_t (jiffies - d->tcf_tm.lastuse); t.expires =jiffies_to_clock_t (d->tcf_tm.expires); -NLA_PUT (skb,TCA_DEF_TM ,sizeof (t), &t); +if (nla_put (skb,TCA_DEF_TM ,sizeof (t), &t)) + goto nla_put_failure;return skb->len; nla_put_failure:
net/sched/act_skbedit.c +16 -11
@@ -166,20 +166,25 @@ static int tcf_skbedit_dump(struct sk_buff *skb, struct tc_action *a, };struct tcf_t t; -NLA_PUT (skb,TCA_SKBEDIT_PARMS ,sizeof (opt), &opt); -if (d->flags &SKBEDIT_F_PRIORITY ) -NLA_PUT (skb,TCA_SKBEDIT_PRIORITY ,sizeof (d->priority), - &d->priority); -if (d->flags &SKBEDIT_F_QUEUE_MAPPING ) -NLA_PUT (skb,TCA_SKBEDIT_QUEUE_MAPPING , -sizeof (d->queue_mapping), &d->queue_mapping); -if (d->flags &SKBEDIT_F_MARK ) -NLA_PUT (skb,TCA_SKBEDIT_MARK ,sizeof (d->mark), - &d->mark); +if (nla_put (skb,TCA_SKBEDIT_PARMS ,sizeof (opt), &opt)) + goto nla_put_failure; +if ((d->flags &SKBEDIT_F_PRIORITY ) && +nla_put (skb,TCA_SKBEDIT_PRIORITY ,sizeof (d->priority), + &d->priority)) + goto nla_put_failure; +if ((d->flags &SKBEDIT_F_QUEUE_MAPPING ) && +nla_put (skb,TCA_SKBEDIT_QUEUE_MAPPING , +sizeof (d->queue_mapping), &d->queue_mapping)) + goto nla_put_failure; +if ((d->flags &SKBEDIT_F_MARK ) && +nla_put (skb,TCA_SKBEDIT_MARK ,sizeof (d->mark), + &d->mark)) + goto nla_put_failure; t.install =jiffies_to_clock_t (jiffies - d->tcf_tm.install); t.lastuse =jiffies_to_clock_t (jiffies - d->tcf_tm.lastuse); t.expires =jiffies_to_clock_t (d->tcf_tm.expires); -NLA_PUT (skb,TCA_SKBEDIT_TM ,sizeof (t), &t); +if (nla_put (skb,TCA_SKBEDIT_TM ,sizeof (t), &t)) + goto nla_put_failure;return skb->len; nla_put_failure:
net/sched/cls_api.c +2 -1
@@ -357,7 +357,8 @@ static int tcf_fill_node(struct sk_buff *skb, struct tcf_proto *tp, tcm->tcm_ifindex =qdisc_dev (tp->q)->ifindex; tcm->tcm_parent = tp->classid; tcm->tcm_info =TC_H_MAKE (tp->prio, tp->protocol); -NLA_PUT_STRING (skb,TCA_KIND , tp->ops->kind); +if (nla_put_string (skb,TCA_KIND , tp->ops->kind)) + goto nla_put_failure; tcm->tcm_handle = fh;if (RTM_DELTFILTER != event) { tcm->tcm_handle =0 ;
net/sched/cls_basic.c +3 -2
@@ -257,8 +257,9 @@ static int basic_dump(struct tcf_proto *tp, unsigned long fh,if (nest ==NULL ) goto nla_put_failure; -if (f->res.classid) -NLA_PUT_U32 (skb,TCA_BASIC_CLASSID , f->res.classid); +if (f->res.classid && +nla_put_u32 (skb,TCA_BASIC_CLASSID , f->res.classid)) + goto nla_put_failure;if (tcf_exts_dump (skb, &f->exts, &basic_ext_map) <0 ||tcf_em_tree_dump (skb, &f->ematches,TCA_BASIC_EMATCHES ) <0 )
net/sched/cls_flow.c +21 -14
@@ -572,25 +572,32 @@ static int flow_dump(struct tcf_proto *tp, unsigned long fh,if (nest ==NULL ) goto nla_put_failure; -NLA_PUT_U32 (skb,TCA_FLOW_KEYS , f->keymask); -NLA_PUT_U32 (skb,TCA_FLOW_MODE , f->mode); +if (nla_put_u32 (skb,TCA_FLOW_KEYS , f->keymask) || +nla_put_u32 (skb,TCA_FLOW_MODE , f->mode)) + goto nla_put_failure;if (f->mask != ~0 || f->xor !=0 ) { -NLA_PUT_U32 (skb,TCA_FLOW_MASK , f->mask); -NLA_PUT_U32 (skb,TCA_FLOW_XOR , f->xor); +if (nla_put_u32 (skb,TCA_FLOW_MASK , f->mask) || +nla_put_u32 (skb,TCA_FLOW_XOR , f->xor)) + goto nla_put_failure; } -if (f->rshift) -NLA_PUT_U32 (skb,TCA_FLOW_RSHIFT , f->rshift); -if (f->addend) -NLA_PUT_U32 (skb,TCA_FLOW_ADDEND , f->addend); +if (f->rshift && +nla_put_u32 (skb,TCA_FLOW_RSHIFT , f->rshift)) + goto nla_put_failure; +if (f->addend && +nla_put_u32 (skb,TCA_FLOW_ADDEND , f->addend)) + goto nla_put_failure; -if (f->divisor) -NLA_PUT_U32 (skb,TCA_FLOW_DIVISOR , f->divisor); -if (f->baseclass) -NLA_PUT_U32 (skb,TCA_FLOW_BASECLASS , f->baseclass); +if (f->divisor && +nla_put_u32 (skb,TCA_FLOW_DIVISOR , f->divisor)) + goto nla_put_failure; +if (f->baseclass && +nla_put_u32 (skb,TCA_FLOW_BASECLASS , f->baseclass)) + goto nla_put_failure; -if (f->perturb_period) -NLA_PUT_U32 (skb,TCA_FLOW_PERTURB , f->perturb_period /HZ ); +if (f->perturb_period && +nla_put_u32 (skb,TCA_FLOW_PERTURB , f->perturb_period /HZ )) + goto nla_put_failure;if (tcf_exts_dump (skb, &f->exts, &flow_ext_map) <0 ) goto nla_put_failure;
net/sched/cls_fw.c +9 -6
@@ -346,14 +346,17 @@ static int fw_dump(struct tcf_proto *tp, unsigned long fh,if (nest ==NULL ) goto nla_put_failure; -if (f->res.classid) -NLA_PUT_U32 (skb,TCA_FW_CLASSID , f->res.classid); +if (f->res.classid && +nla_put_u32 (skb,TCA_FW_CLASSID , f->res.classid)) + goto nla_put_failure;#ifdef CONFIG_NET_CLS_IND -if (strlen (f->indev)) -NLA_PUT_STRING (skb,TCA_FW_INDEV , f->indev); +if (strlen (f->indev) && +nla_put_string (skb,TCA_FW_INDEV , f->indev)) + goto nla_put_failure;#endif /* CONFIG_NET_CLS_IND */ -if (head->mask !=0xFFFFFFFF ) -NLA_PUT_U32 (skb,TCA_FW_MASK , head->mask); +if (head->mask !=0xFFFFFFFF && +nla_put_u32 (skb,TCA_FW_MASK , head->mask)) + goto nla_put_failure;if (tcf_exts_dump (skb, &f->exts, &fw_ext_map) <0 ) goto nla_put_failure;
net/sched/cls_route.c +10 -6
@@ -571,17 +571,21 @@ static int route4_dump(struct tcf_proto *tp, unsigned long fh,if (!(f->handle &0x8000 )) { id = f->id &0xFF ; -NLA_PUT_U32 (skb,TCA_ROUTE4_TO , id); +if (nla_put_u32 (skb,TCA_ROUTE4_TO , id)) + goto nla_put_failure; }if (f->handle &0x80000000 ) { -if ((f->handle >>16 ) !=0xFFFF ) -NLA_PUT_U32 (skb,TCA_ROUTE4_IIF , f->iif); +if ((f->handle >>16 ) !=0xFFFF && +nla_put_u32 (skb,TCA_ROUTE4_IIF , f->iif)) + goto nla_put_failure; }else { id = f->id >>16 ; -NLA_PUT_U32 (skb,TCA_ROUTE4_FROM , id); +if (nla_put_u32 (skb,TCA_ROUTE4_FROM , id)) + goto nla_put_failure; } -if (f->res.classid) -NLA_PUT_U32 (skb,TCA_ROUTE4_CLASSID , f->res.classid); +if (f->res.classid && +nla_put_u32 (skb,TCA_ROUTE4_CLASSID , f->res.classid)) + goto nla_put_failure;if (tcf_exts_dump (skb, &f->exts, &route_ext_map) <0 ) goto nla_put_failure;
net/sched/cls_rsvp.h +10 -6
@@ -615,18 +615,22 @@ static int rsvp_dump(struct tcf_proto *tp, unsigned long fh,if (nest ==NULL ) goto nla_put_failure; -NLA_PUT (skb,TCA_RSVP_DST ,sizeof (s->dst), &s->dst); +if (nla_put (skb,TCA_RSVP_DST ,sizeof (s->dst), &s->dst)) + goto nla_put_failure; pinfo.dpi = s->dpi; pinfo.spi = f->spi; pinfo.protocol = s->protocol; pinfo.tunnelid = s->tunnelid; pinfo.tunnelhdr = f->tunnelhdr; pinfo.pad =0 ; -NLA_PUT (skb,TCA_RSVP_PINFO ,sizeof (pinfo), &pinfo); -if (f->res.classid) -NLA_PUT_U32 (skb,TCA_RSVP_CLASSID , f->res.classid); -if (((f->handle >>8 ) &0xFF ) !=16 ) -NLA_PUT (skb,TCA_RSVP_SRC ,sizeof (f->src), f->src); +if (nla_put (skb,TCA_RSVP_PINFO ,sizeof (pinfo), &pinfo)) + goto nla_put_failure; +if (f->res.classid && +nla_put_u32 (skb,TCA_RSVP_CLASSID , f->res.classid)) + goto nla_put_failure; +if (((f->handle >>8 ) &0xFF ) !=16 && +nla_put (skb,TCA_RSVP_SRC ,sizeof (f->src), f->src)) + goto nla_put_failure;if (tcf_exts_dump (skb, &f->exts, &rsvp_ext_map) <0 ) goto nla_put_failure;
net/sched/cls_tcindex.c +8 -6
@@ -438,10 +438,11 @@ static int tcindex_dump(struct tcf_proto *tp, unsigned long fh,if (!fh) { t->tcm_handle = ~0 ;/* whatever ... */ -NLA_PUT_U32 (skb,TCA_TCINDEX_HASH , p->hash); -NLA_PUT_U16 (skb,TCA_TCINDEX_MASK , p->mask); -NLA_PUT_U32 (skb,TCA_TCINDEX_SHIFT , p->shift); -NLA_PUT_U32 (skb,TCA_TCINDEX_FALL_THROUGH , p->fall_through); +if (nla_put_u32 (skb,TCA_TCINDEX_HASH , p->hash) || +nla_put_u16 (skb,TCA_TCINDEX_MASK , p->mask) || +nla_put_u32 (skb,TCA_TCINDEX_SHIFT , p->shift) || +nla_put_u32 (skb,TCA_TCINDEX_FALL_THROUGH , p->fall_through)) + goto nla_put_failure;nla_nest_end (skb, nest); }else {if (p->perfect) {
@@ -460,8 +461,9 @@ static int tcindex_dump(struct tcf_proto *tp, unsigned long fh, } }pr_debug ("handle = %d\n" , t->tcm_handle); -if (r->res.class) -NLA_PUT_U32 (skb,TCA_TCINDEX_CLASSID , r->res.classid); +if (r->res.class && +nla_put_u32 (skb,TCA_TCINDEX_CLASSID , r->res.classid)) + goto nla_put_failure;if (tcf_exts_dump (skb, &r->exts, &tcindex_ext_map) <0 ) goto nla_put_failure;
net/sched/cls_u32.c +24 -16
@@ -733,36 +733,44 @@ static int u32_dump(struct tcf_proto *tp, unsigned long fh,struct tc_u_hnode *ht = (struct tc_u_hnode *)fh;u32 divisor = ht->divisor +1 ; -NLA_PUT_U32 (skb,TCA_U32_DIVISOR , divisor); +if (nla_put_u32 (skb,TCA_U32_DIVISOR , divisor)) + goto nla_put_failure; }else { -NLA_PUT (skb,TCA_U32_SEL , -sizeof (n->sel) + n->sel.nkeys*sizeof (struct tc_u32_key ), - &n->sel); +if (nla_put (skb,TCA_U32_SEL , +sizeof (n->sel) + n->sel.nkeys*sizeof (struct tc_u32_key ), + &n->sel)) + goto nla_put_failure;if (n->ht_up) {u32 htid = n->handle &0xFFFFF000 ; -NLA_PUT_U32 (skb,TCA_U32_HASH , htid); +if (nla_put_u32 (skb,TCA_U32_HASH , htid)) + goto nla_put_failure; } -if (n->res.classid) -NLA_PUT_U32 (skb,TCA_U32_CLASSID , n->res.classid); -if (n->ht_down) -NLA_PUT_U32 (skb,TCA_U32_LINK , n->ht_down->handle); +if (n->res.classid && +nla_put_u32 (skb,TCA_U32_CLASSID , n->res.classid)) + goto nla_put_failure; +if (n->ht_down && +nla_put_u32 (skb,TCA_U32_LINK , n->ht_down->handle)) + goto nla_put_failure;#ifdef CONFIG_CLS_U32_MARK -if (n->mark.val || n->mark.mask) -NLA_PUT (skb,TCA_U32_MARK ,sizeof (n->mark), &n->mark); +if ((n->mark.val || n->mark.mask) && +nla_put (skb,TCA_U32_MARK ,sizeof (n->mark), &n->mark)) + goto nla_put_failure;#endif if (tcf_exts_dump (skb, &n->exts, &u32_ext_map) <0 ) goto nla_put_failure;#ifdef CONFIG_NET_CLS_IND -if (strlen (n->indev)) -NLA_PUT_STRING (skb,TCA_U32_INDEV , n->indev); +if (strlen (n->indev) && +nla_put_string (skb,TCA_U32_INDEV , n->indev)) + goto nla_put_failure;#endif #ifdef CONFIG_CLS_U32_PERF -NLA_PUT (skb,TCA_U32_PCNT , -sizeof (struct tc_u32_pcnt ) + n->sel.nkeys*sizeof (u64), - n->pf); +if (nla_put (skb,TCA_U32_PCNT , +sizeof (struct tc_u32_pcnt ) + n->sel.nkeys*sizeof (u64), + n->pf)) + goto nla_put_failure;#endif }
net/sched/em_meta.c +12 -7
@@ -585,8 +585,9 @@ static void meta_var_apply_extras(struct meta_value *v,static int meta_var_dump (struct sk_buff *skb,struct meta_value *v,int tlv) { -if (v->val && v->len) -NLA_PUT (skb, tlv, v->len, (void *) v->val); +if (v->val && v->len && +nla_put (skb, tlv, v->len, (void *) v->val)) + goto nla_put_failure;return 0 ; nla_put_failure:
@@ -636,10 +637,13 @@ static void meta_int_apply_extras(struct meta_value *v,static int meta_int_dump (struct sk_buff *skb,struct meta_value *v,int tlv) { -if (v->len ==sizeof (unsigned long )) -NLA_PUT (skb, tlv,sizeof (unsigned long ), &v->val); -else if (v->len ==sizeof (u32)) -NLA_PUT_U32 (skb, tlv, v->val); +if (v->len ==sizeof (unsigned long )) { +if (nla_put (skb, tlv,sizeof (unsigned long ), &v->val)) + goto nla_put_failure; + }else if (v->len ==sizeof (u32)) { +if (nla_put_u32 (skb, tlv, v->val)) + goto nla_put_failure; + }return 0 ;
@@ -831,7 +835,8 @@ static int em_meta_dump(struct sk_buff *skb, struct tcf_ematch *em)memcpy (&hdr.left, &meta->lvalue.hdr,sizeof (hdr.left));memcpy (&hdr.right, &meta->rvalue.hdr,sizeof (hdr.right)); -NLA_PUT (skb,TCA_EM_META_HDR ,sizeof (hdr), &hdr); +if (nla_put (skb,TCA_EM_META_HDR ,sizeof (hdr), &hdr)) + goto nla_put_failure; ops =meta_type_ops (&meta->lvalue); if (ops->dump(skb, &meta->lvalue, TCA_EM_META_LVALUE) < 0 ||
net/sched/ematch.c +4 -2
@@ -441,7 +441,8 @@ int tcf_em_tree_dump(struct sk_buff *skb, struct tcf_ematch_tree *tree, int tlv)if (top_start ==NULL ) goto nla_put_failure; -NLA_PUT (skb,TCA_EMATCH_TREE_HDR ,sizeof (tree->hdr), &tree->hdr); +if (nla_put (skb,TCA_EMATCH_TREE_HDR ,sizeof (tree->hdr), &tree->hdr)) + goto nla_put_failure; list_start =nla_nest_start (skb,TCA_EMATCH_TREE_LIST );if (list_start ==NULL )
@@ -457,7 +458,8 @@ int tcf_em_tree_dump(struct sk_buff *skb, struct tcf_ematch_tree *tree, int tlv) .flags = em->flags }; -NLA_PUT (skb, i +1 ,sizeof (em_hdr), &em_hdr); +if (nla_put (skb, i +1 ,sizeof (em_hdr), &em_hdr)) + goto nla_put_failure;if (em->ops && em->ops->dump) {if (em->ops->dump (skb, em) <0 )
net/sched/sch_api.c +6 -3
@@ -426,7 +426,8 @@ static int qdisc_dump_stab(struct sk_buff *skb, struct qdisc_size_table *stab) nest =nla_nest_start (skb,TCA_STAB );if (nest ==NULL ) goto nla_put_failure; -NLA_PUT (skb,TCA_STAB_BASE ,sizeof (stab->szopts), &stab->szopts); +if (nla_put (skb,TCA_STAB_BASE ,sizeof (stab->szopts), &stab->szopts)) + goto nla_put_failure;nla_nest_end (skb, nest);return skb->len;
@@ -1201,7 +1202,8 @@ static int tc_fill_qdisc(struct sk_buff *skb, struct Qdisc *q, u32 clid, tcm->tcm_parent = clid; tcm->tcm_handle = q->handle; tcm->tcm_info =atomic_read (&q->refcnt); -NLA_PUT_STRING (skb,TCA_KIND , q->ops->id); +if (nla_put_string (skb,TCA_KIND , q->ops->id)) + goto nla_put_failure;if (q->ops->dump && q->ops->dump (q, skb) <0 ) goto nla_put_failure; q->qstats.qlen = q->q.qlen;
@@ -1505,7 +1507,8 @@ static int tc_fill_tclass(struct sk_buff *skb, struct Qdisc *q, tcm->tcm_parent = q->handle; tcm->tcm_handle = q->handle; tcm->tcm_info =0 ; -NLA_PUT_STRING (skb,TCA_KIND , q->ops->id); +if (nla_put_string (skb,TCA_KIND , q->ops->id)) + goto nla_put_failure;if (cl_ops->dump && cl_ops->dump (q, cl, skb, tcm) <0 ) goto nla_put_failure;
net/sched/sch_atm.c +13 -8
@@ -601,7 +601,8 @@ static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl,if (nest ==NULL ) goto nla_put_failure; -NLA_PUT (skb,TCA_ATM_HDR , flow->hdr_len, flow->hdr); +if (nla_put (skb,TCA_ATM_HDR , flow->hdr_len, flow->hdr)) + goto nla_put_failure;if (flow->vcc) {struct sockaddr_atmpvc pvc;int state;
@@ -610,15 +611,19 @@ static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl, pvc.sap_addr.itf = flow->vcc->dev ? flow->vcc->dev->number :-1 ; pvc.sap_addr.vpi = flow->vcc->vpi; pvc.sap_addr.vci = flow->vcc->vci; -NLA_PUT (skb,TCA_ATM_ADDR ,sizeof (pvc), &pvc); +if (nla_put (skb,TCA_ATM_ADDR ,sizeof (pvc), &pvc)) + goto nla_put_failure; state =ATM_VF2VS (flow->vcc->flags); -NLA_PUT_U32 (skb,TCA_ATM_STATE , state); +if (nla_put_u32 (skb,TCA_ATM_STATE , state)) + goto nla_put_failure; + } +if (flow->excess) { +if (nla_put_u32 (skb,TCA_ATM_EXCESS , flow->classid)) + goto nla_put_failure; + }else { +if (nla_put_u32 (skb,TCA_ATM_EXCESS ,0 )) + goto nla_put_failure; } -if (flow->excess) -NLA_PUT_U32 (skb,TCA_ATM_EXCESS , flow->classid); -else -NLA_PUT_U32 (skb,TCA_ATM_EXCESS ,0 ); -nla_nest_end (skb, nest);return skb->len;
net/sched/sch_cbq.c +12 -6
@@ -1425,7 +1425,8 @@ static int cbq_dump_rate(struct sk_buff *skb, struct cbq_class *cl) {unsigned char *b =skb_tail_pointer (skb); -NLA_PUT (skb,TCA_CBQ_RATE ,sizeof (cl->R_tab->rate), &cl->R_tab->rate); +if (nla_put (skb,TCA_CBQ_RATE ,sizeof (cl->R_tab->rate), &cl->R_tab->rate)) + goto nla_put_failure;return skb->len; nla_put_failure:
@@ -1450,7 +1451,8 @@ static int cbq_dump_lss(struct sk_buff *skb, struct cbq_class *cl) opt.minidle = (u32)(-cl->minidle); opt.offtime = cl->offtime; opt.change = ~0 ; -NLA_PUT (skb,TCA_CBQ_LSSOPT ,sizeof (opt), &opt); +if (nla_put (skb,TCA_CBQ_LSSOPT ,sizeof (opt), &opt)) + goto nla_put_failure;return skb->len; nla_put_failure:
@@ -1468,7 +1470,8 @@ static int cbq_dump_wrr(struct sk_buff *skb, struct cbq_class *cl) opt.priority = cl->priority +1 ; opt.cpriority = cl->cpriority +1 ; opt.weight = cl->weight; -NLA_PUT (skb,TCA_CBQ_WRROPT ,sizeof (opt), &opt); +if (nla_put (skb,TCA_CBQ_WRROPT ,sizeof (opt), &opt)) + goto nla_put_failure;return skb->len; nla_put_failure:
@@ -1485,7 +1488,8 @@ static int cbq_dump_ovl(struct sk_buff *skb, struct cbq_class *cl) opt.priority2 = cl->priority2 +1 ; opt.pad =0 ; opt.penalty = cl->penalty; -NLA_PUT (skb,TCA_CBQ_OVL_STRATEGY ,sizeof (opt), &opt); +if (nla_put (skb,TCA_CBQ_OVL_STRATEGY ,sizeof (opt), &opt)) + goto nla_put_failure;return skb->len; nla_put_failure:
@@ -1502,7 +1506,8 @@ static int cbq_dump_fopt(struct sk_buff *skb, struct cbq_class *cl) opt.split = cl->split ? cl->split->common.classid :0 ; opt.defmap = cl->defmap; opt.defchange = ~0 ; -NLA_PUT (skb,TCA_CBQ_FOPT ,sizeof (opt), &opt); +if (nla_put (skb,TCA_CBQ_FOPT ,sizeof (opt), &opt)) + goto nla_put_failure; }return skb->len;
@@ -1521,7 +1526,8 @@ static int cbq_dump_police(struct sk_buff *skb, struct cbq_class *cl) opt.police = cl->police; opt.__res1 =0 ; opt.__res2 =0 ; -NLA_PUT (skb,TCA_CBQ_POLICE ,sizeof (opt), &opt); +if (nla_put (skb,TCA_CBQ_POLICE ,sizeof (opt), &opt)) + goto nla_put_failure; }return skb->len;
net/sched/sch_choke.c +3 -2
@@ -515,8 +515,9 @@ static int choke_dump(struct Qdisc *sch, struct sk_buff *skb)if (opts ==NULL ) goto nla_put_failure; -NLA_PUT (skb,TCA_CHOKE_PARMS ,sizeof (opt), &opt); -NLA_PUT_U32 (skb,TCA_CHOKE_MAX_P , q->parms.max_P); +if (nla_put (skb,TCA_CHOKE_PARMS ,sizeof (opt), &opt) || +nla_put_u32 (skb,TCA_CHOKE_MAX_P , q->parms.max_P)) + goto nla_put_failure;return nla_nest_end (skb, opts); nla_put_failure:
net/sched/sch_drr.c +2 -1
@@ -260,7 +260,8 @@ static int drr_dump_class(struct Qdisc *sch, unsigned long arg, nest =nla_nest_start (skb,TCA_OPTIONS );if (nest ==NULL ) goto nla_put_failure; -NLA_PUT_U32 (skb,TCA_DRR_QUANTUM , cl->quantum); +if (nla_put_u32 (skb,TCA_DRR_QUANTUM , cl->quantum)) + goto nla_put_failure;return nla_nest_end (skb, nest); nla_put_failure:
net/sched/sch_dsmark.c +11 -7
@@ -429,8 +429,9 @@ static int dsmark_dump_class(struct Qdisc *sch, unsigned long cl, opts =nla_nest_start (skb,TCA_OPTIONS );if (opts ==NULL ) goto nla_put_failure; -NLA_PUT_U8 (skb,TCA_DSMARK_MASK , p->mask[cl -1 ]); -NLA_PUT_U8 (skb,TCA_DSMARK_VALUE , p->value[cl -1 ]); +if (nla_put_u8 (skb,TCA_DSMARK_MASK , p->mask[cl -1 ]) || +nla_put_u8 (skb,TCA_DSMARK_VALUE , p->value[cl -1 ])) + goto nla_put_failure;return nla_nest_end (skb, opts);
@@ -447,13 +448,16 @@ static int dsmark_dump(struct Qdisc *sch, struct sk_buff *skb) opts =nla_nest_start (skb,TCA_OPTIONS );if (opts ==NULL ) goto nla_put_failure; -NLA_PUT_U16 (skb,TCA_DSMARK_INDICES , p->indices); +if (nla_put_u16 (skb,TCA_DSMARK_INDICES , p->indices)) + goto nla_put_failure; -if (p->default_index !=NO_DEFAULT_INDEX ) -NLA_PUT_U16 (skb,TCA_DSMARK_DEFAULT_INDEX , p->default_index); +if (p->default_index !=NO_DEFAULT_INDEX && +nla_put_u16 (skb,TCA_DSMARK_DEFAULT_INDEX , p->default_index)) + goto nla_put_failure; -if (p->set_tc_index) -NLA_PUT_FLAG (skb,TCA_DSMARK_SET_TC_INDEX ); +if (p->set_tc_index && +nla_put_flag (skb,TCA_DSMARK_SET_TC_INDEX )) + goto nla_put_failure;return nla_nest_end (skb, opts);
net/sched/sch_fifo.c +2 -1
@@ -85,7 +85,8 @@ static int fifo_dump(struct Qdisc *sch, struct sk_buff *skb) {struct tc_fifo_qopt opt = { .limit = sch->limit }; -NLA_PUT (skb,TCA_OPTIONS ,sizeof (opt), &opt); +if (nla_put (skb,TCA_OPTIONS ,sizeof (opt), &opt)) + goto nla_put_failure;return skb->len; nla_put_failure:
net/sched/sch_generic.c +2 -1
@@ -512,7 +512,8 @@ static int pfifo_fast_dump(struct Qdisc *qdisc, struct sk_buff *skb)struct tc_prio_qopt opt = { .bands =PFIFO_FAST_BANDS };memcpy (&opt.priomap, prio2band,TC_PRIO_MAX +1 ); -NLA_PUT (skb,TCA_OPTIONS ,sizeof (opt), &opt); +if (nla_put (skb,TCA_OPTIONS ,sizeof (opt), &opt)) + goto nla_put_failure;return skb->len; nla_put_failure:
net/sched/sch_gred.c +4 -2
@@ -521,14 +521,16 @@ static int gred_dump(struct Qdisc *sch, struct sk_buff *skb) opts =nla_nest_start (skb,TCA_OPTIONS );if (opts ==NULL ) goto nla_put_failure; -NLA_PUT (skb,TCA_GRED_DPS ,sizeof (sopt), &sopt); +if (nla_put (skb,TCA_GRED_DPS ,sizeof (sopt), &sopt)) + goto nla_put_failure;for (i =0 ; i < MAX_DPs; i++) {struct gred_sched_data *q = table->tab[i]; max_p[i] = q ? q->parms.max_P :0 ; } -NLA_PUT (skb,TCA_GRED_MAX_P ,sizeof (max_p), max_p); +if (nla_put (skb,TCA_GRED_MAX_P ,sizeof (max_p), max_p)) + goto nla_put_failure; parms =nla_nest_start (skb,TCA_GRED_PARMS );if (parms ==NULL )
net/sched/sch_hfsc.c +4 -2
@@ -1305,7 +1305,8 @@ hfsc_dump_sc(struct sk_buff *skb, int attr, struct internal_sc *sc) tsc.m1 =sm2m (sc->sm1); tsc.d =dx2d (sc->dx); tsc.m2 =sm2m (sc->sm2); -NLA_PUT (skb, attr,sizeof (tsc), &tsc); +if (nla_put (skb, attr,sizeof (tsc), &tsc)) + goto nla_put_failure;return skb->len;
@@ -1573,7 +1574,8 @@ hfsc_dump_qdisc(struct Qdisc *sch, struct sk_buff *skb) } qopt.defcls = q->defcls; -NLA_PUT (skb,TCA_OPTIONS ,sizeof (qopt), &qopt); +if (nla_put (skb,TCA_OPTIONS ,sizeof (qopt), &qopt)) + goto nla_put_failure;return skb->len; nla_put_failure:
net/sched/sch_htb.c +4 -2
@@ -1051,7 +1051,8 @@ static int htb_dump(struct Qdisc *sch, struct sk_buff *skb) nest =nla_nest_start (skb,TCA_OPTIONS );if (nest ==NULL ) goto nla_put_failure; -NLA_PUT (skb,TCA_HTB_INIT ,sizeof (gopt), &gopt); +if (nla_put (skb,TCA_HTB_INIT ,sizeof (gopt), &gopt)) + goto nla_put_failure;nla_nest_end (skb, nest);spin_unlock_bh (root_lock);
@@ -1090,7 +1091,8 @@ static int htb_dump_class(struct Qdisc *sch, unsigned long arg, opt.quantum = cl->quantum; opt.prio = cl->prio; opt.level = cl->level; -NLA_PUT (skb,TCA_HTB_PARMS ,sizeof (opt), &opt); +if (nla_put (skb,TCA_HTB_PARMS ,sizeof (opt), &opt)) + goto nla_put_failure;nla_nest_end (skb, nest);spin_unlock_bh (root_lock);
net/sched/sch_mqprio.c +2 -1
@@ -247,7 +247,8 @@ static int mqprio_dump(struct Qdisc *sch, struct sk_buff *skb) opt.offset[i] = dev->tc_to_txq[i].offset; } -NLA_PUT (skb,TCA_OPTIONS ,sizeof (opt), &opt); +if (nla_put (skb,TCA_OPTIONS ,sizeof (opt), &opt)) + goto nla_put_failure;return skb->len; nla_put_failure:
net/sched/sch_multiq.c +2 -1
@@ -284,7 +284,8 @@ static int multiq_dump(struct Qdisc *sch, struct sk_buff *skb) opt.bands = q->bands; opt.max_bands = q->max_bands; -NLA_PUT (skb,TCA_OPTIONS ,sizeof (opt), &opt); +if (nla_put (skb,TCA_OPTIONS ,sizeof (opt), &opt)) + goto nla_put_failure;return skb->len;
net/sched/sch_netem.c +14 -7
@@ -834,7 +834,8 @@ static int dump_loss_model(const struct netem_sched_data *q, .p23 = q->clg.a5, }; -NLA_PUT (skb,NETEM_LOSS_GI ,sizeof (gi), &gi); +if (nla_put (skb,NETEM_LOSS_GI ,sizeof (gi), &gi)) + goto nla_put_failure;break ; }case CLG_GILB_ELL : {
@@ -845,7 +846,8 @@ static int dump_loss_model(const struct netem_sched_data *q, .k1 = q->clg.a4, }; -NLA_PUT (skb,NETEM_LOSS_GE ,sizeof (ge), &ge); +if (nla_put (skb,NETEM_LOSS_GE ,sizeof (ge), &ge)) + goto nla_put_failure;break ; } }
@@ -874,26 +876,31 @@ static int netem_dump(struct Qdisc *sch, struct sk_buff *skb) qopt.loss = q->loss; qopt.gap = q->gap; qopt.duplicate = q->duplicate; -NLA_PUT (skb,TCA_OPTIONS ,sizeof (qopt), &qopt); +if (nla_put (skb,TCA_OPTIONS ,sizeof (qopt), &qopt)) + goto nla_put_failure; cor.delay_corr = q->delay_cor.rho; cor.loss_corr = q->loss_cor.rho; cor.dup_corr = q->dup_cor.rho; -NLA_PUT (skb,TCA_NETEM_CORR ,sizeof (cor), &cor); +if (nla_put (skb,TCA_NETEM_CORR ,sizeof (cor), &cor)) + goto nla_put_failure; reorder.probability = q->reorder; reorder.correlation = q->reorder_cor.rho; -NLA_PUT (skb,TCA_NETEM_REORDER ,sizeof (reorder), &reorder); +if (nla_put (skb,TCA_NETEM_REORDER ,sizeof (reorder), &reorder)) + goto nla_put_failure; corrupt.probability = q->corrupt; corrupt.correlation = q->corrupt_cor.rho; -NLA_PUT (skb,TCA_NETEM_CORRUPT ,sizeof (corrupt), &corrupt); +if (nla_put (skb,TCA_NETEM_CORRUPT ,sizeof (corrupt), &corrupt)) + goto nla_put_failure; rate.rate = q->rate; rate.packet_overhead = q->packet_overhead; rate.cell_size = q->cell_size; rate.cell_overhead = q->cell_overhead; -NLA_PUT (skb,TCA_NETEM_RATE ,sizeof (rate), &rate); +if (nla_put (skb,TCA_NETEM_RATE ,sizeof (rate), &rate)) + goto nla_put_failure;if (dump_loss_model (q, skb) !=0 ) goto nla_put_failure;
net/sched/sch_prio.c +2 -1
@@ -247,7 +247,8 @@ static int prio_dump(struct Qdisc *sch, struct sk_buff *skb) opt.bands = q->bands;memcpy (&opt.priomap, q->prio2band,TC_PRIO_MAX +1 ); -NLA_PUT (skb,TCA_OPTIONS ,sizeof (opt), &opt); +if (nla_put (skb,TCA_OPTIONS ,sizeof (opt), &opt)) + goto nla_put_failure;return skb->len;
net/sched/sch_qfq.c +3 -2
@@ -429,8 +429,9 @@ static int qfq_dump_class(struct Qdisc *sch, unsigned long arg, nest =nla_nest_start (skb,TCA_OPTIONS );if (nest ==NULL ) goto nla_put_failure; -NLA_PUT_U32 (skb,TCA_QFQ_WEIGHT ,ONE_FP /cl->inv_w); -NLA_PUT_U32 (skb,TCA_QFQ_LMAX , cl->lmax); +if (nla_put_u32 (skb,TCA_QFQ_WEIGHT ,ONE_FP /cl->inv_w) || +nla_put_u32 (skb,TCA_QFQ_LMAX , cl->lmax)) + goto nla_put_failure;return nla_nest_end (skb, nest); nla_put_failure:
net/sched/sch_red.c +3 -2
@@ -272,8 +272,9 @@ static int red_dump(struct Qdisc *sch, struct sk_buff *skb) opts =nla_nest_start (skb,TCA_OPTIONS );if (opts ==NULL ) goto nla_put_failure; -NLA_PUT (skb,TCA_RED_PARMS ,sizeof (opt), &opt); -NLA_PUT_U32 (skb,TCA_RED_MAX_P , q->parms.max_P); +if (nla_put (skb,TCA_RED_PARMS ,sizeof (opt), &opt) || +nla_put_u32 (skb,TCA_RED_MAX_P , q->parms.max_P)) + goto nla_put_failure;return nla_nest_end (skb, opts); nla_put_failure:
net/sched/sch_sfb.c +2 -1
@@ -570,7 +570,8 @@ static int sfb_dump(struct Qdisc *sch, struct sk_buff *skb) sch->qstats.backlog = q->qdisc->qstats.backlog; opts =nla_nest_start (skb,TCA_OPTIONS ); -NLA_PUT (skb,TCA_SFB_PARMS ,sizeof (opt), &opt); +if (nla_put (skb,TCA_SFB_PARMS ,sizeof (opt), &opt)) + goto nla_put_failure;return nla_nest_end (skb, opts); nla_put_failure:
net/sched/sch_sfq.c +2 -1
@@ -812,7 +812,8 @@ static int sfq_dump(struct Qdisc *sch, struct sk_buff *skb)memcpy (&opt.stats, &q->stats,sizeof (opt.stats)); opt.flags = q->flags; -NLA_PUT (skb,TCA_OPTIONS ,sizeof (opt), &opt); +if (nla_put (skb,TCA_OPTIONS ,sizeof (opt), &opt)) + goto nla_put_failure;return skb->len;
net/sched/sch_tbf.c +2 -1
@@ -359,7 +359,8 @@ static int tbf_dump(struct Qdisc *sch, struct sk_buff *skb)memset (&opt.peakrate,0 ,sizeof (opt.peakrate)); opt.mtu = q->mtu; opt.buffer = q->buffer; -NLA_PUT (skb,TCA_TBF_PARMS ,sizeof (opt), &opt); +if (nla_put (skb,TCA_TBF_PARMS ,sizeof (opt), &opt)) + goto nla_put_failure;nla_nest_end (skb, nest);return skb->len;
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 7/51 nfc: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/nfc/netlink.c | 70 +++++++++++++++++++++++++++++++---------------------- 1 files changed, 41 insertions(+), 29 deletions(-)
net/nfc/netlink.c +41 -29
@@ -63,19 +63,23 @@ static int nfc_genl_send_target(struct sk_buff *msg, struct nfc_target *target,genl_dump_check_consistent (cb, hdr, &nfc_genl_family); -NLA_PUT_U32 (msg,NFC_ATTR_TARGET_INDEX , target->idx); -NLA_PUT_U32 (msg,NFC_ATTR_PROTOCOLS , target->supported_protocols); -NLA_PUT_U16 (msg,NFC_ATTR_TARGET_SENS_RES , target->sens_res); -NLA_PUT_U8 (msg,NFC_ATTR_TARGET_SEL_RES , target->sel_res); -if (target->nfcid1_len >0 ) -NLA_PUT (msg,NFC_ATTR_TARGET_NFCID1 , target->nfcid1_len, - target->nfcid1); -if (target->sensb_res_len >0 ) -NLA_PUT (msg,NFC_ATTR_TARGET_SENSB_RES , target->sensb_res_len, - target->sensb_res); -if (target->sensf_res_len >0 ) -NLA_PUT (msg,NFC_ATTR_TARGET_SENSF_RES , target->sensf_res_len, - target->sensf_res); +if (nla_put_u32 (msg,NFC_ATTR_TARGET_INDEX , target->idx) || +nla_put_u32 (msg,NFC_ATTR_PROTOCOLS , target->supported_protocols) || +nla_put_u16 (msg,NFC_ATTR_TARGET_SENS_RES , target->sens_res) || +nla_put_u8 (msg,NFC_ATTR_TARGET_SEL_RES , target->sel_res)) + goto nla_put_failure; +if (target->nfcid1_len >0 && +nla_put (msg,NFC_ATTR_TARGET_NFCID1 , target->nfcid1_len, + target->nfcid1)) + goto nla_put_failure; +if (target->sensb_res_len >0 && +nla_put (msg,NFC_ATTR_TARGET_SENSB_RES , target->sensb_res_len, + target->sensb_res)) + goto nla_put_failure; +if (target->sensf_res_len >0 && +nla_put (msg,NFC_ATTR_TARGET_SENSF_RES , target->sensf_res_len, + target->sensf_res)) + goto nla_put_failure;return genlmsg_end (msg, hdr);
@@ -170,7 +174,8 @@ int nfc_genl_targets_found(struct nfc_dev *dev)if (!hdr) goto free_msg; -NLA_PUT_U32 (msg,NFC_ATTR_DEVICE_INDEX , dev->idx); +if (nla_put_u32 (msg,NFC_ATTR_DEVICE_INDEX , dev->idx)) + goto nla_put_failure;genlmsg_end (msg, hdr);
@@ -197,10 +202,11 @@ int nfc_genl_device_added(struct nfc_dev *dev)if (!hdr) goto free_msg; -NLA_PUT_STRING (msg,NFC_ATTR_DEVICE_NAME ,nfc_device_name (dev)); -NLA_PUT_U32 (msg,NFC_ATTR_DEVICE_INDEX , dev->idx); -NLA_PUT_U32 (msg,NFC_ATTR_PROTOCOLS , dev->supported_protocols); -NLA_PUT_U8 (msg,NFC_ATTR_DEVICE_POWERED , dev->dev_up); +if (nla_put_string (msg,NFC_ATTR_DEVICE_NAME ,nfc_device_name (dev)) || +nla_put_u32 (msg,NFC_ATTR_DEVICE_INDEX , dev->idx) || +nla_put_u32 (msg,NFC_ATTR_PROTOCOLS , dev->supported_protocols) || +nla_put_u8 (msg,NFC_ATTR_DEVICE_POWERED , dev->dev_up)) + goto nla_put_failure;genlmsg_end (msg, hdr);
@@ -229,7 +235,8 @@ int nfc_genl_device_removed(struct nfc_dev *dev)if (!hdr) goto free_msg; -NLA_PUT_U32 (msg,NFC_ATTR_DEVICE_INDEX , dev->idx); +if (nla_put_u32 (msg,NFC_ATTR_DEVICE_INDEX , dev->idx)) + goto nla_put_failure;genlmsg_end (msg, hdr);
@@ -259,10 +266,11 @@ static int nfc_genl_send_device(struct sk_buff *msg, struct nfc_dev *dev,if (cb)genl_dump_check_consistent (cb, hdr, &nfc_genl_family); -NLA_PUT_STRING (msg,NFC_ATTR_DEVICE_NAME ,nfc_device_name (dev)); -NLA_PUT_U32 (msg,NFC_ATTR_DEVICE_INDEX , dev->idx); -NLA_PUT_U32 (msg,NFC_ATTR_PROTOCOLS , dev->supported_protocols); -NLA_PUT_U8 (msg,NFC_ATTR_DEVICE_POWERED , dev->dev_up); +if (nla_put_string (msg,NFC_ATTR_DEVICE_NAME ,nfc_device_name (dev)) || +nla_put_u32 (msg,NFC_ATTR_DEVICE_INDEX , dev->idx) || +nla_put_u32 (msg,NFC_ATTR_PROTOCOLS , dev->supported_protocols) || +nla_put_u8 (msg,NFC_ATTR_DEVICE_POWERED , dev->dev_up)) + goto nla_put_failure;return genlmsg_end (msg, hdr);
@@ -339,11 +347,14 @@ int nfc_genl_dep_link_up_event(struct nfc_dev *dev, u32 target_idx,if (!hdr) goto free_msg; -NLA_PUT_U32 (msg,NFC_ATTR_DEVICE_INDEX , dev->idx); -if (rf_mode ==NFC_RF_INITIATOR ) -NLA_PUT_U32 (msg,NFC_ATTR_TARGET_INDEX , target_idx); -NLA_PUT_U8 (msg,NFC_ATTR_COMM_MODE , comm_mode); -NLA_PUT_U8 (msg,NFC_ATTR_RF_MODE , rf_mode); +if (nla_put_u32 (msg,NFC_ATTR_DEVICE_INDEX , dev->idx)) + goto nla_put_failure; +if (rf_mode ==NFC_RF_INITIATOR && +nla_put_u32 (msg,NFC_ATTR_TARGET_INDEX , target_idx)) + goto nla_put_failure; +if (nla_put_u8 (msg,NFC_ATTR_COMM_MODE , comm_mode) || +nla_put_u8 (msg,NFC_ATTR_RF_MODE , rf_mode)) + goto nla_put_failure;genlmsg_end (msg, hdr);
@@ -376,7 +387,8 @@ int nfc_genl_dep_link_down_event(struct nfc_dev *dev)if (!hdr) goto free_msg; -NLA_PUT_U32 (msg,NFC_ATTR_DEVICE_INDEX , dev->idx); +if (nla_put_u32 (msg,NFC_ATTR_DEVICE_INDEX , dev->idx)) + goto nla_put_failure;genlmsg_end (msg, hdr);
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 8/51 genetlink: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/netlink/genetlink.c | 35 ++++++++++++++++++++--------------- 1 files changed, 20 insertions(+), 15 deletions(-)
net/netlink/genetlink.c +20 -15
@@ -635,11 +635,12 @@ static int ctrl_fill_info(struct genl_family *family, u32 pid, u32 seq,if (hdr ==NULL )return -1 ; -NLA_PUT_STRING (skb,CTRL_ATTR_FAMILY_NAME , family->name); -NLA_PUT_U16 (skb,CTRL_ATTR_FAMILY_ID , family->id); -NLA_PUT_U32 (skb,CTRL_ATTR_VERSION , family->version); -NLA_PUT_U32 (skb,CTRL_ATTR_HDRSIZE , family->hdrsize); -NLA_PUT_U32 (skb,CTRL_ATTR_MAXATTR , family->maxattr); +if (nla_put_string (skb,CTRL_ATTR_FAMILY_NAME , family->name) || +nla_put_u16 (skb,CTRL_ATTR_FAMILY_ID , family->id) || +nla_put_u32 (skb,CTRL_ATTR_VERSION , family->version) || +nla_put_u32 (skb,CTRL_ATTR_HDRSIZE , family->hdrsize) || +nla_put_u32 (skb,CTRL_ATTR_MAXATTR , family->maxattr)) + goto nla_put_failure;if (!list_empty (&family->ops_list)) {struct nlattr *nla_ops;
@@ -657,8 +658,9 @@ static int ctrl_fill_info(struct genl_family *family, u32 pid, u32 seq,if (nest ==NULL ) goto nla_put_failure; -NLA_PUT_U32 (skb,CTRL_ATTR_OP_ID , ops->cmd); -NLA_PUT_U32 (skb,CTRL_ATTR_OP_FLAGS , ops->flags); +if (nla_put_u32 (skb,CTRL_ATTR_OP_ID , ops->cmd) || +nla_put_u32 (skb,CTRL_ATTR_OP_FLAGS , ops->flags)) + goto nla_put_failure;nla_nest_end (skb, nest); }
@@ -682,9 +684,10 @@ static int ctrl_fill_info(struct genl_family *family, u32 pid, u32 seq,if (nest ==NULL ) goto nla_put_failure; -NLA_PUT_U32 (skb,CTRL_ATTR_MCAST_GRP_ID , grp->id); -NLA_PUT_STRING (skb,CTRL_ATTR_MCAST_GRP_NAME , - grp->name); +if (nla_put_u32 (skb,CTRL_ATTR_MCAST_GRP_ID , grp->id) || +nla_put_string (skb,CTRL_ATTR_MCAST_GRP_NAME , + grp->name)) + goto nla_put_failure;nla_nest_end (skb, nest); }
@@ -710,8 +713,9 @@ static int ctrl_fill_mcgrp_info(struct genl_multicast_group *grp, u32 pid,if (hdr ==NULL )return -1 ; -NLA_PUT_STRING (skb,CTRL_ATTR_FAMILY_NAME , grp->family->name); -NLA_PUT_U16 (skb,CTRL_ATTR_FAMILY_ID , grp->family->id); +if (nla_put_string (skb,CTRL_ATTR_FAMILY_NAME , grp->family->name) || +nla_put_u16 (skb,CTRL_ATTR_FAMILY_ID , grp->family->id)) + goto nla_put_failure; nla_grps =nla_nest_start (skb,CTRL_ATTR_MCAST_GROUPS );if (nla_grps ==NULL )
@@ -721,9 +725,10 @@ static int ctrl_fill_mcgrp_info(struct genl_multicast_group *grp, u32 pid,if (nest ==NULL ) goto nla_put_failure; -NLA_PUT_U32 (skb,CTRL_ATTR_MCAST_GRP_ID , grp->id); -NLA_PUT_STRING (skb,CTRL_ATTR_MCAST_GRP_NAME , - grp->name); +if (nla_put_u32 (skb,CTRL_ATTR_MCAST_GRP_ID , grp->id) || +nla_put_string (skb,CTRL_ATTR_MCAST_GRP_NAME , + grp->name)) + goto nla_put_failure;nla_nest_end (skb, nest);nla_nest_end (skb, nla_grps);
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 9/51 nfnetlink_queue: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/netfilter/nfnetlink_queue.c | 59 +++++++++++++++++++++++---------------- 1 files changed, 35 insertions(+), 24 deletions(-)
net/netfilter/nfnetlink_queue.c +35 -24
@@ -288,58 +288,67 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue, indev = entry->indev;if (indev) {#ifndef CONFIG_BRIDGE_NETFILTER -NLA_PUT_BE32 (skb,NFQA_IFINDEX_INDEV ,htonl (indev->ifindex)); +if (nla_put_be32 (skb,NFQA_IFINDEX_INDEV ,htonl (indev->ifindex))) + goto nla_put_failure;#else if (entry->pf ==PF_BRIDGE ) {/* Case 1: indev is physical input device, we need to * look for bridge group (when called from * netfilter_bridge) */ -NLA_PUT_BE32 (skb,NFQA_IFINDEX_PHYSINDEV , -htonl (indev->ifindex)); +if (nla_put_be32 (skb,NFQA_IFINDEX_PHYSINDEV , +htonl (indev->ifindex)) ||/* this is the bridge group "brX" */ /* rcu_read_lock()ed by __nf_queue */ -NLA_PUT_BE32 (skb,NFQA_IFINDEX_INDEV , -htonl (br_port_get_rcu (indev)->br->dev->ifindex)); +nla_put_be32 (skb,NFQA_IFINDEX_INDEV , +htonl (br_port_get_rcu (indev)->br->dev->ifindex))) + goto nla_put_failure; }else {/* Case 2: indev is bridge group, we need to look for * physical device (when called from ipv4) */ -NLA_PUT_BE32 (skb,NFQA_IFINDEX_INDEV , -htonl (indev->ifindex)); -if (entskb->nf_bridge && entskb->nf_bridge->physindev) -NLA_PUT_BE32 (skb,NFQA_IFINDEX_PHYSINDEV , -htonl (entskb->nf_bridge->physindev->ifindex)); +if (nla_put_be32 (skb,NFQA_IFINDEX_INDEV , +htonl (indev->ifindex))) + goto nla_put_failure; +if (entskb->nf_bridge && entskb->nf_bridge->physindev && +nla_put_be32 (skb,NFQA_IFINDEX_PHYSINDEV , +htonl (entskb->nf_bridge->physindev->ifindex))) + goto nla_put_failure; }#endif }if (outdev) {#ifndef CONFIG_BRIDGE_NETFILTER -NLA_PUT_BE32 (skb,NFQA_IFINDEX_OUTDEV ,htonl (outdev->ifindex)); +if (nla_put_be32 (skb,NFQA_IFINDEX_OUTDEV ,htonl (outdev->ifindex))) + goto nla_put_failure;#else if (entry->pf ==PF_BRIDGE ) {/* Case 1: outdev is physical output device, we need to * look for bridge group (when called from * netfilter_bridge) */ -NLA_PUT_BE32 (skb,NFQA_IFINDEX_PHYSOUTDEV , -htonl (outdev->ifindex)); +if (nla_put_be32 (skb,NFQA_IFINDEX_PHYSOUTDEV , +htonl (outdev->ifindex)) ||/* this is the bridge group "brX" */ /* rcu_read_lock()ed by __nf_queue */ -NLA_PUT_BE32 (skb,NFQA_IFINDEX_OUTDEV , -htonl (br_port_get_rcu (outdev)->br->dev->ifindex)); +nla_put_be32 (skb,NFQA_IFINDEX_OUTDEV , +htonl (br_port_get_rcu (outdev)->br->dev->ifindex))) + goto nla_put_failure; }else {/* Case 2: outdev is bridge group, we need to look for * physical output device (when called from ipv4) */ -NLA_PUT_BE32 (skb,NFQA_IFINDEX_OUTDEV , -htonl (outdev->ifindex)); -if (entskb->nf_bridge && entskb->nf_bridge->physoutdev) -NLA_PUT_BE32 (skb,NFQA_IFINDEX_PHYSOUTDEV , -htonl (entskb->nf_bridge->physoutdev->ifindex)); +if (nla_put_be32 (skb,NFQA_IFINDEX_OUTDEV , +htonl (outdev->ifindex))) + goto nla_put_failure; +if (entskb->nf_bridge && entskb->nf_bridge->physoutdev && +nla_put_be32 (skb,NFQA_IFINDEX_PHYSOUTDEV , +htonl (entskb->nf_bridge->physoutdev->ifindex))) + goto nla_put_failure; }#endif } -if (entskb->mark) -NLA_PUT_BE32 (skb,NFQA_MARK ,htonl (entskb->mark)); +if (entskb->mark && +nla_put_be32 (skb,NFQA_MARK ,htonl (entskb->mark))) + goto nla_put_failure;if (indev && entskb->dev && entskb->mac_header != entskb->network_header) {
@@ -347,7 +356,8 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,int len =dev_parse_header (entskb, phw.hw_addr);if (len) { phw.hw_addrlen =htons (len); -NLA_PUT (skb,NFQA_HWADDR ,sizeof (phw), &phw); +if (nla_put (skb,NFQA_HWADDR ,sizeof (phw), &phw)) + goto nla_put_failure; } }
@@ -357,7 +367,8 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue, ts.sec =cpu_to_be64 (tv.tv_sec); ts.usec =cpu_to_be64 (tv.tv_usec); -NLA_PUT (skb,NFQA_TIMESTAMP ,sizeof (ts), &ts); +if (nla_put (skb,NFQA_TIMESTAMP ,sizeof (ts), &ts)) + goto nla_put_failure; }if (data_len) {
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 10/51 nfnetlink_log: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/netfilter/nfnetlink_log.c | 100 ++++++++++++++++++++++++----------------- 1 files changed, 58 insertions(+), 42 deletions(-)
net/netfilter/nfnetlink_log.c +58 -42
@@ -391,67 +391,78 @@ __build_packet_message(struct nfulnl_instance *inst, pmsg.hw_protocol = skb->protocol; pmsg.hook = hooknum; -NLA_PUT (inst->skb,NFULA_PACKET_HDR ,sizeof (pmsg), &pmsg); +if (nla_put (inst->skb,NFULA_PACKET_HDR ,sizeof (pmsg), &pmsg)) + goto nla_put_failure; -if (prefix) -NLA_PUT (inst->skb,NFULA_PREFIX , plen, prefix); +if (prefix && +nla_put (inst->skb,NFULA_PREFIX , plen, prefix)) + goto nla_put_failure;if (indev) {#ifndef CONFIG_BRIDGE_NETFILTER -NLA_PUT_BE32 (inst->skb,NFULA_IFINDEX_INDEV , -htonl (indev->ifindex)); +if (nla_put_be32 (inst->skb,NFULA_IFINDEX_INDEV , +htonl (indev->ifindex))) + goto nla_put_failure;#else if (pf ==PF_BRIDGE ) {/* Case 1: outdev is physical input device, we need to * look for bridge group (when called from * netfilter_bridge) */ -NLA_PUT_BE32 (inst->skb,NFULA_IFINDEX_PHYSINDEV , -htonl (indev->ifindex)); +if (nla_put_be32 (inst->skb,NFULA_IFINDEX_PHYSINDEV , +htonl (indev->ifindex)) ||/* this is the bridge group "brX" */ /* rcu_read_lock()ed by nf_hook_slow or nf_log_packet */ -NLA_PUT_BE32 (inst->skb,NFULA_IFINDEX_INDEV , -htonl (br_port_get_rcu (indev)->br->dev->ifindex)); +nla_put_be32 (inst->skb,NFULA_IFINDEX_INDEV , +htonl (br_port_get_rcu (indev)->br->dev->ifindex))) + goto nla_put_failure; }else {/* Case 2: indev is bridge group, we need to look for * physical device (when called from ipv4) */ -NLA_PUT_BE32 (inst->skb,NFULA_IFINDEX_INDEV , -htonl (indev->ifindex)); -if (skb->nf_bridge && skb->nf_bridge->physindev) -NLA_PUT_BE32 (inst->skb,NFULA_IFINDEX_PHYSINDEV , -htonl (skb->nf_bridge->physindev->ifindex)); +if (nla_put_be32 (inst->skb,NFULA_IFINDEX_INDEV , +htonl (indev->ifindex))) + goto nla_put_failure; +if (skb->nf_bridge && skb->nf_bridge->physindev && +nla_put_be32 (inst->skb,NFULA_IFINDEX_PHYSINDEV , +htonl (skb->nf_bridge->physindev->ifindex))) + goto nla_put_failure; }#endif }if (outdev) {#ifndef CONFIG_BRIDGE_NETFILTER -NLA_PUT_BE32 (inst->skb,NFULA_IFINDEX_OUTDEV , -htonl (outdev->ifindex)); +if (nla_put_be32 (inst->skb,NFULA_IFINDEX_OUTDEV , +htonl (outdev->ifindex))) + goto nla_put_failure;#else if (pf ==PF_BRIDGE ) {/* Case 1: outdev is physical output device, we need to * look for bridge group (when called from * netfilter_bridge) */ -NLA_PUT_BE32 (inst->skb,NFULA_IFINDEX_PHYSOUTDEV , -htonl (outdev->ifindex)); +if (nla_put_be32 (inst->skb,NFULA_IFINDEX_PHYSOUTDEV , +htonl (outdev->ifindex)) ||/* this is the bridge group "brX" */ /* rcu_read_lock()ed by nf_hook_slow or nf_log_packet */ -NLA_PUT_BE32 (inst->skb,NFULA_IFINDEX_OUTDEV , -htonl (br_port_get_rcu (outdev)->br->dev->ifindex)); +nla_put_be32 (inst->skb,NFULA_IFINDEX_OUTDEV , +htonl (br_port_get_rcu (outdev)->br->dev->ifindex))) + goto nla_put_failure; }else {/* Case 2: indev is a bridge group, we need to look * for physical device (when called from ipv4) */ -NLA_PUT_BE32 (inst->skb,NFULA_IFINDEX_OUTDEV , -htonl (outdev->ifindex)); -if (skb->nf_bridge && skb->nf_bridge->physoutdev) -NLA_PUT_BE32 (inst->skb,NFULA_IFINDEX_PHYSOUTDEV , -htonl (skb->nf_bridge->physoutdev->ifindex)); +if (nla_put_be32 (inst->skb,NFULA_IFINDEX_OUTDEV , +htonl (outdev->ifindex))) + goto nla_put_failure; +if (skb->nf_bridge && skb->nf_bridge->physoutdev && +nla_put_be32 (inst->skb,NFULA_IFINDEX_PHYSOUTDEV , +htonl (skb->nf_bridge->physoutdev->ifindex))) + goto nla_put_failure; }#endif } -if (skb->mark) -NLA_PUT_BE32 (inst->skb,NFULA_MARK ,htonl (skb->mark)); +if (skb->mark && +nla_put_be32 (inst->skb,NFULA_MARK ,htonl (skb->mark))) + goto nla_put_failure;if (indev && skb->dev && skb->mac_header != skb->network_header) {
@@ -459,16 +470,18 @@ __build_packet_message(struct nfulnl_instance *inst,int len =dev_parse_header (skb, phw.hw_addr);if (len >0 ) { phw.hw_addrlen =htons (len); -NLA_PUT (inst->skb,NFULA_HWADDR ,sizeof (phw), &phw); +if (nla_put (inst->skb,NFULA_HWADDR ,sizeof (phw), &phw)) + goto nla_put_failure; } }if (indev &&skb_mac_header_was_set (skb)) { -NLA_PUT_BE16 (inst->skb,NFULA_HWTYPE ,htons (skb->dev->type)); -NLA_PUT_BE16 (inst->skb,NFULA_HWLEN , -htons (skb->dev->hard_header_len)); -NLA_PUT (inst->skb,NFULA_HWHEADER , skb->dev->hard_header_len, -skb_mac_header (skb)); +if (nla_put_be32 (inst->skb,NFULA_HWTYPE ,htons (skb->dev->type)) || +nla_put_be16 (inst->skb,NFULA_HWLEN , +htons (skb->dev->hard_header_len)) || +nla_put (inst->skb,NFULA_HWHEADER , skb->dev->hard_header_len, +skb_mac_header (skb))) + goto nla_put_failure; }if (skb->tstamp.tv64) {
@@ -477,7 +490,8 @@ __build_packet_message(struct nfulnl_instance *inst, ts.sec =cpu_to_be64 (tv.tv_sec); ts.usec =cpu_to_be64 (tv.tv_usec); -NLA_PUT (inst->skb,NFULA_TIMESTAMP ,sizeof (ts), &ts); +if (nla_put (inst->skb,NFULA_TIMESTAMP ,sizeof (ts), &ts)) + goto nla_put_failure; }/* UID */
@@ -487,22 +501,24 @@ __build_packet_message(struct nfulnl_instance *inst,struct file *file = skb->sk->sk_socket->file;__be32 uid =htonl (file->f_cred->fsuid);__be32 gid =htonl (file->f_cred->fsgid); -/* need to unlock here since NLA_PUT may goto */ read_unlock_bh (&skb->sk->sk_callback_lock); -NLA_PUT_BE32 (inst->skb,NFULA_UID , uid); -NLA_PUT_BE32 (inst->skb,NFULA_GID , gid); +if (nla_put_be32 (inst->skb,NFULA_UID , uid) || +nla_put_be32 (inst->skb,NFULA_GID , gid)) + goto nla_put_failure; }else read_unlock_bh (&skb->sk->sk_callback_lock); }/* local sequence number */ -if (inst->flags &NFULNL_CFG_F_SEQ ) -NLA_PUT_BE32 (inst->skb,NFULA_SEQ ,htonl (inst->seq++)); +if ((inst->flags &NFULNL_CFG_F_SEQ ) && +nla_put_be32 (inst->skb,NFULA_SEQ ,htonl (inst->seq++))) + goto nla_put_failure;/* global sequence number */ -if (inst->flags &NFULNL_CFG_F_SEQ_GLOBAL ) -NLA_PUT_BE32 (inst->skb,NFULA_SEQ_GLOBAL , -htonl (atomic_inc_return (&global_seq))); +if ((inst->flags &NFULNL_CFG_F_SEQ_GLOBAL ) && +nla_put_be32 (inst->skb,NFULA_SEQ_GLOBAL , +htonl (atomic_inc_return (&global_seq)))) + goto nla_put_failure;if (data_len) {struct nlattr *nla;
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 11/51 nfnetlink_cttimeout: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/netfilter/nfnetlink_cttimeout.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
net/netfilter/nfnetlink_cttimeout.c +6 -5
@@ -170,11 +170,12 @@ ctnl_timeout_fill_info(struct sk_buff *skb, u32 pid, u32 seq, u32 type, nfmsg->version =NFNETLINK_V0 ; nfmsg->res_id =0 ; -NLA_PUT_STRING (skb,CTA_TIMEOUT_NAME , timeout->name); -NLA_PUT_BE16 (skb,CTA_TIMEOUT_L3PROTO ,htons (timeout->l3num)); -NLA_PUT_U8 (skb,CTA_TIMEOUT_L4PROTO , timeout->l4proto->l4proto); -NLA_PUT_BE32 (skb,CTA_TIMEOUT_USE , -htonl (atomic_read (&timeout->refcnt))); +if (nla_put_string (skb,CTA_TIMEOUT_NAME , timeout->name) || +nla_put_be16 (skb,CTA_TIMEOUT_L3PROTO ,htons (timeout->l3num)) || +nla_put_u8 (skb,CTA_TIMEOUT_L4PROTO , timeout->l4proto->l4proto) || +nla_put_be32 (skb,CTA_TIMEOUT_USE , +htonl (atomic_read (&timeout->refcnt)))) + goto nla_put_failure;if (likely (l4proto->ctnl_timeout.obj_to_nlattr)) {struct nlattr *nest_parms;
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 12/51 nfnetlink_acct: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/netfilter/nfnetlink_acct.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
net/netfilter/nfnetlink_acct.c +6 -4
@@ -109,7 +109,8 @@ nfnl_acct_fill_info(struct sk_buff *skb, u32 pid, u32 seq, u32 type, nfmsg->version =NFNETLINK_V0 ; nfmsg->res_id =0 ; -NLA_PUT_STRING (skb,NFACCT_NAME , acct->name); +if (nla_put_string (skb,NFACCT_NAME , acct->name)) + goto nla_put_failure;if (type ==NFNL_MSG_ACCT_GET_CTRZERO ) { pkts =atomic64_xchg (&acct->pkts,0 );
@@ -118,9 +119,10 @@ nfnl_acct_fill_info(struct sk_buff *skb, u32 pid, u32 seq, u32 type, pkts =atomic64_read (&acct->pkts); bytes =atomic64_read (&acct->bytes); } -NLA_PUT_BE64 (skb,NFACCT_PKTS ,cpu_to_be64 (pkts)); -NLA_PUT_BE64 (skb,NFACCT_BYTES ,cpu_to_be64 (bytes)); -NLA_PUT_BE32 (skb,NFACCT_USE ,htonl (atomic_read (&acct->refcnt))); +if (nla_put_be64 (skb,NFACCT_PKTS ,cpu_to_be64 (pkts)) || +nla_put_be64 (skb,NFACCT_BYTES ,cpu_to_be64 (bytes)) || +nla_put_be32 (skb,NFACCT_USE ,htonl (atomic_read (&acct->refcnt)))) + goto nla_put_failure;nlmsg_end (skb, nlh);return skb->len;
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 13/51 nf_conntrack_proto_udp{,lite}: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/netfilter/nf_conntrack_proto_udp.c | 9 +++++---- net/netfilter/nf_conntrack_proto_udplite.c | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-)
net/netfilter/nf_conntrack_proto_udp.c +5 -4
@@ -181,10 +181,11 @@ udp_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data) {const unsigned int *timeouts = data; -NLA_PUT_BE32 (skb,CTA_TIMEOUT_UDP_UNREPLIED , -htonl (timeouts[UDP_CT_UNREPLIED ] /HZ )); -NLA_PUT_BE32 (skb,CTA_TIMEOUT_UDP_REPLIED , -htonl (timeouts[UDP_CT_REPLIED ] /HZ )); +if (nla_put_be32 (skb,CTA_TIMEOUT_UDP_UNREPLIED , +htonl (timeouts[UDP_CT_UNREPLIED ] /HZ )) || +nla_put_be32 (skb,CTA_TIMEOUT_UDP_REPLIED , +htonl (timeouts[UDP_CT_REPLIED ] /HZ ))) + goto nla_put_failure;return 0 ; nla_put_failure:
net/netfilter/nf_conntrack_proto_udplite.c +5 -4
@@ -185,10 +185,11 @@ udplite_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data) {const unsigned int *timeouts = data; -NLA_PUT_BE32 (skb,CTA_TIMEOUT_UDPLITE_UNREPLIED , -htonl (timeouts[UDPLITE_CT_UNREPLIED ] /HZ )); -NLA_PUT_BE32 (skb,CTA_TIMEOUT_UDPLITE_REPLIED , -htonl (timeouts[UDPLITE_CT_REPLIED ] /HZ )); +if (nla_put_be32 (skb,CTA_TIMEOUT_UDPLITE_UNREPLIED , +htonl (timeouts[UDPLITE_CT_UNREPLIED ] /HZ )) || +nla_put_be32 (skb,CTA_TIMEOUT_UDPLITE_REPLIED , +htonl (timeouts[UDPLITE_CT_REPLIED ] /HZ ))) + goto nla_put_failure;return 0 ; nla_put_failure:
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 14/51 nf_conntrack_proto_tcp: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/netfilter/nf_conntrack_proto_tcp.c | 68 ++++++++++++++++--------------- 1 files changed, 35 insertions(+), 33 deletions(-)
net/netfilter/nf_conntrack_proto_tcp.c +35 -33
@@ -1147,21 +1147,22 @@ static int tcp_to_nlattr(struct sk_buff *skb, struct nlattr *nla,if (!nest_parms) goto nla_put_failure; -NLA_PUT_U8 (skb,CTA_PROTOINFO_TCP_STATE , ct->proto.tcp.state); - -NLA_PUT_U8 (skb,CTA_PROTOINFO_TCP_WSCALE_ORIGINAL , - ct->proto.tcp.seen[0 ].td_scale); - -NLA_PUT_U8 (skb,CTA_PROTOINFO_TCP_WSCALE_REPLY , - ct->proto.tcp.seen[1 ].td_scale); +if (nla_put_u8 (skb,CTA_PROTOINFO_TCP_STATE , ct->proto.tcp.state) || +nla_put_u8 (skb,CTA_PROTOINFO_TCP_WSCALE_ORIGINAL , + ct->proto.tcp.seen[0 ].td_scale) || +nla_put_u8 (skb,CTA_PROTOINFO_TCP_WSCALE_REPLY , + ct->proto.tcp.seen[1 ].td_scale)) + goto nla_put_failure; tmp.flags = ct->proto.tcp.seen[0 ].flags; -NLA_PUT (skb,CTA_PROTOINFO_TCP_FLAGS_ORIGINAL , -sizeof (struct nf_ct_tcp_flags ), &tmp); +if (nla_put (skb,CTA_PROTOINFO_TCP_FLAGS_ORIGINAL , +sizeof (struct nf_ct_tcp_flags ), &tmp)) + goto nla_put_failure; tmp.flags = ct->proto.tcp.seen[1 ].flags; -NLA_PUT (skb,CTA_PROTOINFO_TCP_FLAGS_REPLY , -sizeof (struct nf_ct_tcp_flags ), &tmp); +if (nla_put (skb,CTA_PROTOINFO_TCP_FLAGS_REPLY , +sizeof (struct nf_ct_tcp_flags ), &tmp)) + goto nla_put_failure;spin_unlock_bh (&ct->lock);nla_nest_end (skb, nest_parms);
@@ -1310,28 +1311,29 @@ tcp_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data) {const unsigned int *timeouts = data; -NLA_PUT_BE32 (skb,CTA_TIMEOUT_TCP_SYN_SENT , -htonl (timeouts[TCP_CONNTRACK_SYN_SENT ] /HZ )); -NLA_PUT_BE32 (skb,CTA_TIMEOUT_TCP_SYN_RECV , -htonl (timeouts[TCP_CONNTRACK_SYN_RECV ] /HZ )); -NLA_PUT_BE32 (skb,CTA_TIMEOUT_TCP_ESTABLISHED , -htonl (timeouts[TCP_CONNTRACK_ESTABLISHED ] /HZ )); -NLA_PUT_BE32 (skb,CTA_TIMEOUT_TCP_FIN_WAIT , -htonl (timeouts[TCP_CONNTRACK_FIN_WAIT ] /HZ )); -NLA_PUT_BE32 (skb,CTA_TIMEOUT_TCP_CLOSE_WAIT , -htonl (timeouts[TCP_CONNTRACK_CLOSE_WAIT ] /HZ )); -NLA_PUT_BE32 (skb,CTA_TIMEOUT_TCP_LAST_ACK , -htonl (timeouts[TCP_CONNTRACK_LAST_ACK ] /HZ )); -NLA_PUT_BE32 (skb,CTA_TIMEOUT_TCP_TIME_WAIT , -htonl (timeouts[TCP_CONNTRACK_TIME_WAIT ] /HZ )); -NLA_PUT_BE32 (skb,CTA_TIMEOUT_TCP_CLOSE , -htonl (timeouts[TCP_CONNTRACK_CLOSE ] /HZ )); -NLA_PUT_BE32 (skb,CTA_TIMEOUT_TCP_SYN_SENT2 , -htonl (timeouts[TCP_CONNTRACK_SYN_SENT2 ] /HZ )); -NLA_PUT_BE32 (skb,CTA_TIMEOUT_TCP_RETRANS , -htonl (timeouts[TCP_CONNTRACK_RETRANS ] /HZ )); -NLA_PUT_BE32 (skb,CTA_TIMEOUT_TCP_UNACK , -htonl (timeouts[TCP_CONNTRACK_UNACK ] /HZ )); +if (nla_put_be32 (skb,CTA_TIMEOUT_TCP_SYN_SENT , +htonl (timeouts[TCP_CONNTRACK_SYN_SENT ] /HZ )) || +nla_put_be32 (skb,CTA_TIMEOUT_TCP_SYN_RECV , +htonl (timeouts[TCP_CONNTRACK_SYN_RECV ] /HZ )) || +nla_put_be32 (skb,CTA_TIMEOUT_TCP_ESTABLISHED , +htonl (timeouts[TCP_CONNTRACK_ESTABLISHED ] /HZ )) || +nla_put_be32 (skb,CTA_TIMEOUT_TCP_FIN_WAIT , +htonl (timeouts[TCP_CONNTRACK_FIN_WAIT ] /HZ )) || +nla_put_be32 (skb,CTA_TIMEOUT_TCP_CLOSE_WAIT , +htonl (timeouts[TCP_CONNTRACK_CLOSE_WAIT ] /HZ )) || +nla_put_be32 (skb,CTA_TIMEOUT_TCP_LAST_ACK , +htonl (timeouts[TCP_CONNTRACK_LAST_ACK ] /HZ )) || +nla_put_be32 (skb,CTA_TIMEOUT_TCP_TIME_WAIT , +htonl (timeouts[TCP_CONNTRACK_TIME_WAIT ] /HZ )) || +nla_put_be32 (skb,CTA_TIMEOUT_TCP_CLOSE , +htonl (timeouts[TCP_CONNTRACK_CLOSE ] /HZ )) || +nla_put_be32 (skb,CTA_TIMEOUT_TCP_SYN_SENT2 , +htonl (timeouts[TCP_CONNTRACK_SYN_SENT2 ] /HZ )) || +nla_put_be32 (skb,CTA_TIMEOUT_TCP_RETRANS , +htonl (timeouts[TCP_CONNTRACK_RETRANS ] /HZ )) || +nla_put_be32 (skb,CTA_TIMEOUT_TCP_UNACK , +htonl (timeouts[TCP_CONNTRACK_UNACK ] /HZ ))) + goto nla_put_failure;return 0 ; nla_put_failure:
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 15/51 nf_conntrack_proto_sctp: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/netfilter/nf_conntrack_proto_sctp.c | 22 ++++++++++------------ 1 files changed, 10 insertions(+), 12 deletions(-)
net/netfilter/nf_conntrack_proto_sctp.c +10 -12
@@ -482,15 +482,12 @@ static int sctp_to_nlattr(struct sk_buff *skb, struct nlattr *nla,if (!nest_parms) goto nla_put_failure; -NLA_PUT_U8 (skb,CTA_PROTOINFO_SCTP_STATE , ct->proto.sctp.state); - -NLA_PUT_BE32 (skb, -CTA_PROTOINFO_SCTP_VTAG_ORIGINAL , - ct->proto.sctp.vtag[IP_CT_DIR_ORIGINAL ]); - -NLA_PUT_BE32 (skb, -CTA_PROTOINFO_SCTP_VTAG_REPLY , - ct->proto.sctp.vtag[IP_CT_DIR_REPLY ]); +if (nla_put_u8 (skb,CTA_PROTOINFO_SCTP_STATE , ct->proto.sctp.state) || +nla_put_be32 (skb,CTA_PROTOINFO_SCTP_VTAG_ORIGINAL , + ct->proto.sctp.vtag[IP_CT_DIR_ORIGINAL ]) || +nla_put_be32 (skb,CTA_PROTOINFO_SCTP_VTAG_REPLY , + ct->proto.sctp.vtag[IP_CT_DIR_REPLY ])) + goto nla_put_failure;spin_unlock_bh (&ct->lock);
@@ -578,9 +575,10 @@ sctp_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data)const unsigned int *timeouts = data;int i; -for (i=CTA_TIMEOUT_SCTP_UNSPEC +1 ; i<CTA_TIMEOUT_SCTP_MAX +1 ; i++) -NLA_PUT_BE32 (skb, i,htonl (timeouts[i] /HZ )); - +for (i=CTA_TIMEOUT_SCTP_UNSPEC +1 ; i<CTA_TIMEOUT_SCTP_MAX +1 ; i++) { +if (nla_put_be32 (skb, i,htonl (timeouts[i] /HZ ))) + goto nla_put_failure; + }return 0 ; nla_put_failure:
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 16/51 nf_conntrack_proto_gre: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/netfilter/nf_conntrack_proto_gre.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
net/netfilter/nf_conntrack_proto_gre.c +5 -4
@@ -321,10 +321,11 @@ gre_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data) {const unsigned int *timeouts = data; -NLA_PUT_BE32 (skb,CTA_TIMEOUT_GRE_UNREPLIED , -htonl (timeouts[GRE_CT_UNREPLIED ] /HZ )); -NLA_PUT_BE32 (skb,CTA_TIMEOUT_GRE_REPLIED , -htonl (timeouts[GRE_CT_REPLIED ] /HZ )); +if (nla_put_be32 (skb,CTA_TIMEOUT_GRE_UNREPLIED , +htonl (timeouts[GRE_CT_UNREPLIED ] /HZ )) || +nla_put_be32 (skb,CTA_TIMEOUT_GRE_REPLIED , +htonl (timeouts[GRE_CT_REPLIED ] /HZ ))) + goto nla_put_failure;return 0 ; nla_put_failure:
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 4/51 phonet: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/phonet/pn_netlink.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
net/phonet/pn_netlink.c +5 -3
@@ -116,7 +116,8 @@ static int fill_addr(struct sk_buff *skb, struct net_device *dev, u8 addr, ifm->ifa_flags =IFA_F_PERMANENT ; ifm->ifa_scope =RT_SCOPE_LINK ; ifm->ifa_index = dev->ifindex; -NLA_PUT_U8 (skb,IFA_LOCAL , addr); +if (nla_put_u8 (skb,IFA_LOCAL , addr)) + goto nla_put_failure;return nlmsg_end (skb, nlh); nla_put_failure:
@@ -183,8 +184,9 @@ static int fill_route(struct sk_buff *skb, struct net_device *dev, u8 dst, rtm->rtm_scope =RT_SCOPE_UNIVERSE ; rtm->rtm_type =RTN_UNICAST ; rtm->rtm_flags =0 ; -NLA_PUT_U8 (skb,RTA_DST , dst); -NLA_PUT_U32 (skb,RTA_OIF , dev->ifindex); +if (nla_put_u8 (skb,RTA_DST , dst) || +nla_put_u32 (skb,RTA_OIF , dev->ifindex)) + goto nla_put_failure;return nlmsg_end (skb, nlh); nla_put_failure:
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 17/51 nf_conntrack_proto_generic: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/netfilter/nf_conntrack_proto_generic.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
net/netfilter/nf_conntrack_proto_generic.c +2 -1
@@ -90,7 +90,8 @@ generic_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data) {const unsigned int *timeout = data; -NLA_PUT_BE32 (skb,CTA_TIMEOUT_GENERIC_TIMEOUT ,htonl (*timeout /HZ )); +if (nla_put_be32 (skb,CTA_TIMEOUT_GENERIC_TIMEOUT ,htonl (*timeout /HZ ))) + goto nla_put_failure;return 0 ;
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 5/51 netlink: Add nla_put_be{16,32,64}() helpers.
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
--- include/net/netlink.h | 35 ++++++++++++++++++++++++++++++++++- 1 files changed, 34 insertions(+), 1 deletions(-)
include/net/netlink.h +34 -1
@@ -772,6 +772,17 @@ static inline int nla_put_u16(struct sk_buff *skb, int attrtype, u16 value) }/** +* nla_put_be16 - Add a __be16 netlink attribute to a socket buffer +* @skb: socket buffer to add attribute to +* @attrtype: attribute type +* @value: numeric value +*/ +static inline int nla_put_be16 (struct sk_buff *skb,int attrtype,__be16 value) +{ +return nla_put (skb, attrtype,sizeof (__be16), &value); +} + +/** * nla_put_u32 - Add a u32 netlink attribute to a socket buffer * @skb: socket buffer to add attribute to * @attrtype: attribute type
@@ -783,7 +794,18 @@ static inline int nla_put_u32(struct sk_buff *skb, int attrtype, u32 value) }/** -* nla_put_64 - Add a u64 netlink attribute to a socket buffer +* nla_put_be32 - Add a __be32 netlink attribute to a socket buffer +* @skb: socket buffer to add attribute to +* @attrtype: attribute type +* @value: numeric value +*/ +static inline int nla_put_be32 (struct sk_buff *skb,int attrtype,__be32 value) +{ +return nla_put (skb, attrtype,sizeof (__be32), &value); +} + +/** +* nla_put_u64 - Add a u64 netlink attribute to a socket buffer * @skb: socket buffer to add attribute to * @attrtype: attribute type * @value: numeric value
@@ -794,6 +816,17 @@ static inline int nla_put_u64(struct sk_buff *skb, int attrtype, u64 value) }/** +* nla_put_be64 - Add a __be64 netlink attribute to a socket buffer +* @skb: socket buffer to add attribute to +* @attrtype: attribute type +* @value: numeric value +*/ +static inline int nla_put_be64 (struct sk_buff *skb,int attrtype,__be64 value) +{ +return nla_put (skb, attrtype,sizeof (__be64), &value); +} + +/** * nla_put_string - Add a string netlink attribute to a socket buffer * @skb: socket buffer to add attribute to * @attrtype: attribute type
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 6/51 openvswitch: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/openvswitch/datapath.c | 34 ++++++++++++++++++++-------------- net/openvswitch/flow.c | 18 +++++++++++------- 2 files changed, 31 insertions(+), 21 deletions(-)
net/openvswitch/datapath.c +20 -14
@@ -779,15 +779,18 @@ static int ovs_flow_cmd_fill_info(struct sw_flow *flow, struct datapath *dp, tcp_flags = flow->tcp_flags;spin_unlock_bh (&flow->lock); -if (used) -NLA_PUT_U64 (skb,OVS_FLOW_ATTR_USED ,ovs_flow_used_time (used)); +if (used && +nla_put_u64 (skb,OVS_FLOW_ATTR_USED ,ovs_flow_used_time (used))) + goto nla_put_failure; -if (stats.n_packets) -NLA_PUT (skb,OVS_FLOW_ATTR_STATS , -sizeof (struct ovs_flow_stats ), &stats); +if (stats.n_packets && +nla_put (skb,OVS_FLOW_ATTR_STATS , +sizeof (struct ovs_flow_stats ), &stats)) + goto nla_put_failure; -if (tcp_flags) -NLA_PUT_U8 (skb,OVS_FLOW_ATTR_TCP_FLAGS , tcp_flags); +if (tcp_flags && +nla_put_u8 (skb,OVS_FLOW_ATTR_TCP_FLAGS , tcp_flags)) + goto nla_put_failure;/* If OVS_FLOW_ATTR_ACTIONS doesn't fit, skip dumping the actions if * this is the first flow to be dumped into 'skb'. This is unusual for
@@ -1169,7 +1172,8 @@ static int ovs_dp_cmd_fill_info(struct datapath *dp, struct sk_buff *skb, goto nla_put_failure;get_dp_stats (dp, &dp_stats); -NLA_PUT (skb,OVS_DP_ATTR_STATS ,sizeof (struct ovs_dp_stats ), &dp_stats); +if (nla_put (skb,OVS_DP_ATTR_STATS ,sizeof (struct ovs_dp_stats ), &dp_stats)) + goto nla_put_failure;return genlmsg_end (skb, ovs_header);
@@ -1469,14 +1473,16 @@ static int ovs_vport_cmd_fill_info(struct vport *vport, struct sk_buff *skb, ovs_header->dp_ifindex =get_dpifindex (vport->dp); -NLA_PUT_U32 (skb,OVS_VPORT_ATTR_PORT_NO , vport->port_no); -NLA_PUT_U32 (skb,OVS_VPORT_ATTR_TYPE , vport->ops->type); -NLA_PUT_STRING (skb,OVS_VPORT_ATTR_NAME , vport->ops->get_name (vport)); -NLA_PUT_U32 (skb,OVS_VPORT_ATTR_UPCALL_PID , vport->upcall_pid); +if (nla_put_u32 (skb,OVS_VPORT_ATTR_PORT_NO , vport->port_no) || +nla_put_u32 (skb,OVS_VPORT_ATTR_TYPE , vport->ops->type) || +nla_put_string (skb,OVS_VPORT_ATTR_NAME , vport->ops->get_name (vport)) || +nla_put_u32 (skb,OVS_VPORT_ATTR_UPCALL_PID , vport->upcall_pid)) + goto nla_put_failure;ovs_vport_get_stats (vport, &vport_stats); -NLA_PUT (skb,OVS_VPORT_ATTR_STATS ,sizeof (struct ovs_vport_stats ), - &vport_stats); +if (nla_put (skb,OVS_VPORT_ATTR_STATS ,sizeof (struct ovs_vport_stats ), + &vport_stats)) + goto nla_put_failure; err =ovs_vport_get_options (vport, skb);if (err == -EMSGSIZE )
net/openvswitch/flow.c +11 -7
@@ -1174,11 +1174,13 @@ int ovs_flow_to_nlattrs(const struct sw_flow_key *swkey, struct sk_buff *skb)struct ovs_key_ethernet *eth_key;struct nlattr *nla, *encap; -if (swkey->phy.priority) -NLA_PUT_U32 (skb,OVS_KEY_ATTR_PRIORITY , swkey->phy.priority); +if (swkey->phy.priority && +nla_put_u32 (skb,OVS_KEY_ATTR_PRIORITY , swkey->phy.priority)) + goto nla_put_failure; -if (swkey->phy.in_port !=USHRT_MAX ) -NLA_PUT_U32 (skb,OVS_KEY_ATTR_IN_PORT , swkey->phy.in_port); +if (swkey->phy.in_port !=USHRT_MAX && +nla_put_u32 (skb,OVS_KEY_ATTR_IN_PORT , swkey->phy.in_port)) + goto nla_put_failure; nla =nla_reserve (skb,OVS_KEY_ATTR_ETHERNET ,sizeof (*eth_key));if (!nla)
@@ -1188,8 +1190,9 @@ int ovs_flow_to_nlattrs(const struct sw_flow_key *swkey, struct sk_buff *skb)memcpy (eth_key->eth_dst, swkey->eth.dst,ETH_ALEN );if (swkey->eth.tci || swkey->eth.type ==htons (ETH_P_8021Q )) { -NLA_PUT_BE16 (skb,OVS_KEY_ATTR_ETHERTYPE ,htons (ETH_P_8021Q )); -NLA_PUT_BE16 (skb,OVS_KEY_ATTR_VLAN , swkey->eth.tci); +if (nla_put_be16 (skb,OVS_KEY_ATTR_ETHERTYPE ,htons (ETH_P_8021Q )) || +nla_put_be16 (skb,OVS_KEY_ATTR_VLAN , swkey->eth.tci)) + goto nla_put_failure; encap =nla_nest_start (skb,OVS_KEY_ATTR_ENCAP );if (!swkey->eth.tci) goto unencap;
@@ -1200,7 +1203,8 @@ int ovs_flow_to_nlattrs(const struct sw_flow_key *swkey, struct sk_buff *skb)if (swkey->eth.type ==htons (ETH_P_802_2 )) goto unencap; -NLA_PUT_BE16 (skb,OVS_KEY_ATTR_ETHERTYPE , swkey->eth.type); +if (nla_put_be16 (skb,OVS_KEY_ATTR_ETHERTYPE , swkey->eth.type)) + goto nla_put_failure;if (swkey->eth.type ==htons (ETH_P_IP )) {struct ovs_key_ipv4 *ipv4_key;
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 20/51 nf_conntrack_core: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/netfilter/nf_conntrack_core.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
net/netfilter/nf_conntrack_core.c +3 -2
@@ -1151,8 +1151,9 @@ static struct nf_ct_ext_type nf_ct_zone_extend __read_mostly = {int nf_ct_port_tuple_to_nlattr (struct sk_buff *skb,const struct nf_conntrack_tuple *tuple) { -NLA_PUT_BE16 (skb,CTA_PROTO_SRC_PORT , tuple->src.u.tcp.port); -NLA_PUT_BE16 (skb,CTA_PROTO_DST_PORT , tuple->dst.u.tcp.port); +if (nla_put_be16 (skb,CTA_PROTO_SRC_PORT , tuple->src.u.tcp.port) || +nla_put_be16 (skb,CTA_PROTO_DST_PORT , tuple->dst.u.tcp.port)) + goto nla_put_failure;return 0 ; nla_put_failure:
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 19/51 nf_conntrack_netlink: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/netfilter/nf_conntrack_netlink.c | 83 ++++++++++++++++++++-------------- 1 files changed, 49 insertions(+), 34 deletions(-)
net/netfilter/nf_conntrack_netlink.c +49 -34
@@ -66,7 +66,8 @@ ctnetlink_dump_tuples_proto(struct sk_buff *skb, nest_parms =nla_nest_start (skb,CTA_TUPLE_PROTO |NLA_F_NESTED );if (!nest_parms) goto nla_put_failure; -NLA_PUT_U8 (skb,CTA_PROTO_NUM , tuple->dst.protonum); +if (nla_put_u8 (skb,CTA_PROTO_NUM , tuple->dst.protonum)) + goto nla_put_failure;if (likely (l4proto->tuple_to_nlattr)) ret = l4proto->tuple_to_nlattr (skb, tuple);
@@ -126,7 +127,8 @@ ctnetlink_dump_tuples(struct sk_buff *skb,static inline int ctnetlink_dump_status (struct sk_buff *skb,const struct nf_conn *ct) { -NLA_PUT_BE32 (skb,CTA_STATUS ,htonl (ct->status)); +if (nla_put_be32 (skb,CTA_STATUS ,htonl (ct->status))) + goto nla_put_failure;return 0 ; nla_put_failure:
@@ -141,7 +143,8 @@ ctnetlink_dump_timeout(struct sk_buff *skb, const struct nf_conn *ct)if (timeout <0 ) timeout =0 ; -NLA_PUT_BE32 (skb,CTA_TIMEOUT ,htonl (timeout)); +if (nla_put_be32 (skb,CTA_TIMEOUT ,htonl (timeout))) + goto nla_put_failure;return 0 ; nla_put_failure:
@@ -190,7 +193,8 @@ ctnetlink_dump_helpinfo(struct sk_buff *skb, const struct nf_conn *ct) nest_helper =nla_nest_start (skb,CTA_HELP |NLA_F_NESTED );if (!nest_helper) goto nla_put_failure; -NLA_PUT_STRING (skb,CTA_HELP_NAME , helper->name); +if (nla_put_string (skb,CTA_HELP_NAME , helper->name)) + goto nla_put_failure;if (helper->to_nlattr) helper->to_nlattr (skb, ct);
@@ -214,8 +218,9 @@ dump_counters(struct sk_buff *skb, u64 pkts, u64 bytes,if (!nest_count) goto nla_put_failure; -NLA_PUT_BE64 (skb,CTA_COUNTERS_PACKETS ,cpu_to_be64 (pkts)); -NLA_PUT_BE64 (skb,CTA_COUNTERS_BYTES ,cpu_to_be64 (bytes)); +if (nla_put_be64 (skb,CTA_COUNTERS_PACKETS ,cpu_to_be64 (pkts)) || +nla_put_be64 (skb,CTA_COUNTERS_BYTES ,cpu_to_be64 (bytes))) + goto nla_put_failure;nla_nest_end (skb, nest_count);
@@ -260,11 +265,10 @@ ctnetlink_dump_timestamp(struct sk_buff *skb, const struct nf_conn *ct)if (!nest_count) goto nla_put_failure; -NLA_PUT_BE64 (skb,CTA_TIMESTAMP_START ,cpu_to_be64 (tstamp->start)); -if (tstamp->stop !=0 ) { -NLA_PUT_BE64 (skb,CTA_TIMESTAMP_STOP , -cpu_to_be64 (tstamp->stop)); - } +if (nla_put_be64 (skb,CTA_TIMESTAMP_START ,cpu_to_be64 (tstamp->start)) || + (tstamp->stop !=0 &&nla_put_be64 (skb,CTA_TIMESTAMP_STOP , +cpu_to_be64 (tstamp->stop)))) + goto nla_put_failure;nla_nest_end (skb, nest_count);return 0 ;
@@ -277,7 +281,8 @@ nla_put_failure:static inline int ctnetlink_dump_mark (struct sk_buff *skb,const struct nf_conn *ct) { -NLA_PUT_BE32 (skb,CTA_MARK ,htonl (ct->mark)); +if (nla_put_be32 (skb,CTA_MARK ,htonl (ct->mark))) + goto nla_put_failure;return 0 ; nla_put_failure:
@@ -304,7 +309,8 @@ ctnetlink_dump_secctx(struct sk_buff *skb, const struct nf_conn *ct)if (!nest_secctx) goto nla_put_failure; -NLA_PUT_STRING (skb,CTA_SECCTX_NAME , secctx); +if (nla_put_string (skb,CTA_SECCTX_NAME , secctx)) + goto nla_put_failure;nla_nest_end (skb, nest_secctx); ret =0 ;
@@ -349,12 +355,13 @@ dump_nat_seq_adj(struct sk_buff *skb, const struct nf_nat_seq *natseq, int type)if (!nest_parms) goto nla_put_failure; -NLA_PUT_BE32 (skb,CTA_NAT_SEQ_CORRECTION_POS , -htonl (natseq->correction_pos)); -NLA_PUT_BE32 (skb,CTA_NAT_SEQ_OFFSET_BEFORE , -htonl (natseq->offset_before)); -NLA_PUT_BE32 (skb,CTA_NAT_SEQ_OFFSET_AFTER , -htonl (natseq->offset_after)); +if (nla_put_be32 (skb,CTA_NAT_SEQ_CORRECTION_POS , +htonl (natseq->correction_pos)) || +nla_put_be32 (skb,CTA_NAT_SEQ_OFFSET_BEFORE , +htonl (natseq->offset_before)) || +nla_put_be32 (skb,CTA_NAT_SEQ_OFFSET_AFTER , +htonl (natseq->offset_after))) + goto nla_put_failure;nla_nest_end (skb, nest_parms);
@@ -390,7 +397,8 @@ ctnetlink_dump_nat_seq_adj(struct sk_buff *skb, const struct nf_conn *ct)static inline int ctnetlink_dump_id (struct sk_buff *skb,const struct nf_conn *ct) { -NLA_PUT_BE32 (skb,CTA_ID ,htonl ((unsigned long )ct)); +if (nla_put_be32 (skb,CTA_ID ,htonl ((unsigned long )ct))) + goto nla_put_failure;return 0 ; nla_put_failure:
@@ -400,7 +408,8 @@ nla_put_failure:static inline int ctnetlink_dump_use (struct sk_buff *skb,const struct nf_conn *ct) { -NLA_PUT_BE32 (skb,CTA_USE ,htonl (atomic_read (&ct->ct_general.use))); +if (nla_put_be32 (skb,CTA_USE ,htonl (atomic_read (&ct->ct_general.use)))) + goto nla_put_failure;return 0 ; nla_put_failure:
@@ -440,8 +449,9 @@ ctnetlink_fill_info(struct sk_buff *skb, u32 pid, u32 seq, u32 type, goto nla_put_failure;nla_nest_end (skb, nest_parms); -if (nf_ct_zone (ct)) -NLA_PUT_BE16 (skb,CTA_ZONE ,htons (nf_ct_zone (ct))); +if (nf_ct_zone (ct) && +nla_put_be16 (skb,CTA_ZONE ,htons (nf_ct_zone (ct)))) + goto nla_put_failure; if (ctnetlink_dump_status(skb, ct) < 0 || ctnetlink_dump_timeout(skb, ct) < 0 ||
@@ -617,8 +627,9 @@ ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item) goto nla_put_failure;nla_nest_end (skb, nest_parms); -if (nf_ct_zone (ct)) -NLA_PUT_BE16 (skb,CTA_ZONE ,htons (nf_ct_zone (ct))); +if (nf_ct_zone (ct) && +nla_put_be16 (skb,CTA_ZONE ,htons (nf_ct_zone (ct)))) + goto nla_put_failure;if (ctnetlink_dump_id (skb, ct) <0 ) goto nla_put_failure;
@@ -1705,7 +1716,8 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb,if (!nest_parms) goto nla_put_failure; -NLA_PUT_BE32 (skb,CTA_EXPECT_NAT_DIR ,htonl (exp->dir)); +if (nla_put_be32 (skb,CTA_EXPECT_NAT_DIR ,htonl (exp->dir))) + goto nla_put_failure; nat_tuple.src.l3num =nf_ct_l3num (master); nat_tuple.src.u3.ip = exp->saved_ip;
@@ -1718,21 +1730,24 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb,nla_nest_end (skb, nest_parms); }#endif -NLA_PUT_BE32 (skb,CTA_EXPECT_TIMEOUT ,htonl (timeout)); -NLA_PUT_BE32 (skb,CTA_EXPECT_ID ,htonl ((unsigned long )exp)); -NLA_PUT_BE32 (skb,CTA_EXPECT_FLAGS ,htonl (exp->flags)); -NLA_PUT_BE32 (skb,CTA_EXPECT_CLASS ,htonl (exp->class)); +if (nla_put_be32 (skb,CTA_EXPECT_TIMEOUT ,htonl (timeout)) || +nla_put_be32 (skb,CTA_EXPECT_ID ,htonl ((unsigned long )exp)) || +nla_put_be32 (skb,CTA_EXPECT_FLAGS ,htonl (exp->flags)) || +nla_put_be32 (skb,CTA_EXPECT_CLASS ,htonl (exp->class))) + goto nla_put_failure; help =nfct_help (master);if (help) {struct nf_conntrack_helper *helper; helper =rcu_dereference (help->helper); -if (helper) -NLA_PUT_STRING (skb,CTA_EXPECT_HELP_NAME , helper->name); +if (helper && +nla_put_string (skb,CTA_EXPECT_HELP_NAME , helper->name)) + goto nla_put_failure; } expfn =nf_ct_helper_expectfn_find_by_symbol (exp->expectfn); -if (expfn !=NULL ) -NLA_PUT_STRING (skb,CTA_EXPECT_FN , expfn->name); +if (expfn !=NULL && +nla_put_string (skb,CTA_EXPECT_FN , expfn->name)) + goto nla_put_failure;return 0 ;
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 22/51 netlink: Add nla_put_net{16,32,64}() helpers.
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
--- include/net/netlink.h | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+), 0 deletions(-)
include/net/netlink.h +33 -0
@@ -783,6 +783,17 @@ static inline int nla_put_be16(struct sk_buff *skb, int attrtype, __be16 value) }/** +* nla_put_net16 - Add 16-bit network byte order netlink attribute to a socket buffer +* @skb: socket buffer to add attribute to +* @attrtype: attribute type +* @value: numeric value +*/ +static inline int nla_put_net16 (struct sk_buff *skb,int attrtype,__be16 value) +{ +return nla_put_be16 (skb, attrtype |NLA_F_NET_BYTEORDER , value); +} + +/** * nla_put_u32 - Add a u32 netlink attribute to a socket buffer * @skb: socket buffer to add attribute to * @attrtype: attribute type
@@ -805,6 +816,17 @@ static inline int nla_put_be32(struct sk_buff *skb, int attrtype, __be32 value) }/** +* nla_put_net32 - Add 32-bit network byte order netlink attribute to a socket buffer +* @skb: socket buffer to add attribute to +* @attrtype: attribute type +* @value: numeric value +*/ +static inline int nla_put_net32 (struct sk_buff *skb,int attrtype,__be32 value) +{ +return nla_put_be32 (skb, attrtype |NLA_F_NET_BYTEORDER , value); +} + +/** * nla_put_u64 - Add a u64 netlink attribute to a socket buffer * @skb: socket buffer to add attribute to * @attrtype: attribute type
@@ -827,6 +849,17 @@ static inline int nla_put_be64(struct sk_buff *skb, int attrtype, __be64 value) }/** +* nla_put_net64 - Add 64-bit network byte order netlink attribute to a socket buffer +* @skb: socket buffer to add attribute to +* @attrtype: attribute type +* @value: numeric value +*/ +static inline int nla_put_net64 (struct sk_buff *skb,int attrtype,__be64 value) +{ +return nla_put_be64 (skb, attrtype |NLA_F_NET_BYTEORDER , value); +} + +/** * nla_put_string - Add a string netlink attribute to a socket buffer * @skb: socket buffer to add attribute to * @attrtype: attribute type
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 18/51 nf_conntrack_proto_dccp: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/netfilter/nf_conntrack_proto_dccp.c | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-)
net/netfilter/nf_conntrack_proto_dccp.c +10 -8
@@ -643,11 +643,12 @@ static int dccp_to_nlattr(struct sk_buff *skb, struct nlattr *nla, nest_parms =nla_nest_start (skb,CTA_PROTOINFO_DCCP |NLA_F_NESTED );if (!nest_parms) goto nla_put_failure; -NLA_PUT_U8 (skb,CTA_PROTOINFO_DCCP_STATE , ct->proto.dccp.state); -NLA_PUT_U8 (skb,CTA_PROTOINFO_DCCP_ROLE , - ct->proto.dccp.role[IP_CT_DIR_ORIGINAL ]); -NLA_PUT_BE64 (skb,CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ , -cpu_to_be64 (ct->proto.dccp.handshake_seq)); +if (nla_put_u8 (skb,CTA_PROTOINFO_DCCP_STATE , ct->proto.dccp.state) || +nla_put_u8 (skb,CTA_PROTOINFO_DCCP_ROLE , + ct->proto.dccp.role[IP_CT_DIR_ORIGINAL ]) || +nla_put_be64 (skb,CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ , +cpu_to_be64 (ct->proto.dccp.handshake_seq))) + goto nla_put_failure;nla_nest_end (skb, nest_parms);spin_unlock_bh (&ct->lock);return 0 ;
@@ -739,9 +740,10 @@ dccp_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data)const unsigned int *timeouts = data;int i; -for (i=CTA_TIMEOUT_DCCP_UNSPEC +1 ; i<CTA_TIMEOUT_DCCP_MAX +1 ; i++) -NLA_PUT_BE32 (skb, i,htonl (timeouts[i] /HZ )); - +for (i=CTA_TIMEOUT_DCCP_UNSPEC +1 ; i<CTA_TIMEOUT_DCCP_MAX +1 ; i++) { +if (nla_put_be32 (skb, i,htonl (timeouts[i] /HZ ))) + goto nla_put_failure; + }return 0 ; nla_put_failure:
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 21/51 ipvs: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/netfilter/ipvs/ip_vs_ctl.c | 108 +++++++++++++++++++++------------------ 1 files changed, 58 insertions(+), 50 deletions(-)
net/netfilter/ipvs/ip_vs_ctl.c +58 -50
@@ -2816,17 +2816,17 @@ static int ip_vs_genl_fill_stats(struct sk_buff *skb, int container_type,ip_vs_copy_stats (&ustats, stats); -NLA_PUT_U32 (skb,IPVS_STATS_ATTR_CONNS , ustats.conns); -NLA_PUT_U32 (skb,IPVS_STATS_ATTR_INPKTS , ustats.inpkts); -NLA_PUT_U32 (skb,IPVS_STATS_ATTR_OUTPKTS , ustats.outpkts); -NLA_PUT_U64 (skb,IPVS_STATS_ATTR_INBYTES , ustats.inbytes); -NLA_PUT_U64 (skb,IPVS_STATS_ATTR_OUTBYTES , ustats.outbytes); -NLA_PUT_U32 (skb,IPVS_STATS_ATTR_CPS , ustats.cps); -NLA_PUT_U32 (skb,IPVS_STATS_ATTR_INPPS , ustats.inpps); -NLA_PUT_U32 (skb,IPVS_STATS_ATTR_OUTPPS , ustats.outpps); -NLA_PUT_U32 (skb,IPVS_STATS_ATTR_INBPS , ustats.inbps); -NLA_PUT_U32 (skb,IPVS_STATS_ATTR_OUTBPS , ustats.outbps); - +if (nla_put_u32 (skb,IPVS_STATS_ATTR_CONNS , ustats.conns) || +nla_put_u32 (skb,IPVS_STATS_ATTR_INPKTS , ustats.inpkts) || +nla_put_u32 (skb,IPVS_STATS_ATTR_OUTPKTS , ustats.outpkts) || +nla_put_u64 (skb,IPVS_STATS_ATTR_INBYTES , ustats.inbytes) || +nla_put_u64 (skb,IPVS_STATS_ATTR_OUTBYTES , ustats.outbytes) || +nla_put_u32 (skb,IPVS_STATS_ATTR_CPS , ustats.cps) || +nla_put_u32 (skb,IPVS_STATS_ATTR_INPPS , ustats.inpps) || +nla_put_u32 (skb,IPVS_STATS_ATTR_OUTPPS , ustats.outpps) || +nla_put_u32 (skb,IPVS_STATS_ATTR_INBPS , ustats.inbps) || +nla_put_u32 (skb,IPVS_STATS_ATTR_OUTBPS , ustats.outbps)) + goto nla_put_failure;nla_nest_end (skb, nl_stats);return 0 ;
@@ -2847,23 +2847,25 @@ static int ip_vs_genl_fill_service(struct sk_buff *skb,if (!nl_service)return -EMSGSIZE ; -NLA_PUT_U16 (skb,IPVS_SVC_ATTR_AF , svc->af); - +if (nla_put_u16 (skb,IPVS_SVC_ATTR_AF , svc->af)) + goto nla_put_failure;if (svc->fwmark) { -NLA_PUT_U32 (skb,IPVS_SVC_ATTR_FWMARK , svc->fwmark); +if (nla_put_u32 (skb,IPVS_SVC_ATTR_FWMARK , svc->fwmark)) + goto nla_put_failure; }else { -NLA_PUT_U16 (skb,IPVS_SVC_ATTR_PROTOCOL , svc->protocol); -NLA_PUT (skb,IPVS_SVC_ATTR_ADDR ,sizeof (svc->addr), &svc->addr); -NLA_PUT_U16 (skb,IPVS_SVC_ATTR_PORT , svc->port); +if (nla_put_u16 (skb,IPVS_SVC_ATTR_PROTOCOL , svc->protocol) || +nla_put (skb,IPVS_SVC_ATTR_ADDR ,sizeof (svc->addr), &svc->addr) || +nla_put_u16 (skb,IPVS_SVC_ATTR_PORT , svc->port)) + goto nla_put_failure; } -NLA_PUT_STRING (skb,IPVS_SVC_ATTR_SCHED_NAME , svc->scheduler->name); -if (svc->pe) -NLA_PUT_STRING (skb,IPVS_SVC_ATTR_PE_NAME , svc->pe->name); -NLA_PUT (skb,IPVS_SVC_ATTR_FLAGS ,sizeof (flags), &flags); -NLA_PUT_U32 (skb,IPVS_SVC_ATTR_TIMEOUT , svc->timeout /HZ ); -NLA_PUT_U32 (skb,IPVS_SVC_ATTR_NETMASK , svc->netmask); - +if (nla_put_string (skb,IPVS_SVC_ATTR_SCHED_NAME , svc->scheduler->name) || + (svc->pe && +nla_put_string (skb,IPVS_SVC_ATTR_PE_NAME , svc->pe->name)) || +nla_put (skb,IPVS_SVC_ATTR_FLAGS ,sizeof (flags), &flags) || +nla_put_u32 (skb,IPVS_SVC_ATTR_TIMEOUT , svc->timeout /HZ ) || +nla_put_u32 (skb,IPVS_SVC_ATTR_NETMASK , svc->netmask)) + goto nla_put_failure;if (ip_vs_genl_fill_stats (skb,IPVS_SVC_ATTR_STATS , &svc->stats)) goto nla_put_failure;
@@ -3038,21 +3040,22 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)if (!nl_dest)return -EMSGSIZE ; -NLA_PUT (skb,IPVS_DEST_ATTR_ADDR ,sizeof (dest->addr), &dest->addr); -NLA_PUT_U16 (skb,IPVS_DEST_ATTR_PORT , dest->port); - -NLA_PUT_U32 (skb,IPVS_DEST_ATTR_FWD_METHOD , -atomic_read (&dest->conn_flags) &IP_VS_CONN_F_FWD_MASK ); -NLA_PUT_U32 (skb,IPVS_DEST_ATTR_WEIGHT ,atomic_read (&dest->weight)); -NLA_PUT_U32 (skb,IPVS_DEST_ATTR_U_THRESH , dest->u_threshold); -NLA_PUT_U32 (skb,IPVS_DEST_ATTR_L_THRESH , dest->l_threshold); -NLA_PUT_U32 (skb,IPVS_DEST_ATTR_ACTIVE_CONNS , -atomic_read (&dest->activeconns)); -NLA_PUT_U32 (skb,IPVS_DEST_ATTR_INACT_CONNS , -atomic_read (&dest->inactconns)); -NLA_PUT_U32 (skb,IPVS_DEST_ATTR_PERSIST_CONNS , -atomic_read (&dest->persistconns)); - +if (nla_put (skb,IPVS_DEST_ATTR_ADDR ,sizeof (dest->addr), &dest->addr) || +nla_put_u16 (skb,IPVS_DEST_ATTR_PORT , dest->port) || +nla_put_u32 (skb,IPVS_DEST_ATTR_FWD_METHOD , + (atomic_read (&dest->conn_flags) & +IP_VS_CONN_F_FWD_MASK )) || +nla_put_u32 (skb,IPVS_DEST_ATTR_WEIGHT , +atomic_read (&dest->weight)) || +nla_put_u32 (skb,IPVS_DEST_ATTR_U_THRESH , dest->u_threshold) || +nla_put_u32 (skb,IPVS_DEST_ATTR_L_THRESH , dest->l_threshold) || +nla_put_u32 (skb,IPVS_DEST_ATTR_ACTIVE_CONNS , +atomic_read (&dest->activeconns)) || +nla_put_u32 (skb,IPVS_DEST_ATTR_INACT_CONNS , +atomic_read (&dest->inactconns)) || +nla_put_u32 (skb,IPVS_DEST_ATTR_PERSIST_CONNS , +atomic_read (&dest->persistconns))) + goto nla_put_failure;if (ip_vs_genl_fill_stats (skb,IPVS_DEST_ATTR_STATS , &dest->stats)) goto nla_put_failure;
@@ -3181,10 +3184,10 @@ static int ip_vs_genl_fill_daemon(struct sk_buff *skb, __be32 state,if (!nl_daemon)return -EMSGSIZE ; -NLA_PUT_U32 (skb,IPVS_DAEMON_ATTR_STATE , state); -NLA_PUT_STRING (skb,IPVS_DAEMON_ATTR_MCAST_IFN , mcast_ifn); -NLA_PUT_U32 (skb,IPVS_DAEMON_ATTR_SYNC_ID , syncid); - +if (nla_put_u32 (skb,IPVS_DAEMON_ATTR_STATE , state) || +nla_put_string (skb,IPVS_DAEMON_ATTR_MCAST_IFN , mcast_ifn) || +nla_put_u32 (skb,IPVS_DAEMON_ATTR_SYNC_ID , syncid)) + goto nla_put_failure;nla_nest_end (skb, nl_daemon);return 0 ;
@@ -3473,21 +3476,26 @@ static int ip_vs_genl_get_cmd(struct sk_buff *skb, struct genl_info *info)__ip_vs_get_timeouts (net, &t);#ifdef CONFIG_IP_VS_PROTO_TCP -NLA_PUT_U32 (msg,IPVS_CMD_ATTR_TIMEOUT_TCP , t.tcp_timeout); -NLA_PUT_U32 (msg,IPVS_CMD_ATTR_TIMEOUT_TCP_FIN , - t.tcp_fin_timeout); +if (nla_put_u32 (msg,IPVS_CMD_ATTR_TIMEOUT_TCP , + t.tcp_timeout) || +nla_put_u32 (msg,IPVS_CMD_ATTR_TIMEOUT_TCP_FIN , + t.tcp_fin_timeout)) + goto nla_put_failure;#endif #ifdef CONFIG_IP_VS_PROTO_UDP -NLA_PUT_U32 (msg,IPVS_CMD_ATTR_TIMEOUT_UDP , t.udp_timeout); +if (nla_put_u32 (msg,IPVS_CMD_ATTR_TIMEOUT_UDP , t.udp_timeout)) + goto nla_put_failure;#endif break ; }case IPVS_CMD_GET_INFO : -NLA_PUT_U32 (msg,IPVS_INFO_ATTR_VERSION ,IP_VS_VERSION_CODE ); -NLA_PUT_U32 (msg,IPVS_INFO_ATTR_CONN_TAB_SIZE , - ip_vs_conn_tab_size); +if (nla_put_u32 (msg,IPVS_INFO_ATTR_VERSION , +IP_VS_VERSION_CODE ) || +nla_put_u32 (msg,IPVS_INFO_ATTR_CONN_TAB_SIZE , + ip_vs_conn_tab_size)) + goto nla_put_failure;break ; }
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 24/51 l2tp: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/l2tp/l2tp_netlink.c | 114 ++++++++++++++++++++++++++-------------------- 1 files changed, 64 insertions(+), 50 deletions(-)
net/l2tp/l2tp_netlink.c +64 -50
@@ -231,24 +231,28 @@ static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 pid, u32 seq, int flags,if (IS_ERR (hdr))return PTR_ERR (hdr); -NLA_PUT_U8 (skb,L2TP_ATTR_PROTO_VERSION , tunnel->version); -NLA_PUT_U32 (skb,L2TP_ATTR_CONN_ID , tunnel->tunnel_id); -NLA_PUT_U32 (skb,L2TP_ATTR_PEER_CONN_ID , tunnel->peer_tunnel_id); -NLA_PUT_U32 (skb,L2TP_ATTR_DEBUG , tunnel->debug); -NLA_PUT_U16 (skb,L2TP_ATTR_ENCAP_TYPE , tunnel->encap); +if (nla_put_u8 (skb,L2TP_ATTR_PROTO_VERSION , tunnel->version) || +nla_put_u32 (skb,L2TP_ATTR_CONN_ID , tunnel->tunnel_id) || +nla_put_u32 (skb,L2TP_ATTR_PEER_CONN_ID , tunnel->peer_tunnel_id) || +nla_put_u32 (skb,L2TP_ATTR_DEBUG , tunnel->debug) || +nla_put_u16 (skb,L2TP_ATTR_ENCAP_TYPE , tunnel->encap)) + goto nla_put_failure; nest =nla_nest_start (skb,L2TP_ATTR_STATS );if (nest ==NULL ) goto nla_put_failure; -NLA_PUT_U64 (skb,L2TP_ATTR_TX_PACKETS , tunnel->stats.tx_packets); -NLA_PUT_U64 (skb,L2TP_ATTR_TX_BYTES , tunnel->stats.tx_bytes); -NLA_PUT_U64 (skb,L2TP_ATTR_TX_ERRORS , tunnel->stats.tx_errors); -NLA_PUT_U64 (skb,L2TP_ATTR_RX_PACKETS , tunnel->stats.rx_packets); -NLA_PUT_U64 (skb,L2TP_ATTR_RX_BYTES , tunnel->stats.rx_bytes); -NLA_PUT_U64 (skb,L2TP_ATTR_RX_SEQ_DISCARDS , tunnel->stats.rx_seq_discards); -NLA_PUT_U64 (skb,L2TP_ATTR_RX_OOS_PACKETS , tunnel->stats.rx_oos_packets); -NLA_PUT_U64 (skb,L2TP_ATTR_RX_ERRORS , tunnel->stats.rx_errors); +if (nla_put_u64 (skb,L2TP_ATTR_TX_PACKETS , tunnel->stats.tx_packets) || +nla_put_u64 (skb,L2TP_ATTR_TX_BYTES , tunnel->stats.tx_bytes) || +nla_put_u64 (skb,L2TP_ATTR_TX_ERRORS , tunnel->stats.tx_errors) || +nla_put_u64 (skb,L2TP_ATTR_RX_PACKETS , tunnel->stats.rx_packets) || +nla_put_u64 (skb,L2TP_ATTR_RX_BYTES , tunnel->stats.rx_bytes) || +nla_put_u64 (skb,L2TP_ATTR_RX_SEQ_DISCARDS , + tunnel->stats.rx_seq_discards) || +nla_put_u64 (skb,L2TP_ATTR_RX_OOS_PACKETS , + tunnel->stats.rx_oos_packets) || +nla_put_u64 (skb,L2TP_ATTR_RX_ERRORS , tunnel->stats.rx_errors)) + goto nla_put_failure;nla_nest_end (skb, nest); sk = tunnel->sock;
@@ -259,13 +263,16 @@ static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 pid, u32 seq, int flags,switch (tunnel->encap) {case L2TP_ENCAPTYPE_UDP : -NLA_PUT_U16 (skb,L2TP_ATTR_UDP_SPORT ,ntohs (inet->inet_sport)); -NLA_PUT_U16 (skb,L2TP_ATTR_UDP_DPORT ,ntohs (inet->inet_dport)); -NLA_PUT_U8 (skb,L2TP_ATTR_UDP_CSUM , (sk->sk_no_check !=UDP_CSUM_NOXMIT )); +if (nla_put_u16 (skb,L2TP_ATTR_UDP_SPORT ,ntohs (inet->inet_sport)) || +nla_put_u16 (skb,L2TP_ATTR_UDP_DPORT ,ntohs (inet->inet_dport)) || +nla_put_u8 (skb,L2TP_ATTR_UDP_CSUM , + (sk->sk_no_check !=UDP_CSUM_NOXMIT ))) + goto nla_put_failure;/* NOBREAK */ case L2TP_ENCAPTYPE_IP : -NLA_PUT_BE32 (skb,L2TP_ATTR_IP_SADDR , inet->inet_saddr); -NLA_PUT_BE32 (skb,L2TP_ATTR_IP_DADDR , inet->inet_daddr); +if (nla_put_be32 (skb,L2TP_ATTR_IP_SADDR , inet->inet_saddr) || +nla_put_be32 (skb,L2TP_ATTR_IP_DADDR , inet->inet_daddr)) + goto nla_put_failure;break ; }
@@ -563,43 +570,50 @@ static int l2tp_nl_session_send(struct sk_buff *skb, u32 pid, u32 seq, int flagsif (IS_ERR (hdr))return PTR_ERR (hdr); -NLA_PUT_U32 (skb,L2TP_ATTR_CONN_ID , tunnel->tunnel_id); -NLA_PUT_U32 (skb,L2TP_ATTR_SESSION_ID , session->session_id); -NLA_PUT_U32 (skb,L2TP_ATTR_PEER_CONN_ID , tunnel->peer_tunnel_id); -NLA_PUT_U32 (skb,L2TP_ATTR_PEER_SESSION_ID , session->peer_session_id); -NLA_PUT_U32 (skb,L2TP_ATTR_DEBUG , session->debug); -NLA_PUT_U16 (skb,L2TP_ATTR_PW_TYPE , session->pwtype); -NLA_PUT_U16 (skb,L2TP_ATTR_MTU , session->mtu); -if (session->mru) -NLA_PUT_U16 (skb,L2TP_ATTR_MRU , session->mru); - -if (session->ifname && session->ifname[0 ]) -NLA_PUT_STRING (skb,L2TP_ATTR_IFNAME , session->ifname); -if (session->cookie_len) -NLA_PUT (skb,L2TP_ATTR_COOKIE , session->cookie_len, &session->cookie[0 ]); -if (session->peer_cookie_len) -NLA_PUT (skb,L2TP_ATTR_PEER_COOKIE , session->peer_cookie_len, &session->peer_cookie[0 ]); -NLA_PUT_U8 (skb,L2TP_ATTR_RECV_SEQ , session->recv_seq); -NLA_PUT_U8 (skb,L2TP_ATTR_SEND_SEQ , session->send_seq); -NLA_PUT_U8 (skb,L2TP_ATTR_LNS_MODE , session->lns_mode); +if (nla_put_u32 (skb,L2TP_ATTR_CONN_ID , tunnel->tunnel_id) || +nla_put_u32 (skb,L2TP_ATTR_SESSION_ID , session->session_id) || +nla_put_u32 (skb,L2TP_ATTR_PEER_CONN_ID , tunnel->peer_tunnel_id) || +nla_put_u32 (skb,L2TP_ATTR_PEER_SESSION_ID , + session->peer_session_id) || +nla_put_u32 (skb,L2TP_ATTR_DEBUG , session->debug) || +nla_put_u16 (skb,L2TP_ATTR_PW_TYPE , session->pwtype) || +nla_put_u16 (skb,L2TP_ATTR_MTU , session->mtu) || + (session->mru && +nla_put_u16 (skb,L2TP_ATTR_MRU , session->mru))) + goto nla_put_failure; + +if ((session->ifname && session->ifname[0 ] && +nla_put_string (skb,L2TP_ATTR_IFNAME , session->ifname)) || + (session->cookie_len && +nla_put (skb,L2TP_ATTR_COOKIE , session->cookie_len, + &session->cookie[0 ])) || + (session->peer_cookie_len && +nla_put (skb,L2TP_ATTR_PEER_COOKIE , session->peer_cookie_len, + &session->peer_cookie[0 ])) || +nla_put_u8 (skb,L2TP_ATTR_RECV_SEQ , session->recv_seq) || +nla_put_u8 (skb,L2TP_ATTR_SEND_SEQ , session->send_seq) || +nla_put_u8 (skb,L2TP_ATTR_LNS_MODE , session->lns_mode) || #ifdef CONFIG_XFRM -if ((sk) && (sk->sk_policy[0 ] || sk->sk_policy[1 ])) -NLA_PUT_U8 (skb,L2TP_ATTR_USING_IPSEC ,1 ); + (((sk) && (sk->sk_policy[0 ] || sk->sk_policy[1 ])) && +nla_put_u8 (skb,L2TP_ATTR_USING_IPSEC ,1 )) || #endif -if (session->reorder_timeout) -NLA_PUT_MSECS (skb,L2TP_ATTR_RECV_TIMEOUT , session->reorder_timeout); - + (session->reorder_timeout && +nla_put_msecs (skb,L2TP_ATTR_RECV_TIMEOUT , session->reorder_timeout))) + goto nla_put_failure; nest =nla_nest_start (skb,L2TP_ATTR_STATS );if (nest ==NULL ) goto nla_put_failure; -NLA_PUT_U64 (skb,L2TP_ATTR_TX_PACKETS , session->stats.tx_packets); -NLA_PUT_U64 (skb,L2TP_ATTR_TX_BYTES , session->stats.tx_bytes); -NLA_PUT_U64 (skb,L2TP_ATTR_TX_ERRORS , session->stats.tx_errors); -NLA_PUT_U64 (skb,L2TP_ATTR_RX_PACKETS , session->stats.rx_packets); -NLA_PUT_U64 (skb,L2TP_ATTR_RX_BYTES , session->stats.rx_bytes); -NLA_PUT_U64 (skb,L2TP_ATTR_RX_SEQ_DISCARDS , session->stats.rx_seq_discards); -NLA_PUT_U64 (skb,L2TP_ATTR_RX_OOS_PACKETS , session->stats.rx_oos_packets); -NLA_PUT_U64 (skb,L2TP_ATTR_RX_ERRORS , session->stats.rx_errors); +if (nla_put_u64 (skb,L2TP_ATTR_TX_PACKETS , session->stats.tx_packets) || +nla_put_u64 (skb,L2TP_ATTR_TX_BYTES , session->stats.tx_bytes) || +nla_put_u64 (skb,L2TP_ATTR_TX_ERRORS , session->stats.tx_errors) || +nla_put_u64 (skb,L2TP_ATTR_RX_PACKETS , session->stats.rx_packets) || +nla_put_u64 (skb,L2TP_ATTR_RX_BYTES , session->stats.rx_bytes) || +nla_put_u64 (skb,L2TP_ATTR_RX_SEQ_DISCARDS , + session->stats.rx_seq_discards) || +nla_put_u64 (skb,L2TP_ATTR_RX_OOS_PACKETS , + session->stats.rx_oos_packets) || +nla_put_u64 (skb,L2TP_ATTR_RX_ERRORS , session->stats.rx_errors)) + goto nla_put_failure;nla_nest_end (skb, nest);return genlmsg_end (skb, hdr);
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 25/51 dcbnl: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/dcb/dcbnl.c | 72 ++++++++++++++++++++++++++++++++----------------------- 1 files changed, 42 insertions(+), 30 deletions(-)
net/dcb/dcbnl.c +42 -30
@@ -1205,13 +1205,15 @@ static int dcbnl_build_peer_app(struct net_device *netdev, struct sk_buff* skb,if (!app) goto nla_put_failure; -if (app_info_type) -NLA_PUT (skb, app_info_type,sizeof (info), &info); - -for (i =0 ; i < app_count; i++) -NLA_PUT (skb, app_entry_type,sizeof (struct dcb_app ), - &table[i]); +if (app_info_type && +nla_put (skb, app_info_type,sizeof (info), &info)) + goto nla_put_failure; +for (i =0 ; i < app_count; i++) { +if (nla_put (skb, app_entry_type,sizeof (struct dcb_app ), + &table[i])) + goto nla_put_failure; + }nla_nest_end (skb, app); } err =0 ;
@@ -1230,8 +1232,8 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)int dcbx;int err = -EMSGSIZE ; -NLA_PUT_STRING (skb,DCB_ATTR_IFNAME , netdev->name); - +if (nla_put_string (skb,DCB_ATTR_IFNAME , netdev->name)) + goto nla_put_failure; ieee =nla_nest_start (skb,DCB_ATTR_IEEE );if (!ieee) goto nla_put_failure;
@@ -1239,15 +1241,17 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)if (ops->ieee_getets) {struct ieee_ets ets; err = ops->ieee_getets (netdev, &ets); -if (!err) -NLA_PUT (skb,DCB_ATTR_IEEE_ETS ,sizeof (ets), &ets); +if (!err && +nla_put (skb,DCB_ATTR_IEEE_ETS ,sizeof (ets), &ets)) + goto nla_put_failure; }if (ops->ieee_getpfc) {struct ieee_pfc pfc; err = ops->ieee_getpfc (netdev, &pfc); -if (!err) -NLA_PUT (skb,DCB_ATTR_IEEE_PFC ,sizeof (pfc), &pfc); +if (!err && +nla_put (skb,DCB_ATTR_IEEE_PFC ,sizeof (pfc), &pfc)) + goto nla_put_failure; } app =nla_nest_start (skb,DCB_ATTR_IEEE_APP_TABLE );
@@ -1278,15 +1282,17 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)if (ops->ieee_peer_getets) {struct ieee_ets ets; err = ops->ieee_peer_getets (netdev, &ets); -if (!err) -NLA_PUT (skb,DCB_ATTR_IEEE_PEER_ETS ,sizeof (ets), &ets); +if (!err && +nla_put (skb,DCB_ATTR_IEEE_PEER_ETS ,sizeof (ets), &ets)) + goto nla_put_failure; }if (ops->ieee_peer_getpfc) {struct ieee_pfc pfc; err = ops->ieee_peer_getpfc (netdev, &pfc); -if (!err) -NLA_PUT (skb,DCB_ATTR_IEEE_PEER_PFC ,sizeof (pfc), &pfc); +if (!err && +nla_put (skb,DCB_ATTR_IEEE_PEER_PFC ,sizeof (pfc), &pfc)) + goto nla_put_failure; }if (ops->peer_getappinfo && ops->peer_getapptable) {
@@ -1340,10 +1346,11 @@ static int dcbnl_cee_pg_fill(struct sk_buff *skb, struct net_device *dev, ops->getpgtccfgtx (dev, i -DCB_PG_ATTR_TC_0 , &prio, &pgid, &tc_pct, &up_map); -NLA_PUT_U8 (skb,DCB_TC_ATTR_PARAM_PGID , pgid); -NLA_PUT_U8 (skb,DCB_TC_ATTR_PARAM_UP_MAPPING , up_map); -NLA_PUT_U8 (skb,DCB_TC_ATTR_PARAM_STRICT_PRIO , prio); -NLA_PUT_U8 (skb,DCB_TC_ATTR_PARAM_BW_PCT , tc_pct); +if (nla_put_u8 (skb,DCB_TC_ATTR_PARAM_PGID , pgid) || +nla_put_u8 (skb,DCB_TC_ATTR_PARAM_UP_MAPPING , up_map) || +nla_put_u8 (skb,DCB_TC_ATTR_PARAM_STRICT_PRIO , prio) || +nla_put_u8 (skb,DCB_TC_ATTR_PARAM_BW_PCT , tc_pct)) + goto nla_put_failure;nla_nest_end (skb, tc_nest); }
@@ -1356,7 +1363,8 @@ static int dcbnl_cee_pg_fill(struct sk_buff *skb, struct net_device *dev,else ops->getpgbwgcfgtx (dev, i -DCB_PG_ATTR_BW_ID_0 , &tc_pct); -NLA_PUT_U8 (skb, i, tc_pct); +if (nla_put_u8 (skb, i, tc_pct)) + goto nla_put_failure; }nla_nest_end (skb, pg);return 0 ;
@@ -1373,8 +1381,8 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)int dcbx, i, err = -EMSGSIZE ;u8 value; -NLA_PUT_STRING (skb,DCB_ATTR_IFNAME , netdev->name); - +if (nla_put_string (skb,DCB_ATTR_IFNAME , netdev->name)) + goto nla_put_failure; cee =nla_nest_start (skb,DCB_ATTR_CEE );if (!cee) goto nla_put_failure;
@@ -1401,7 +1409,8 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)for (i =DCB_PFC_UP_ATTR_0 ; i <=DCB_PFC_UP_ATTR_7 ; i++) { ops->getpfccfg (netdev, i -DCB_PFC_UP_ATTR_0 , &value); -NLA_PUT_U8 (skb, i, value); +if (nla_put_u8 (skb, i, value)) + goto nla_put_failure; }nla_nest_end (skb, pfc_nest); }
@@ -1454,8 +1463,9 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)for (i =DCB_FEATCFG_ATTR_ALL +1 ; i <=DCB_FEATCFG_ATTR_MAX ; i++) -if (!ops->getfeatcfg (netdev, i, &value)) -NLA_PUT_U8 (skb, i, value); +if (!ops->getfeatcfg (netdev, i, &value) && +nla_put_u8 (skb, i, value)) + goto nla_put_failure;nla_nest_end (skb, feat); }
@@ -1464,15 +1474,17 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)if (ops->cee_peer_getpg) {struct cee_pg pg; err = ops->cee_peer_getpg (netdev, &pg); -if (!err) -NLA_PUT (skb,DCB_ATTR_CEE_PEER_PG ,sizeof (pg), &pg); +if (!err && +nla_put (skb,DCB_ATTR_CEE_PEER_PG ,sizeof (pg), &pg)) + goto nla_put_failure; }if (ops->cee_peer_getpfc) {struct cee_pfc pfc; err = ops->cee_peer_getpfc (netdev, &pfc); -if (!err) -NLA_PUT (skb,DCB_ATTR_CEE_PEER_PFC ,sizeof (pfc), &pfc); +if (!err && +nla_put (skb,DCB_ATTR_CEE_PEER_PFC ,sizeof (pfc), &pfc)) + goto nla_put_failure; }if (ops->peer_getappinfo && ops->peer_getapptable) {
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 23/51 ipset: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- include/linux/netfilter/ipset/ip_set.h | 46 ++++++++++------- include/linux/netfilter/ipset/ip_set_ahash.h | 21 +++++--- net/netfilter/ipset/ip_set_bitmap_ip.c | 33 +++++++------ net/netfilter/ipset/ip_set_bitmap_ipmac.c | 43 +++++++++------- net/netfilter/ipset/ip_set_bitmap_port.c | 29 ++++++----- net/netfilter/ipset/ip_set_core.c | 43 +++++++++------- net/netfilter/ipset/ip_set_hash_ip.c | 20 +++++--- net/netfilter/ipset/ip_set_hash_ipport.c | 37 +++++++------ net/netfilter/ipset/ip_set_hash_ipportip.c | 45 +++++++++-------- net/netfilter/ipset/ip_set_hash_ipportnet.c | 69 +++++++++++++------------ net/netfilter/ipset/ip_set_hash_net.c | 45 +++++++++-------- net/netfilter/ipset/ip_set_hash_netiface.c | 52 ++++++++++--------- net/netfilter/ipset/ip_set_hash_netport.c | 61 ++++++++++++----------- net/netfilter/ipset/ip_set_list_set.c | 23 +++++---- 14 files changed, 309 insertions(+), 258 deletions(-)
include/linux/netfilter/ipset/ip_set.h +26 -20
@@ -411,26 +411,32 @@ ip_set_get_h16(const struct nlattr *attr)#define ipset_nest_start (skb, attr) nla_nest_start(skb, attr | NLA_F_NESTED)#define ipset_nest_end (skb, start) nla_nest_end(skb, start) -#define NLA_PUT_IPADDR4 (skb, type, ipaddr) \ -do { \ - struct nlattr *__nested = ipset_nest_start(skb, type); \ - \ - if (!__nested) \ - goto nla_put_failure; \ - NLA_PUT_NET32(skb, IPSET_ATTR_IPADDR_IPV4, ipaddr); \ - ipset_nest_end(skb, __nested); \ -} while (0) - -#define NLA_PUT_IPADDR6 (skb, type, ipaddrptr) \ -do { \ - struct nlattr *__nested = ipset_nest_start(skb, type); \ - \ - if (!__nested) \ - goto nla_put_failure; \ - NLA_PUT(skb, IPSET_ATTR_IPADDR_IPV6, \ - sizeof(struct in6_addr), ipaddrptr); \ - ipset_nest_end(skb, __nested); \ -} while (0) +static inline int nla_put_ipaddr4 (struct sk_buff *skb,int type,__be32 ipaddr) +{ +struct nlattr *__nested =ipset_nest_start (skb, type); +int ret; + +if (!__nested) +return -EMSGSIZE ; + ret =nla_put_net32 (skb,IPSET_ATTR_IPADDR_IPV4 , ipaddr); +if (!ret) +ipset_nest_end (skb, __nested); +return ret; +} + +static inline int nla_put_ipaddr6 (struct sk_buff *skb,int type,const struct in6_addr *ipaddrptr) +{ +struct nlattr *__nested =ipset_nest_start (skb, type); +int ret; + +if (!__nested) +return -EMSGSIZE ; + ret =nla_put (skb,IPSET_ATTR_IPADDR_IPV6 , +sizeof (struct in6_addr ), ipaddrptr); +if (!ret) +ipset_nest_end (skb, __nested); +return ret; +}/* Get address from skbuff */ static inline __be32
include/linux/netfilter/ipset/ip_set_ahash.h +12 -9
@@ -594,17 +594,20 @@ type_pf_head(struct ip_set *set, struct sk_buff *skb) nested =ipset_nest_start (skb,IPSET_ATTR_DATA );if (!nested) goto nla_put_failure; -NLA_PUT_NET32 (skb,IPSET_ATTR_HASHSIZE , -htonl (jhash_size (h->table->htable_bits))); -NLA_PUT_NET32 (skb,IPSET_ATTR_MAXELEM ,htonl (h->maxelem)); +if (nla_put_net32 (skb,IPSET_ATTR_HASHSIZE , +htonl (jhash_size (h->table->htable_bits))) || +nla_put_net32 (skb,IPSET_ATTR_MAXELEM ,htonl (h->maxelem))) + goto nla_put_failure;#ifdef IP_SET_HASH_WITH_NETMASK -if (h->netmask !=HOST_MASK ) -NLA_PUT_U8 (skb,IPSET_ATTR_NETMASK , h->netmask); +if (h->netmask !=HOST_MASK && +nla_put_u8 (skb,IPSET_ATTR_NETMASK , h->netmask)) + goto nla_put_failure;#endif -NLA_PUT_NET32 (skb,IPSET_ATTR_REFERENCES ,htonl (set->ref -1 )); -NLA_PUT_NET32 (skb,IPSET_ATTR_MEMSIZE ,htonl (memsize)); -if (with_timeout (h->timeout)) -NLA_PUT_NET32 (skb,IPSET_ATTR_TIMEOUT ,htonl (h->timeout)); +if (nla_put_net32 (skb,IPSET_ATTR_REFERENCES ,htonl (set->ref -1 )) || +nla_put_net32 (skb,IPSET_ATTR_MEMSIZE ,htonl (memsize)) || + (with_timeout (h->timeout) && +nla_put_net32 (skb,IPSET_ATTR_TIMEOUT ,htonl (h->timeout)))) + goto nla_put_failure;ipset_nest_end (skb, nested);return 0 ;
net/netfilter/ipset/ip_set_bitmap_ip.c +18 -15
@@ -109,8 +109,9 @@ bitmap_ip_list(const struct ip_set *set, }else goto nla_put_failure; } -NLA_PUT_IPADDR4 (skb,IPSET_ATTR_IP , -htonl (map->first_ip + id * map->hosts)); +if (nla_put_ipaddr4 (skb,IPSET_ATTR_IP , +htonl (map->first_ip + id * map->hosts))) + goto nla_put_failure;ipset_nest_end (skb, nested); }ipset_nest_end (skb, atd);
@@ -194,10 +195,11 @@ bitmap_ip_tlist(const struct ip_set *set, }else goto nla_put_failure; } -NLA_PUT_IPADDR4 (skb,IPSET_ATTR_IP , -htonl (map->first_ip + id * map->hosts)); -NLA_PUT_NET32 (skb,IPSET_ATTR_TIMEOUT , -htonl (ip_set_timeout_get (members[id]))); +if (nla_put_ipaddr4 (skb,IPSET_ATTR_IP , +htonl (map->first_ip + id * map->hosts)) || +nla_put_net32 (skb,IPSET_ATTR_TIMEOUT , +htonl (ip_set_timeout_get (members[id])))) + goto nla_put_failure;ipset_nest_end (skb, nested); }ipset_nest_end (skb, adt);
@@ -334,15 +336,16 @@ bitmap_ip_head(struct ip_set *set, struct sk_buff *skb) nested =ipset_nest_start (skb,IPSET_ATTR_DATA );if (!nested) goto nla_put_failure; -NLA_PUT_IPADDR4 (skb,IPSET_ATTR_IP ,htonl (map->first_ip)); -NLA_PUT_IPADDR4 (skb,IPSET_ATTR_IP_TO ,htonl (map->last_ip)); -if (map->netmask !=32 ) -NLA_PUT_U8 (skb,IPSET_ATTR_NETMASK , map->netmask); -NLA_PUT_NET32 (skb,IPSET_ATTR_REFERENCES ,htonl (set->ref -1 )); -NLA_PUT_NET32 (skb,IPSET_ATTR_MEMSIZE , -htonl (sizeof (*map) + map->memsize)); -if (with_timeout (map->timeout)) -NLA_PUT_NET32 (skb,IPSET_ATTR_TIMEOUT ,htonl (map->timeout)); +if (nla_put_ipaddr4 (skb,IPSET_ATTR_IP ,htonl (map->first_ip)) || +nla_put_ipaddr4 (skb,IPSET_ATTR_IP_TO ,htonl (map->last_ip)) || + (map->netmask !=32 && +nla_put_u8 (skb,IPSET_ATTR_NETMASK , map->netmask)) || +nla_put_net32 (skb,IPSET_ATTR_REFERENCES ,htonl (set->ref -1 )) || +nla_put_net32 (skb,IPSET_ATTR_MEMSIZE , +htonl (sizeof (*map) + map->memsize)) || + (with_timeout (map->timeout) && +nla_put_net32 (skb,IPSET_ATTR_TIMEOUT ,htonl (map->timeout)))) + goto nla_put_failure;ipset_nest_end (skb, nested);return 0 ;
net/netfilter/ipset/ip_set_bitmap_ipmac.c +24 -19
63 lines not on this page · raw message
net/netfilter/ipset/ip_set_bitmap_port.c +16 -13
@@ -96,8 +96,9 @@ bitmap_port_list(const struct ip_set *set, }else goto nla_put_failure; } -NLA_PUT_NET16 (skb,IPSET_ATTR_PORT , -htons (map->first_port + id)); +if (nla_put_net16 (skb,IPSET_ATTR_PORT , +htons (map->first_port + id))) + goto nla_put_failure;ipset_nest_end (skb, nested); }ipset_nest_end (skb, atd);
@@ -183,10 +184,11 @@ bitmap_port_tlist(const struct ip_set *set, }else goto nla_put_failure; } -NLA_PUT_NET16 (skb,IPSET_ATTR_PORT , -htons (map->first_port + id)); -NLA_PUT_NET32 (skb,IPSET_ATTR_TIMEOUT , -htonl (ip_set_timeout_get (members[id]))); +if (nla_put_net16 (skb,IPSET_ATTR_PORT , +htons (map->first_port + id)) || +nla_put_net32 (skb,IPSET_ATTR_TIMEOUT , +htonl (ip_set_timeout_get (members[id])))) + goto nla_put_failure;ipset_nest_end (skb, nested); }ipset_nest_end (skb, adt);
@@ -320,13 +322,14 @@ bitmap_port_head(struct ip_set *set, struct sk_buff *skb) nested =ipset_nest_start (skb,IPSET_ATTR_DATA );if (!nested) goto nla_put_failure; -NLA_PUT_NET16 (skb,IPSET_ATTR_PORT ,htons (map->first_port)); -NLA_PUT_NET16 (skb,IPSET_ATTR_PORT_TO ,htons (map->last_port)); -NLA_PUT_NET32 (skb,IPSET_ATTR_REFERENCES ,htonl (set->ref -1 )); -NLA_PUT_NET32 (skb,IPSET_ATTR_MEMSIZE , -htonl (sizeof (*map) + map->memsize)); -if (with_timeout (map->timeout)) -NLA_PUT_NET32 (skb,IPSET_ATTR_TIMEOUT ,htonl (map->timeout)); +if (nla_put_net16 (skb,IPSET_ATTR_PORT ,htons (map->first_port)) || +nla_put_net16 (skb,IPSET_ATTR_PORT_TO ,htons (map->last_port)) || +nla_put_net32 (skb,IPSET_ATTR_REFERENCES ,htonl (set->ref -1 )) || +nla_put_net32 (skb,IPSET_ATTR_MEMSIZE , +htonl (sizeof (*map) + map->memsize)) || + (with_timeout (map->timeout) && +nla_put_net32 (skb,IPSET_ATTR_TIMEOUT ,htonl (map->timeout)))) + goto nla_put_failure;ipset_nest_end (skb, nested);return 0 ;
net/netfilter/ipset/ip_set_core.c +24 -19
72 lines not on this page · raw message
net/netfilter/ipset/ip_set_hash_ip.c +12 -8
@@ -81,7 +81,8 @@ hash_ip4_data_zero_out(struct hash_ip4_elem *elem)static inline bool hash_ip4_data_list (struct sk_buff *skb,const struct hash_ip4_elem *data) { -NLA_PUT_IPADDR4 (skb,IPSET_ATTR_IP , data->ip); +if (nla_put_ipaddr4 (skb,IPSET_ATTR_IP , data->ip)) + goto nla_put_failure;return 0 ; nla_put_failure:
@@ -94,9 +95,10 @@ hash_ip4_data_tlist(struct sk_buff *skb, const struct hash_ip4_elem *data)const struct hash_ip4_telem *tdata = (const struct hash_ip4_telem *)data; -NLA_PUT_IPADDR4 (skb,IPSET_ATTR_IP , tdata->ip); -NLA_PUT_NET32 (skb,IPSET_ATTR_TIMEOUT , -htonl (ip_set_timeout_get (tdata->timeout))); +if (nla_put_ipaddr4 (skb,IPSET_ATTR_IP , tdata->ip) || +nla_put_net32 (skb,IPSET_ATTR_TIMEOUT , +htonl (ip_set_timeout_get (tdata->timeout)))) + goto nla_put_failure;return 0 ;
@@ -262,7 +264,8 @@ ip6_netmask(union nf_inet_addr *ip, u8 prefix)static bool hash_ip6_data_list (struct sk_buff *skb,const struct hash_ip6_elem *data) { -NLA_PUT_IPADDR6 (skb,IPSET_ATTR_IP , &data->ip); +if (nla_put_ipaddr6 (skb,IPSET_ATTR_IP , &data->ip.in6)) + goto nla_put_failure;return 0 ; nla_put_failure:
@@ -275,9 +278,10 @@ hash_ip6_data_tlist(struct sk_buff *skb, const struct hash_ip6_elem *data)const struct hash_ip6_telem *e = (const struct hash_ip6_telem *)data; -NLA_PUT_IPADDR6 (skb,IPSET_ATTR_IP , &e->ip); -NLA_PUT_NET32 (skb,IPSET_ATTR_TIMEOUT , -htonl (ip_set_timeout_get (e->timeout))); +if (nla_put_ipaddr6 (skb,IPSET_ATTR_IP , &e->ip.in6) || +nla_put_net32 (skb,IPSET_ATTR_TIMEOUT , +htonl (ip_set_timeout_get (e->timeout)))) + goto nla_put_failure;return 0 ; nla_put_failure:
net/netfilter/ipset/ip_set_hash_ipport.c +20 -17
@@ -93,9 +93,10 @@ static bool hash_ipport4_data_list(struct sk_buff *skb, const struct hash_ipport4_elem *data) { - NLA_PUT_IPADDR4(skb, IPSET_ATTR_IP, data->ip); -NLA_PUT_NET16 (skb,IPSET_ATTR_PORT , data->port); -NLA_PUT_U8 (skb,IPSET_ATTR_PROTO , data->proto); + if (nla_put_ipaddr4(skb, IPSET_ATTR_IP, data->ip) || + nla_put_net16(skb, IPSET_ATTR_PORT, data->port) || + nla_put_u8(skb, IPSET_ATTR_PROTO, data->proto)) + goto nla_put_failure;return 0 ; nla_put_failure:
@@ -109,12 +110,12 @@ hash_ipport4_data_tlist(struct sk_buff *skb,const struct hash_ipport4_telem *tdata = (const struct hash_ipport4_telem *)data; -NLA_PUT_IPADDR4 (skb,IPSET_ATTR_IP , tdata->ip); -NLA_PUT_NET16 (skb,IPSET_ATTR_PORT , tdata->port); -NLA_PUT_U8 (skb,IPSET_ATTR_PROTO , data->proto); -NLA_PUT_NET32 (skb,IPSET_ATTR_TIMEOUT , -htonl (ip_set_timeout_get (tdata->timeout))); - +if (nla_put_ipaddr4 (skb,IPSET_ATTR_IP , tdata->ip) || +nla_put_net16 (skb,IPSET_ATTR_PORT , tdata->port) || +nla_put_u8 (skb,IPSET_ATTR_PROTO , data->proto) || +nla_put_net32 (skb,IPSET_ATTR_TIMEOUT , +htonl (ip_set_timeout_get (tdata->timeout)))) + goto nla_put_failure;return 0 ; nla_put_failure:
@@ -308,9 +309,10 @@ static bool hash_ipport6_data_list(struct sk_buff *skb, const struct hash_ipport6_elem *data) { - NLA_PUT_IPADDR6(skb, IPSET_ATTR_IP, &data->ip); -NLA_PUT_NET16 (skb,IPSET_ATTR_PORT , data->port); -NLA_PUT_U8 (skb,IPSET_ATTR_PROTO , data->proto); + if (nla_put_ipaddr6(skb, IPSET_ATTR_IP, &data->ip.in6) || + nla_put_net16(skb, IPSET_ATTR_PORT, data->port) || + nla_put_u8(skb, IPSET_ATTR_PROTO, data->proto)) + goto nla_put_failure;return 0 ; nla_put_failure:
@@ -324,11 +326,12 @@ hash_ipport6_data_tlist(struct sk_buff *skb,const struct hash_ipport6_telem *e = (const struct hash_ipport6_telem *)data; -NLA_PUT_IPADDR6 (skb,IPSET_ATTR_IP , &e->ip); -NLA_PUT_NET16 (skb,IPSET_ATTR_PORT , data->port); -NLA_PUT_U8 (skb,IPSET_ATTR_PROTO , data->proto); -NLA_PUT_NET32 (skb,IPSET_ATTR_TIMEOUT , -htonl (ip_set_timeout_get (e->timeout))); +if (nla_put_ipaddr6 (skb,IPSET_ATTR_IP , &e->ip.in6) || +nla_put_net16 (skb,IPSET_ATTR_PORT , data->port) || +nla_put_u8 (skb,IPSET_ATTR_PROTO , data->proto) || +nla_put_net32 (skb,IPSET_ATTR_TIMEOUT , +htonl (ip_set_timeout_get (e->timeout)))) + goto nla_put_failure;return 0 ; nla_put_failure:
net/netfilter/ipset/ip_set_hash_ipportip.c +24 -21
69 lines not on this page · raw message
net/netfilter/ipset/ip_set_hash_ipportnet.c +36 -33
93 lines not on this page · raw message
net/netfilter/ipset/ip_set_hash_net.c +24 -21
69 lines not on this page · raw message
net/netfilter/ipset/ip_set_hash_netiface.c +28 -24
76 lines not on this page · raw message
net/netfilter/ipset/ip_set_hash_netport.c +32 -29
85 lines not on this page · raw message
net/netfilter/ipset/ip_set_list_set.c +13 -10
@@ -402,12 +402,13 @@ list_set_head(struct ip_set *set, struct sk_buff *skb) nested =ipset_nest_start (skb,IPSET_ATTR_DATA );if (!nested) goto nla_put_failure; -NLA_PUT_NET32 (skb,IPSET_ATTR_SIZE ,htonl (map->size)); -if (with_timeout (map->timeout)) -NLA_PUT_NET32 (skb,IPSET_ATTR_TIMEOUT ,htonl (map->timeout)); -NLA_PUT_NET32 (skb,IPSET_ATTR_REFERENCES ,htonl (set->ref -1 )); -NLA_PUT_NET32 (skb,IPSET_ATTR_MEMSIZE , -htonl (sizeof (*map) + map->size * map->dsize)); +if (nla_put_net32 (skb,IPSET_ATTR_SIZE ,htonl (map->size)) || + (with_timeout (map->timeout) && +nla_put_net32 (skb,IPSET_ATTR_TIMEOUT ,htonl (map->timeout))) || +nla_put_net32 (skb,IPSET_ATTR_REFERENCES ,htonl (set->ref -1 )) || +nla_put_net32 (skb,IPSET_ATTR_MEMSIZE , +htonl (sizeof (*map) + map->size * map->dsize))) + goto nla_put_failure;ipset_nest_end (skb, nested);return 0 ;
@@ -442,13 +443,15 @@ list_set_list(const struct ip_set *set, }else goto nla_put_failure; } -NLA_PUT_STRING (skb,IPSET_ATTR_NAME , -ip_set_name_byindex (e->id)); +if (nla_put_string (skb,IPSET_ATTR_NAME , +ip_set_name_byindex (e->id))) + goto nla_put_failure;if (with_timeout (map->timeout)) {const struct set_telem *te = (const struct set_telem *) e; -NLA_PUT_NET32 (skb,IPSET_ATTR_TIMEOUT , -htonl (ip_set_timeout_get (te->timeout))); +__be32 to =htonl (ip_set_timeout_get (te->timeout)); +if (nla_put_net32 (skb,IPSET_ATTR_TIMEOUT , to)) + goto nla_put_failure; }ipset_nest_end (skb, nested); }
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 28/51 netlink: Add nla_put_le{16,32,64}() helpers.
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
--- include/net/netlink.h | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+), 0 deletions(-)
include/net/netlink.h +33 -0
@@ -794,6 +794,17 @@ static inline int nla_put_net16(struct sk_buff *skb, int attrtype, __be16 value) }/** +* nla_put_le16 - Add a __le16 netlink attribute to a socket buffer +* @skb: socket buffer to add attribute to +* @attrtype: attribute type +* @value: numeric value +*/ +static inline int nla_put_le16 (struct sk_buff *skb,int attrtype,__le16 value) +{ +return nla_put (skb, attrtype,sizeof (__le16), &value); +} + +/** * nla_put_u32 - Add a u32 netlink attribute to a socket buffer * @skb: socket buffer to add attribute to * @attrtype: attribute type
@@ -827,6 +838,17 @@ static inline int nla_put_net32(struct sk_buff *skb, int attrtype, __be32 value) }/** +* nla_put_le32 - Add a __le32 netlink attribute to a socket buffer +* @skb: socket buffer to add attribute to +* @attrtype: attribute type +* @value: numeric value +*/ +static inline int nla_put_le32 (struct sk_buff *skb,int attrtype,__le32 value) +{ +return nla_put (skb, attrtype,sizeof (__le32), &value); +} + +/** * nla_put_u64 - Add a u64 netlink attribute to a socket buffer * @skb: socket buffer to add attribute to * @attrtype: attribute type
@@ -860,6 +882,17 @@ static inline int nla_put_net64(struct sk_buff *skb, int attrtype, __be64 value) }/** +* nla_put_le64 - Add a __le64 netlink attribute to a socket buffer +* @skb: socket buffer to add attribute to +* @attrtype: attribute type +* @value: numeric value +*/ +static inline int nla_put_le64 (struct sk_buff *skb,int attrtype,__le64 value) +{ +return nla_put (skb, attrtype,sizeof (__le64), &value); +} + +/** * nla_put_string - Add a string netlink attribute to a socket buffer * @skb: socket buffer to add attribute to * @attrtype: attribute type
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 27/51 rtnetlink: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/core/rtnetlink.c | 67 ++++++++++++++++++++++++++------------------------ 1 files changed, 35 insertions(+), 32 deletions(-)
net/core/rtnetlink.c +35 -32
@@ -608,7 +608,8 @@ int rtnetlink_put_metrics(struct sk_buff *skb, u32 *metrics)for (i =0 ; i <RTAX_MAX ; i++) {if (metrics[i]) { valid++; -NLA_PUT_U32 (skb, i+1 , metrics[i]); +if (nla_put_u32 (skb, i+1 , metrics[i])) + goto nla_put_failure; } }
@@ -808,7 +809,8 @@ static int rtnl_vf_ports_fill(struct sk_buff *skb, struct net_device *dev) vf_port =nla_nest_start (skb,IFLA_VF_PORT );if (!vf_port) goto nla_put_failure; -NLA_PUT_U32 (skb,IFLA_PORT_VF , vf); +if (nla_put_u32 (skb,IFLA_PORT_VF , vf)) + goto nla_put_failure; err = dev->netdev_ops->ndo_get_vf_port (dev, vf, skb);if (err == -EMSGSIZE ) goto nla_put_failure;
@@ -892,25 +894,22 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev, ifm->ifi_flags =dev_get_flags (dev); ifm->ifi_change = change; -NLA_PUT_STRING (skb,IFLA_IFNAME , dev->name); -NLA_PUT_U32 (skb,IFLA_TXQLEN , dev->tx_queue_len); -NLA_PUT_U8 (skb,IFLA_OPERSTATE , -netif_running (dev) ? dev->operstate :IF_OPER_DOWN ); -NLA_PUT_U8 (skb,IFLA_LINKMODE , dev->link_mode); -NLA_PUT_U32 (skb,IFLA_MTU , dev->mtu); -NLA_PUT_U32 (skb,IFLA_GROUP , dev->group); - -if (dev->ifindex != dev->iflink) -NLA_PUT_U32 (skb,IFLA_LINK , dev->iflink); - -if (dev->master) -NLA_PUT_U32 (skb,IFLA_MASTER , dev->master->ifindex); - -if (dev->qdisc) -NLA_PUT_STRING (skb,IFLA_QDISC , dev->qdisc->ops->id); - -if (dev->ifalias) -NLA_PUT_STRING (skb,IFLA_IFALIAS , dev->ifalias); +if (nla_put_string (skb,IFLA_IFNAME , dev->name) || +nla_put_u32 (skb,IFLA_TXQLEN , dev->tx_queue_len) || +nla_put_u8 (skb,IFLA_OPERSTATE , +netif_running (dev) ? dev->operstate :IF_OPER_DOWN ) || +nla_put_u8 (skb,IFLA_LINKMODE , dev->link_mode) || +nla_put_u32 (skb,IFLA_MTU , dev->mtu) || +nla_put_u32 (skb,IFLA_GROUP , dev->group) || + (dev->ifindex != dev->iflink && +nla_put_u32 (skb,IFLA_LINK , dev->iflink)) || + (dev->master && +nla_put_u32 (skb,IFLA_MASTER , dev->master->ifindex)) || + (dev->qdisc && +nla_put_string (skb,IFLA_QDISC , dev->qdisc->ops->id)) || + (dev->ifalias && +nla_put_string (skb,IFLA_IFALIAS , dev->ifalias))) + goto nla_put_failure;if (1 ) {struct rtnl_link_ifmap map = {
@@ -921,12 +920,14 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev, .dma = dev->dma, .port = dev->if_port, }; -NLA_PUT (skb,IFLA_MAP ,sizeof (map), &map); +if (nla_put (skb,IFLA_MAP ,sizeof (map), &map)) + goto nla_put_failure; }if (dev->addr_len) { -NLA_PUT (skb,IFLA_ADDRESS , dev->addr_len, dev->dev_addr); -NLA_PUT (skb,IFLA_BROADCAST , dev->addr_len, dev->broadcast); +if (nla_put (skb,IFLA_ADDRESS , dev->addr_len, dev->dev_addr) || +nla_put (skb,IFLA_BROADCAST , dev->addr_len, dev->broadcast)) + goto nla_put_failure; } attr = nla_reserve(skb, IFLA_STATS,
@@ -943,8 +944,9 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev, goto nla_put_failure;copy_rtnl_link_stats64 (nla_data (attr), stats); -if (dev->dev.parent && (ext_filter_mask &RTEXT_FILTER_VF )) -NLA_PUT_U32 (skb,IFLA_NUM_VF ,dev_num_vf (dev->dev.parent)); +if (dev->dev.parent && (ext_filter_mask &RTEXT_FILTER_VF ) && +nla_put_u32 (skb,IFLA_NUM_VF ,dev_num_vf (dev->dev.parent))) + goto nla_put_failure;if (dev->netdev_ops->ndo_get_vf_config && dev->dev.parent && (ext_filter_mask &RTEXT_FILTER_VF )) {
@@ -987,12 +989,13 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,nla_nest_cancel (skb, vfinfo); goto nla_put_failure; } -NLA_PUT (skb,IFLA_VF_MAC ,sizeof (vf_mac), &vf_mac); -NLA_PUT (skb,IFLA_VF_VLAN ,sizeof (vf_vlan), &vf_vlan); -NLA_PUT (skb,IFLA_VF_TX_RATE ,sizeof (vf_tx_rate), - &vf_tx_rate); -NLA_PUT (skb,IFLA_VF_SPOOFCHK ,sizeof (vf_spoofchk), - &vf_spoofchk); +if (nla_put (skb,IFLA_VF_MAC ,sizeof (vf_mac), &vf_mac) || +nla_put (skb,IFLA_VF_VLAN ,sizeof (vf_vlan), &vf_vlan) || +nla_put (skb,IFLA_VF_TX_RATE ,sizeof (vf_tx_rate), + &vf_tx_rate) || +nla_put (skb,IFLA_VF_SPOOFCHK ,sizeof (vf_spoofchk), + &vf_spoofchk)) + goto nla_put_failure;nla_nest_end (skb, vf); }nla_nest_end (skb, vfinfo);
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 31/51 infiniband: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- drivers/infiniband/core/netlink.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/infiniband/core/netlink.c +2 -1
@@ -125,7 +125,8 @@ int ibnl_put_attr(struct sk_buff *skb, struct nlmsghdr *nlh,unsigned char *prev_tail; prev_tail =skb_tail_pointer (skb); -NLA_PUT (skb, type, len, data); +if (nla_put (skb, type, len, data)) + goto nla_put_failure; nlh->nlmsg_len +=skb_tail_pointer (skb) - prev_tail;return 0 ;
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 30/51 crypto: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- crypto/ablkcipher.c | 12 ++++++------ crypto/aead.c | 12 ++++++------ crypto/ahash.c | 6 +++--- crypto/blkcipher.c | 6 +++--- crypto/crypto_user.c | 22 +++++++++++----------- crypto/pcompress.c | 6 +++--- crypto/rng.c | 6 +++--- crypto/shash.c | 6 +++--- 8 files changed, 38 insertions(+), 38 deletions(-)
crypto/ablkcipher.c +6 -6
@@ -397,9 +397,9 @@ static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg) rblkcipher.max_keysize = alg->cra_ablkcipher.max_keysize; rblkcipher.ivsize = alg->cra_ablkcipher.ivsize; -NLA_PUT (skb,CRYPTOCFGA_REPORT_BLKCIPHER , -sizeof (struct crypto_report_blkcipher ), &rblkcipher); - +if (nla_put (skb,CRYPTOCFGA_REPORT_BLKCIPHER , +sizeof (struct crypto_report_blkcipher ), &rblkcipher)) + goto nla_put_failure;return 0 ; nla_put_failure:
@@ -478,9 +478,9 @@ static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg) rblkcipher.max_keysize = alg->cra_ablkcipher.max_keysize; rblkcipher.ivsize = alg->cra_ablkcipher.ivsize; -NLA_PUT (skb,CRYPTOCFGA_REPORT_BLKCIPHER , -sizeof (struct crypto_report_blkcipher ), &rblkcipher); - +if (nla_put (skb,CRYPTOCFGA_REPORT_BLKCIPHER , +sizeof (struct crypto_report_blkcipher ), &rblkcipher)) + goto nla_put_failure;return 0 ; nla_put_failure:
crypto/aead.c +6 -6
@@ -125,9 +125,9 @@ static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg) raead.maxauthsize = aead->maxauthsize; raead.ivsize = aead->ivsize; -NLA_PUT (skb,CRYPTOCFGA_REPORT_AEAD , -sizeof (struct crypto_report_aead ), &raead); - +if (nla_put (skb,CRYPTOCFGA_REPORT_AEAD , +sizeof (struct crypto_report_aead ), &raead)) + goto nla_put_failure;return 0 ; nla_put_failure:
@@ -210,9 +210,9 @@ static int crypto_nivaead_report(struct sk_buff *skb, struct crypto_alg *alg) raead.maxauthsize = aead->maxauthsize; raead.ivsize = aead->ivsize; -NLA_PUT (skb,CRYPTOCFGA_REPORT_AEAD , -sizeof (struct crypto_report_aead ), &raead); - +if (nla_put (skb,CRYPTOCFGA_REPORT_AEAD , +sizeof (struct crypto_report_aead ), &raead)) + goto nla_put_failure;return 0 ; nla_put_failure:
crypto/ahash.c +3 -3
@@ -409,9 +409,9 @@ static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg) rhash.blocksize = alg->cra_blocksize; rhash.digestsize =__crypto_hash_alg_common (alg)->digestsize; -NLA_PUT (skb,CRYPTOCFGA_REPORT_HASH , -sizeof (struct crypto_report_hash ), &rhash); - +if (nla_put (skb,CRYPTOCFGA_REPORT_HASH , +sizeof (struct crypto_report_hash ), &rhash)) + goto nla_put_failure;return 0 ; nla_put_failure:
crypto/blkcipher.c +3 -3
@@ -508,9 +508,9 @@ static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg) rblkcipher.max_keysize = alg->cra_blkcipher.max_keysize; rblkcipher.ivsize = alg->cra_blkcipher.ivsize; -NLA_PUT (skb,CRYPTOCFGA_REPORT_BLKCIPHER , -sizeof (struct crypto_report_blkcipher ), &rblkcipher); - +if (nla_put (skb,CRYPTOCFGA_REPORT_BLKCIPHER , +sizeof (struct crypto_report_blkcipher ), &rblkcipher)) + goto nla_put_failure;return 0 ; nla_put_failure:
crypto/crypto_user.c +11 -11
@@ -77,9 +77,9 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg) rcipher.min_keysize = alg->cra_cipher.cia_min_keysize; rcipher.max_keysize = alg->cra_cipher.cia_max_keysize; -NLA_PUT (skb,CRYPTOCFGA_REPORT_CIPHER , -sizeof (struct crypto_report_cipher ), &rcipher); - +if (nla_put (skb,CRYPTOCFGA_REPORT_CIPHER , +sizeof (struct crypto_report_cipher ), &rcipher)) + goto nla_put_failure;return 0 ; nla_put_failure:
@@ -92,9 +92,9 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)snprintf (rcomp.type,CRYPTO_MAX_ALG_NAME ,"%s" ,"compression" ); -NLA_PUT (skb,CRYPTOCFGA_REPORT_COMPRESS , -sizeof (struct crypto_report_comp ), &rcomp); - +if (nla_put (skb,CRYPTOCFGA_REPORT_COMPRESS , +sizeof (struct crypto_report_comp ), &rcomp)) + goto nla_put_failure;return 0 ; nla_put_failure:
@@ -113,16 +113,16 @@ static int crypto_report_one(struct crypto_alg *alg, ualg->cru_flags = alg->cra_flags; ualg->cru_refcnt =atomic_read (&alg->cra_refcnt); -NLA_PUT_U32 (skb,CRYPTOCFGA_PRIORITY_VAL , alg->cra_priority); - +if (nla_put_u32 (skb,CRYPTOCFGA_PRIORITY_VAL , alg->cra_priority)) + goto nla_put_failure;if (alg->cra_flags &CRYPTO_ALG_LARVAL ) {struct crypto_report_larval rl;snprintf (rl.type,CRYPTO_MAX_ALG_NAME ,"%s" ,"larval" ); -NLA_PUT (skb,CRYPTOCFGA_REPORT_LARVAL , -sizeof (struct crypto_report_larval ), &rl); - +if (nla_put (skb,CRYPTOCFGA_REPORT_LARVAL , +sizeof (struct crypto_report_larval ), &rl)) + goto nla_put_failure; goto out; }
crypto/pcompress.c +3 -3
@@ -55,9 +55,9 @@ static int crypto_pcomp_report(struct sk_buff *skb, struct crypto_alg *alg)snprintf (rpcomp.type,CRYPTO_MAX_ALG_NAME ,"%s" ,"pcomp" ); -NLA_PUT (skb,CRYPTOCFGA_REPORT_COMPRESS , -sizeof (struct crypto_report_comp ), &rpcomp); - +if (nla_put (skb,CRYPTOCFGA_REPORT_COMPRESS , +sizeof (struct crypto_report_comp ), &rpcomp)) + goto nla_put_failure;return 0 ; nla_put_failure:
crypto/rng.c +3 -3
@@ -69,9 +69,9 @@ static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg) rrng.seedsize = alg->cra_rng.seedsize; -NLA_PUT (skb,CRYPTOCFGA_REPORT_RNG , -sizeof (struct crypto_report_rng ), &rrng); - +if (nla_put (skb,CRYPTOCFGA_REPORT_RNG , +sizeof (struct crypto_report_rng ), &rrng)) + goto nla_put_failure;return 0 ; nla_put_failure:
crypto/shash.c +3 -3
@@ -534,9 +534,9 @@ static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg) rhash.blocksize = alg->cra_blocksize; rhash.digestsize = salg->digestsize; -NLA_PUT (skb,CRYPTOCFGA_REPORT_HASH , -sizeof (struct crypto_report_hash ), &rhash); - +if (nla_put (skb,CRYPTOCFGA_REPORT_HASH , +sizeof (struct crypto_report_hash ), &rhash)) + goto nla_put_failure;return 0 ; nla_put_failure:
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 26/51 neighbour: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/core/neighbour.c | 75 ++++++++++++++++++++++++++----------------------- 1 files changed, 40 insertions(+), 35 deletions(-)
net/core/neighbour.c +40 -35
@@ -1768,29 +1768,29 @@ static int neightbl_fill_parms(struct sk_buff *skb, struct neigh_parms *parms)if (nest ==NULL )return -ENOBUFS ; -if (parms->dev) -NLA_PUT_U32 (skb,NDTPA_IFINDEX , parms->dev->ifindex); - -NLA_PUT_U32 (skb,NDTPA_REFCNT ,atomic_read (&parms->refcnt)); -NLA_PUT_U32 (skb,NDTPA_QUEUE_LENBYTES , parms->queue_len_bytes); -/* approximative value for deprecated QUEUE_LEN (in packets) */ -NLA_PUT_U32 (skb,NDTPA_QUEUE_LEN , -DIV_ROUND_UP (parms->queue_len_bytes, -SKB_TRUESIZE (ETH_FRAME_LEN ))); -NLA_PUT_U32 (skb,NDTPA_PROXY_QLEN , parms->proxy_qlen); -NLA_PUT_U32 (skb,NDTPA_APP_PROBES , parms->app_probes); -NLA_PUT_U32 (skb,NDTPA_UCAST_PROBES , parms->ucast_probes); -NLA_PUT_U32 (skb,NDTPA_MCAST_PROBES , parms->mcast_probes); -NLA_PUT_MSECS (skb,NDTPA_REACHABLE_TIME , parms->reachable_time); -NLA_PUT_MSECS (skb,NDTPA_BASE_REACHABLE_TIME , - parms->base_reachable_time); -NLA_PUT_MSECS (skb,NDTPA_GC_STALETIME , parms->gc_staletime); -NLA_PUT_MSECS (skb,NDTPA_DELAY_PROBE_TIME , parms->delay_probe_time); -NLA_PUT_MSECS (skb,NDTPA_RETRANS_TIME , parms->retrans_time); -NLA_PUT_MSECS (skb,NDTPA_ANYCAST_DELAY , parms->anycast_delay); -NLA_PUT_MSECS (skb,NDTPA_PROXY_DELAY , parms->proxy_delay); -NLA_PUT_MSECS (skb,NDTPA_LOCKTIME , parms->locktime); - +if ((parms->dev && +nla_put_u32 (skb,NDTPA_IFINDEX , parms->dev->ifindex)) || +nla_put_u32 (skb,NDTPA_REFCNT ,atomic_read (&parms->refcnt)) || +nla_put_u32 (skb,NDTPA_QUEUE_LENBYTES , parms->queue_len_bytes) || +/* approximative value for deprecated QUEUE_LEN (in packets) */ +nla_put_u32 (skb,NDTPA_QUEUE_LEN , +DIV_ROUND_UP (parms->queue_len_bytes, +SKB_TRUESIZE (ETH_FRAME_LEN ))) || +nla_put_u32 (skb,NDTPA_PROXY_QLEN , parms->proxy_qlen) || +nla_put_u32 (skb,NDTPA_APP_PROBES , parms->app_probes) || +nla_put_u32 (skb,NDTPA_UCAST_PROBES , parms->ucast_probes) || +nla_put_u32 (skb,NDTPA_MCAST_PROBES , parms->mcast_probes) || +nla_put_msecs (skb,NDTPA_REACHABLE_TIME , parms->reachable_time) || +nla_put_msecs (skb,NDTPA_BASE_REACHABLE_TIME , + parms->base_reachable_time) || +nla_put_msecs (skb,NDTPA_GC_STALETIME , parms->gc_staletime) || +nla_put_msecs (skb,NDTPA_DELAY_PROBE_TIME , + parms->delay_probe_time) || +nla_put_msecs (skb,NDTPA_RETRANS_TIME , parms->retrans_time) || +nla_put_msecs (skb,NDTPA_ANYCAST_DELAY , parms->anycast_delay) || +nla_put_msecs (skb,NDTPA_PROXY_DELAY , parms->proxy_delay) || +nla_put_msecs (skb,NDTPA_LOCKTIME , parms->locktime)) + goto nla_put_failure;return nla_nest_end (skb, nest); nla_put_failure:
@@ -1815,12 +1815,12 @@ static int neightbl_fill_info(struct sk_buff *skb, struct neigh_table *tbl, ndtmsg->ndtm_pad1 =0 ; ndtmsg->ndtm_pad2 =0 ; -NLA_PUT_STRING (skb,NDTA_NAME , tbl->id); -NLA_PUT_MSECS (skb,NDTA_GC_INTERVAL , tbl->gc_interval); -NLA_PUT_U32 (skb,NDTA_THRESH1 , tbl->gc_thresh1); -NLA_PUT_U32 (skb,NDTA_THRESH2 , tbl->gc_thresh2); -NLA_PUT_U32 (skb,NDTA_THRESH3 , tbl->gc_thresh3); - +if (nla_put_string (skb,NDTA_NAME , tbl->id) || +nla_put_msecs (skb,NDTA_GC_INTERVAL , tbl->gc_interval) || +nla_put_u32 (skb,NDTA_THRESH1 , tbl->gc_thresh1) || +nla_put_u32 (skb,NDTA_THRESH2 , tbl->gc_thresh2) || +nla_put_u32 (skb,NDTA_THRESH3 , tbl->gc_thresh3)) + goto nla_put_failure; {unsigned long now = jiffies;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, ndc.ndtc_hash_mask = ((1 << nht->hash_shift) -1 );rcu_read_unlock_bh (); -NLA_PUT (skb,NDTA_CONFIG ,sizeof (ndc), &ndc); +if (nla_put (skb,NDTA_CONFIG ,sizeof (ndc), &ndc)) + goto nla_put_failure; } {
@@ -1866,7 +1867,8 @@ static int neightbl_fill_info(struct sk_buff *skb, struct neigh_table *tbl, ndst.ndts_forced_gc_runs += st->forced_gc_runs; } -NLA_PUT (skb,NDTA_STATS ,sizeof (ndst), &ndst); +if (nla_put (skb,NDTA_STATS ,sizeof (ndst), &ndst)) + goto nla_put_failure; }BUG_ON (tbl->parms.dev);
@@ -2137,7 +2139,8 @@ static int neigh_fill_info(struct sk_buff *skb, struct neighbour *neigh, ndm->ndm_type = neigh->type; ndm->ndm_ifindex = neigh->dev->ifindex; -NLA_PUT (skb,NDA_DST , neigh->tbl->key_len, neigh->primary_key); +if (nla_put (skb,NDA_DST , neigh->tbl->key_len, neigh->primary_key)) + goto nla_put_failure;read_lock_bh (&neigh->lock); ndm->ndm_state = neigh->nud_state;
@@ -2157,8 +2160,9 @@ static int neigh_fill_info(struct sk_buff *skb, struct neighbour *neigh, ci.ndm_refcnt =atomic_read (&neigh->refcnt) -1 ;read_unlock_bh (&neigh->lock); -NLA_PUT_U32 (skb,NDA_PROBES ,atomic_read (&neigh->probes)); -NLA_PUT (skb,NDA_CACHEINFO ,sizeof (ci), &ci); +if (nla_put_u32 (skb,NDA_PROBES ,atomic_read (&neigh->probes)) || +nla_put (skb,NDA_CACHEINFO ,sizeof (ci), &ci)) + goto nla_put_failure;return nlmsg_end (skb, nlh);
@@ -2187,7 +2191,8 @@ static int pneigh_fill_info(struct sk_buff *skb, struct pneigh_entry *pn, ndm->ndm_ifindex = pn->dev->ifindex; ndm->ndm_state =NUD_NONE ; -NLA_PUT (skb,NDA_DST , tbl->key_len, pn->key); +if (nla_put (skb,NDA_DST , tbl->key_len, pn->key)) + goto nla_put_failure;return nlmsg_end (skb, nlh);
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 29/51 decnet: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/decnet/dn_dev.c | 14 +++++++------- net/decnet/dn_rules.c | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-)
net/decnet/dn_dev.c +7 -7
@@ -695,13 +695,13 @@ static int dn_nl_fill_ifaddr(struct sk_buff *skb, struct dn_ifaddr *ifa, ifm->ifa_scope = ifa->ifa_scope; ifm->ifa_index = ifa->ifa_dev->dev->ifindex; -if (ifa->ifa_address) -NLA_PUT_LE16 (skb,IFA_ADDRESS , ifa->ifa_address); -if (ifa->ifa_local) -NLA_PUT_LE16 (skb,IFA_LOCAL , ifa->ifa_local); -if (ifa->ifa_label[0 ]) -NLA_PUT_STRING (skb,IFA_LABEL , ifa->ifa_label); - +if ((ifa->ifa_address && +nla_put_le16 (skb,IFA_ADDRESS , ifa->ifa_address)) || + (ifa->ifa_local && +nla_put_le16 (skb,IFA_LOCAL , ifa->ifa_local)) || + (ifa->ifa_label[0 ] && +nla_put_string (skb,IFA_LABEL , ifa->ifa_label))) + goto nla_put_failure;return nlmsg_end (skb, nlh); nla_put_failure:
net/decnet/dn_rules.c +5 -5
@@ -204,11 +204,11 @@ static int dn_fib_rule_fill(struct fib_rule *rule, struct sk_buff *skb, frh->src_len = r->src_len; frh->tos =0 ; -if (r->dst_len) -NLA_PUT_LE16 (skb,FRA_DST , r->dst); -if (r->src_len) -NLA_PUT_LE16 (skb,FRA_SRC , r->src); - +if ((r->dst_len && +nla_put_le16 (skb,FRA_DST , r->dst)) || + (r->src_len && +nla_put_le16 (skb,FRA_SRC , r->src))) + goto nla_put_failure;return 0 ; nla_put_failure:
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 32/51 can: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- drivers/net/can/dev.c | 31 ++++++++++++++++--------------- 1 files changed, 16 insertions(+), 15 deletions(-)
drivers/net/can/dev.c +16 -15
@@ -687,18 +687,19 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev)if (priv->do_get_state) priv->do_get_state (dev, &state); -NLA_PUT_U32 (skb,IFLA_CAN_STATE , state); -NLA_PUT (skb,IFLA_CAN_CTRLMODE ,sizeof (cm), &cm); -NLA_PUT_U32 (skb,IFLA_CAN_RESTART_MS , priv->restart_ms); -NLA_PUT (skb,IFLA_CAN_BITTIMING , -sizeof (priv->bittiming), &priv->bittiming); -NLA_PUT (skb,IFLA_CAN_CLOCK ,sizeof (cm), &priv->clock); -if (priv->do_get_berr_counter && !priv->do_get_berr_counter (dev, &bec)) -NLA_PUT (skb,IFLA_CAN_BERR_COUNTER ,sizeof (bec), &bec); -if (priv->bittiming_const) -NLA_PUT (skb,IFLA_CAN_BITTIMING_CONST , -sizeof (*priv->bittiming_const), priv->bittiming_const); - +if (nla_put_u32 (skb,IFLA_CAN_STATE , state) || +nla_put (skb,IFLA_CAN_CTRLMODE ,sizeof (cm), &cm) || +nla_put_u32 (skb,IFLA_CAN_RESTART_MS , priv->restart_ms) || +nla_put (skb,IFLA_CAN_BITTIMING , +sizeof (priv->bittiming), &priv->bittiming) || +nla_put (skb,IFLA_CAN_CLOCK ,sizeof (cm), &priv->clock) || + (priv->do_get_berr_counter && + !priv->do_get_berr_counter (dev, &bec) && +nla_put (skb,IFLA_CAN_BERR_COUNTER ,sizeof (bec), &bec)) || + (priv->bittiming_const && +nla_put (skb,IFLA_CAN_BITTIMING_CONST , +sizeof (*priv->bittiming_const), priv->bittiming_const))) + goto nla_put_failure;return 0 ; nla_put_failure:
@@ -714,9 +715,9 @@ static int can_fill_xstats(struct sk_buff *skb, const struct net_device *dev) {struct can_priv *priv =netdev_priv (dev); -NLA_PUT (skb,IFLA_INFO_XSTATS , -sizeof (priv->can_stats), &priv->can_stats); - +if (nla_put (skb,IFLA_INFO_XSTATS , +sizeof (priv->can_stats), &priv->can_stats)) + goto nla_put_failure;return 0 ; nla_put_failure:
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 33/51 enic: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- drivers/net/ethernet/cisco/enic/enic_main.c | 22 ++++++++++------------ 1 files changed, 10 insertions(+), 12 deletions(-)
drivers/net/ethernet/cisco/enic/enic_main.c +10 -12
@@ -1193,18 +1193,16 @@ static int enic_get_vf_port(struct net_device *netdev, int vf,if (err)return err; -NLA_PUT_U16 (skb,IFLA_PORT_REQUEST , pp->request); -NLA_PUT_U16 (skb,IFLA_PORT_RESPONSE , response); -if (pp->set &ENIC_SET_NAME ) -NLA_PUT (skb,IFLA_PORT_PROFILE ,PORT_PROFILE_MAX , - pp->name); -if (pp->set &ENIC_SET_INSTANCE ) -NLA_PUT (skb,IFLA_PORT_INSTANCE_UUID ,PORT_UUID_MAX , - pp->instance_uuid); -if (pp->set &ENIC_SET_HOST ) -NLA_PUT (skb,IFLA_PORT_HOST_UUID ,PORT_UUID_MAX , - pp->host_uuid); - +if (nla_put_u16 (skb,IFLA_PORT_REQUEST , pp->request) || +nla_put_u16 (skb,IFLA_PORT_RESPONSE , response) || + ((pp->set &ENIC_SET_NAME ) && +nla_put (skb,IFLA_PORT_PROFILE ,PORT_PROFILE_MAX , pp->name)) || + ((pp->set &ENIC_SET_INSTANCE ) && +nla_put (skb,IFLA_PORT_INSTANCE_UUID ,PORT_UUID_MAX , + pp->instance_uuid)) || + ((pp->set &ENIC_SET_HOST ) && +nla_put (skb,IFLA_PORT_HOST_UUID ,PORT_UUID_MAX , pp->host_uuid))) + goto nla_put_failure;return 0 ; nla_put_failure:
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 34/51 macvlan: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- drivers/net/macvlan.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/net/macvlan.c +2 -1
@@ -773,7 +773,8 @@ static int macvlan_fill_info(struct sk_buff *skb, {struct macvlan_dev *vlan =netdev_priv (dev); -NLA_PUT_U32 (skb,IFLA_MACVLAN_MODE , vlan->mode); +if (nla_put_u32 (skb,IFLA_MACVLAN_MODE , vlan->mode)) + goto nla_put_failure;return 0 ; nla_put_failure:
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 35/51 team: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- drivers/net/team/team.c | 50 +++++++++++++++++++++++++++++----------------- 1 files changed, 31 insertions(+), 19 deletions(-)
drivers/net/team/team.c +31 -19
@@ -1248,7 +1248,8 @@ static int team_nl_fill_options_get(struct sk_buff *skb,if (IS_ERR (hdr))return PTR_ERR (hdr); -NLA_PUT_U32 (skb,TEAM_ATTR_TEAM_IFINDEX , team->dev->ifindex); +if (nla_put_u32 (skb,TEAM_ATTR_TEAM_IFINDEX , team->dev->ifindex)) + goto nla_put_failure; option_list =nla_nest_start (skb,TEAM_ATTR_LIST_OPTION );if (!option_list)return -EMSGSIZE ;
@@ -1263,24 +1264,31 @@ static int team_nl_fill_options_get(struct sk_buff *skb, option_item =nla_nest_start (skb,TEAM_ATTR_ITEM_OPTION );if (!option_item) goto nla_put_failure; -NLA_PUT_STRING (skb,TEAM_ATTR_OPTION_NAME , option->name); +if (nla_put_string (skb,TEAM_ATTR_OPTION_NAME , option->name)) + goto nla_put_failure;if (option->changed) { -NLA_PUT_FLAG (skb,TEAM_ATTR_OPTION_CHANGED ); +if (nla_put_flag (skb,TEAM_ATTR_OPTION_CHANGED )) + goto nla_put_failure; option->changed = false; } -if (option->removed) -NLA_PUT_FLAG (skb,TEAM_ATTR_OPTION_REMOVED ); +if (option->removed && +nla_put_flag (skb,TEAM_ATTR_OPTION_REMOVED )) + goto nla_put_failure;switch (option->type) {case TEAM_OPTION_TYPE_U32 : -NLA_PUT_U8 (skb,TEAM_ATTR_OPTION_TYPE ,NLA_U32 ); +if (nla_put_u8 (skb,TEAM_ATTR_OPTION_TYPE ,NLA_U32 )) + goto nla_put_failure;team_option_get (team, option, &arg); -NLA_PUT_U32 (skb,TEAM_ATTR_OPTION_DATA , arg); +if (nla_put_u32 (skb,TEAM_ATTR_OPTION_DATA , arg)) + goto nla_put_failure;break ;case TEAM_OPTION_TYPE_STRING : -NLA_PUT_U8 (skb,TEAM_ATTR_OPTION_TYPE ,NLA_STRING ); +if (nla_put_u8 (skb,TEAM_ATTR_OPTION_TYPE ,NLA_STRING )) + goto nla_put_failure;team_option_get (team, option, &arg); -NLA_PUT_STRING (skb,TEAM_ATTR_OPTION_DATA , - (char *) arg); +if (nla_put_string (skb,TEAM_ATTR_OPTION_DATA , + (char *) arg)) + goto nla_put_failure;break ;default :BUG ();
@@ -1420,7 +1428,8 @@ static int team_nl_fill_port_list_get(struct sk_buff *skb,if (IS_ERR (hdr))return PTR_ERR (hdr); -NLA_PUT_U32 (skb,TEAM_ATTR_TEAM_IFINDEX , team->dev->ifindex); +if (nla_put_u32 (skb,TEAM_ATTR_TEAM_IFINDEX , team->dev->ifindex)) + goto nla_put_failure; port_list =nla_nest_start (skb,TEAM_ATTR_LIST_PORT );if (!port_list)return -EMSGSIZE ;
@@ -1434,17 +1443,20 @@ static int team_nl_fill_port_list_get(struct sk_buff *skb, port_item =nla_nest_start (skb,TEAM_ATTR_ITEM_PORT );if (!port_item) goto nla_put_failure; -NLA_PUT_U32 (skb,TEAM_ATTR_PORT_IFINDEX , port->dev->ifindex); +if (nla_put_u32 (skb,TEAM_ATTR_PORT_IFINDEX , port->dev->ifindex)) + goto nla_put_failure;if (port->changed) { -NLA_PUT_FLAG (skb,TEAM_ATTR_PORT_CHANGED ); +if (nla_put_flag (skb,TEAM_ATTR_PORT_CHANGED )) + goto nla_put_failure; port->changed = false; } -if (port->removed) -NLA_PUT_FLAG (skb,TEAM_ATTR_PORT_REMOVED ); -if (port->linkup) -NLA_PUT_FLAG (skb,TEAM_ATTR_PORT_LINKUP ); -NLA_PUT_U32 (skb,TEAM_ATTR_PORT_SPEED , port->speed); -NLA_PUT_U8 (skb,TEAM_ATTR_PORT_DUPLEX , port->duplex); +if ((port->removed && +nla_put_flag (skb,TEAM_ATTR_PORT_REMOVED )) || + (port->linkup && +nla_put_flag (skb,TEAM_ATTR_PORT_LINKUP )) || +nla_put_u32 (skb,TEAM_ATTR_PORT_SPEED , port->speed) || +nla_put_u8 (skb,TEAM_ATTR_PORT_DUPLEX , port->duplex)) + goto nla_put_failure;nla_nest_end (skb, port_item); }
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 37/51 netfilter: ipv6: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 9 +++++---- net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c | 12 ++++++------ 2 files changed, 11 insertions(+), 10 deletions(-)
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +5 -4
@@ -278,10 +278,11 @@ static struct nf_hook_ops ipv6_conntrack_ops[] __read_mostly = {static int ipv6_tuple_to_nlattr (struct sk_buff *skb,const struct nf_conntrack_tuple *tuple) { -NLA_PUT (skb,CTA_IP_V6_SRC ,sizeof (u_int32_t) *4 , - &tuple->src.u3.ip6); -NLA_PUT (skb,CTA_IP_V6_DST ,sizeof (u_int32_t) *4 , - &tuple->dst.u3.ip6); +if (nla_put (skb,CTA_IP_V6_SRC ,sizeof (u_int32_t) *4 , + &tuple->src.u3.ip6) || +nla_put (skb,CTA_IP_V6_DST ,sizeof (u_int32_t) *4 , + &tuple->dst.u3.ip6)) + goto nla_put_failure;return 0 ; nla_put_failure:
net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c +6 -6
@@ -234,10 +234,10 @@ icmpv6_error(struct net *net, struct nf_conn *tmpl,static int icmpv6_tuple_to_nlattr (struct sk_buff *skb,const struct nf_conntrack_tuple *t) { -NLA_PUT_BE16 (skb,CTA_PROTO_ICMPV6_ID , t->src.u.icmp.id); -NLA_PUT_U8 (skb,CTA_PROTO_ICMPV6_TYPE , t->dst.u.icmp.type); -NLA_PUT_U8 (skb,CTA_PROTO_ICMPV6_CODE , t->dst.u.icmp.code); - +if (nla_put_be16 (skb,CTA_PROTO_ICMPV6_ID , t->src.u.icmp.id) || +nla_put_u8 (skb,CTA_PROTO_ICMPV6_TYPE , t->dst.u.icmp.type) || +nla_put_u8 (skb,CTA_PROTO_ICMPV6_CODE , t->dst.u.icmp.code)) + goto nla_put_failure;return 0 ; nla_put_failure:
@@ -300,8 +300,8 @@ icmpv6_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data) {const unsigned int *timeout = data; -NLA_PUT_BE32 (skb,CTA_TIMEOUT_ICMPV6_TIMEOUT ,htonl (*timeout /HZ )); - +if (nla_put_be32 (skb,CTA_TIMEOUT_ICMPV6_TIMEOUT ,htonl (*timeout /HZ ))) + goto nla_put_failure;return 0 ; nla_put_failure:
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 36/51 ipv6: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/ipv6/addrconf.c | 32 +++++++++++++++----------------- net/ipv6/fib6_rules.c | 15 +++++++-------- net/ipv6/ip6mr.c | 9 +++++---- net/ipv6/ndisc.c | 5 +++-- net/ipv6/route.c | 38 +++++++++++++++++++++++--------------- 5 files changed, 53 insertions(+), 46 deletions(-)
net/ipv6/addrconf.c +15 -17
@@ -3989,14 +3989,14 @@ static int inet6_fill_ifla6_attrs(struct sk_buff *skb, struct inet6_dev *idev)struct nlattr *nla;struct ifla_cacheinfo ci; -NLA_PUT_U32 (skb,IFLA_INET6_FLAGS , idev->if_flags); - +if (nla_put_u32 (skb,IFLA_INET6_FLAGS , idev->if_flags)) + goto nla_put_failure; ci.max_reasm_len =IPV6_MAXPLEN ; ci.tstamp =cstamp_delta (idev->tstamp); ci.reachable_time =jiffies_to_msecs (idev->nd_parms->reachable_time); ci.retrans_time =jiffies_to_msecs (idev->nd_parms->retrans_time); -NLA_PUT (skb,IFLA_INET6_CACHEINFO ,sizeof (ci), &ci); - +if (nla_put (skb,IFLA_INET6_CACHEINFO ,sizeof (ci), &ci)) + goto nla_put_failure; nla =nla_reserve (skb,IFLA_INET6_CONF ,DEVCONF_MAX *sizeof (s32));if (nla ==NULL ) goto nla_put_failure;
@@ -4061,15 +4061,13 @@ static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev, hdr->ifi_flags =dev_get_flags (dev); hdr->ifi_change =0 ; -NLA_PUT_STRING (skb,IFLA_IFNAME , dev->name); - -if (dev->addr_len) -NLA_PUT (skb,IFLA_ADDRESS , dev->addr_len, dev->dev_addr); - -NLA_PUT_U32 (skb,IFLA_MTU , dev->mtu); -if (dev->ifindex != dev->iflink) -NLA_PUT_U32 (skb,IFLA_LINK , dev->iflink); - +if (nla_put_string (skb,IFLA_IFNAME , dev->name) || + (dev->addr_len && +nla_put (skb,IFLA_ADDRESS , dev->addr_len, dev->dev_addr)) || +nla_put_u32 (skb,IFLA_MTU , dev->mtu) || + (dev->ifindex != dev->iflink && +nla_put_u32 (skb,IFLA_LINK , dev->iflink))) + goto nla_put_failure; protoinfo =nla_nest_start (skb,IFLA_PROTINFO );if (protoinfo ==NULL ) goto nla_put_failure;
@@ -4182,12 +4180,12 @@ static int inet6_fill_prefix(struct sk_buff *skb, struct inet6_dev *idev,if (pinfo->autoconf) pmsg->prefix_flags |=IF_PREFIX_AUTOCONF ; -NLA_PUT (skb,PREFIX_ADDRESS ,sizeof (pinfo->prefix), &pinfo->prefix); - +if (nla_put (skb,PREFIX_ADDRESS ,sizeof (pinfo->prefix), &pinfo->prefix)) + goto nla_put_failure; ci.preferred_time =ntohl (pinfo->prefered); ci.valid_time =ntohl (pinfo->valid); -NLA_PUT (skb,PREFIX_CACHEINFO ,sizeof (ci), &ci); - +if (nla_put (skb,PREFIX_CACHEINFO ,sizeof (ci), &ci)) + goto nla_put_failure;return nlmsg_end (skb, nlh); nla_put_failure:
net/ipv6/fib6_rules.c +7 -8
@@ -215,14 +215,13 @@ static int fib6_rule_fill(struct fib_rule *rule, struct sk_buff *skb, frh->src_len = rule6->src.plen; frh->tos = rule6->tclass; -if (rule6->dst.plen) -NLA_PUT (skb,FRA_DST ,sizeof (struct in6_addr ), - &rule6->dst.addr); - -if (rule6->src.plen) -NLA_PUT (skb,FRA_SRC ,sizeof (struct in6_addr ), - &rule6->src.addr); - +if ((rule6->dst.plen && +nla_put (skb,FRA_DST ,sizeof (struct in6_addr ), + &rule6->dst.addr)) || + (rule6->src.plen && +nla_put (skb,FRA_SRC ,sizeof (struct in6_addr ), + &rule6->src.addr))) + goto nla_put_failure;return 0 ; nla_put_failure:
net/ipv6/ip6mr.c +5 -4
@@ -2216,14 +2216,15 @@ static int ip6mr_fill_mroute(struct mr6_table *mrt, struct sk_buff *skb, rtm->rtm_src_len =128 ; rtm->rtm_tos =0 ; rtm->rtm_table = mrt->id; -NLA_PUT_U32 (skb,RTA_TABLE , mrt->id); +if (nla_put_u32 (skb,RTA_TABLE , mrt->id)) + goto nla_put_failure; rtm->rtm_scope =RT_SCOPE_UNIVERSE ; rtm->rtm_protocol =RTPROT_UNSPEC ; rtm->rtm_flags =0 ; -NLA_PUT (skb,RTA_SRC ,16 , &c->mf6c_origin); -NLA_PUT (skb,RTA_DST ,16 , &c->mf6c_mcastgrp); - +if (nla_put (skb,RTA_SRC ,16 , &c->mf6c_origin) || +nla_put (skb,RTA_DST ,16 , &c->mf6c_mcastgrp)) + goto nla_put_failure;if (__ip6mr_fill_mroute (mrt, skb, c, rtm) <0 ) goto nla_put_failure;
net/ipv6/ndisc.c +3 -2
@@ -1099,8 +1099,9 @@ static void ndisc_ra_useropt(struct sk_buff *ra, struct nd_opt_hdr *opt)memcpy (ndmsg +1 , opt, opt->nd_opt_len <<3 ); -NLA_PUT (skb,NDUSEROPT_SRCADDR ,sizeof (struct in6_addr ), - &ipv6_hdr (ra)->saddr); +if (nla_put (skb,NDUSEROPT_SRCADDR ,sizeof (struct in6_addr ), + &ipv6_hdr (ra)->saddr)) + goto nla_put_failure;nlmsg_end (skb, nlh);rtnl_notify (skb, net,0 ,RTNLGRP_ND_USEROPT ,NULL ,GFP_ATOMIC );
net/ipv6/route.c +23 -15
@@ -2413,7 +2413,8 @@ static int rt6_fill_node(struct net *net,else table =RT6_TABLE_UNSPEC ; rtm->rtm_table = table; -NLA_PUT_U32 (skb,RTA_TABLE , table); +if (nla_put_u32 (skb,RTA_TABLE , table)) + goto nla_put_failure;if (rt->rt6i_flags &RTF_REJECT ) rtm->rtm_type =RTN_UNREACHABLE ;else if (rt->rt6i_flags &RTF_LOCAL )
@@ -2436,16 +2437,20 @@ static int rt6_fill_node(struct net *net, rtm->rtm_flags |=RTM_F_CLONED ;if (dst) { -NLA_PUT (skb,RTA_DST ,16 , dst); +if (nla_put (skb,RTA_DST ,16 , dst)) + goto nla_put_failure; rtm->rtm_dst_len =128 ; }else if (rtm->rtm_dst_len) -NLA_PUT (skb,RTA_DST ,16 , &rt->rt6i_dst.addr); +if (nla_put (skb,RTA_DST ,16 , &rt->rt6i_dst.addr)) + goto nla_put_failure;#ifdef CONFIG_IPV6_SUBTREES if (src) { -NLA_PUT (skb,RTA_SRC ,16 , src); +if (nla_put (skb,RTA_SRC ,16 , src)) + goto nla_put_failure; rtm->rtm_src_len =128 ; - }else if (rtm->rtm_src_len) -NLA_PUT (skb,RTA_SRC ,16 , &rt->rt6i_src.addr); + }else if (rtm->rtm_src_len && +nla_put (skb,RTA_SRC ,16 , &rt->rt6i_src.addr)) + goto nla_put_failure;#endif if (iif) {#ifdef CONFIG_IPV6_MROUTE
@@ -2463,17 +2468,20 @@ static int rt6_fill_node(struct net *net, } } else#endif -NLA_PUT_U32 (skb,RTA_IIF , iif); +if (nla_put_u32 (skb,RTA_IIF , iif)) + goto nla_put_failure; }else if (dst) {struct in6_addr saddr_buf; -if (ip6_route_get_saddr (net, rt, dst,0 , &saddr_buf) ==0 ) -NLA_PUT (skb,RTA_PREFSRC ,16 , &saddr_buf); +if (ip6_route_get_saddr (net, rt, dst,0 , &saddr_buf) ==0 && +nla_put (skb,RTA_PREFSRC ,16 , &saddr_buf)) + goto nla_put_failure; }if (rt->rt6i_prefsrc.plen) {struct in6_addr saddr_buf; saddr_buf = rt->rt6i_prefsrc.addr; -NLA_PUT (skb,RTA_PREFSRC ,16 , &saddr_buf); +if (nla_put (skb,RTA_PREFSRC ,16 , &saddr_buf)) + goto nla_put_failure; }if (rtnetlink_put_metrics (skb,dst_metrics_ptr (&rt->dst)) <0 )
@@ -2489,11 +2497,11 @@ static int rt6_fill_node(struct net *net, }rcu_read_unlock (); -if (rt->dst.dev) -NLA_PUT_U32 (skb,RTA_OIF , rt->dst.dev->ifindex); - -NLA_PUT_U32 (skb,RTA_PRIORITY , rt->rt6i_metric); - +if (rt->dst.dev && +nla_put_u32 (skb,RTA_OIF , rt->dst.dev->ifindex)) + goto nla_put_failure; +if (nla_put_u32 (skb,RTA_PRIORITY , rt->rt6i_metric)) + goto nla_put_failure;if (!(rt->rt6i_flags &RTF_EXPIRES )) expires =0 ;else if (rt->dst.expires - jiffies <INT_MAX )
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 39/51 netfilter: ipv4: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 5 +++-- net/ipv4/netfilter/nf_conntrack_proto_icmp.c | 12 ++++++------ 2 files changed, 9 insertions(+), 8 deletions(-)
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +3 -2
@@ -303,8 +303,9 @@ getorigdst(struct sock *sk, int optval, void __user *user, int *len)static int ipv4_tuple_to_nlattr (struct sk_buff *skb,const struct nf_conntrack_tuple *tuple) { -NLA_PUT_BE32 (skb,CTA_IP_V4_SRC , tuple->src.u3.ip); -NLA_PUT_BE32 (skb,CTA_IP_V4_DST , tuple->dst.u3.ip); +if (nla_put_be32 (skb,CTA_IP_V4_SRC , tuple->src.u3.ip) || +nla_put_be32 (skb,CTA_IP_V4_DST , tuple->dst.u3.ip)) + goto nla_put_failure;return 0 ; nla_put_failure:
net/ipv4/netfilter/nf_conntrack_proto_icmp.c +6 -6
@@ -228,10 +228,10 @@ icmp_error(struct net *net, struct nf_conn *tmpl,static int icmp_tuple_to_nlattr (struct sk_buff *skb,const struct nf_conntrack_tuple *t) { -NLA_PUT_BE16 (skb,CTA_PROTO_ICMP_ID , t->src.u.icmp.id); -NLA_PUT_U8 (skb,CTA_PROTO_ICMP_TYPE , t->dst.u.icmp.type); -NLA_PUT_U8 (skb,CTA_PROTO_ICMP_CODE , t->dst.u.icmp.code); - +if (nla_put_be16 (skb,CTA_PROTO_ICMP_ID , t->src.u.icmp.id) || +nla_put_u8 (skb,CTA_PROTO_ICMP_TYPE , t->dst.u.icmp.type) || +nla_put_u8 (skb,CTA_PROTO_ICMP_CODE , t->dst.u.icmp.code)) + goto nla_put_failure;return 0 ; nla_put_failure:
@@ -293,8 +293,8 @@ icmp_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data) {const unsigned int *timeout = data; -NLA_PUT_BE32 (skb,CTA_TIMEOUT_ICMP_TIMEOUT ,htonl (*timeout /HZ )); - +if (nla_put_be32 (skb,CTA_TIMEOUT_ICMP_TIMEOUT ,htonl (*timeout /HZ ))) + goto nla_put_failure;return 0 ; nla_put_failure:
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 38/51 ipv4: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/ipv4/devinet.c | 20 ++++++++---------- net/ipv4/fib_rules.c | 16 +++++++------- net/ipv4/fib_semantics.c | 47 +++++++++++++++++++++++++-------------------- net/ipv4/ip_gre.c | 23 +++++++++++---------- net/ipv4/ipmr.c | 9 ++++--- net/ipv4/route.c | 45 ++++++++++++++++++++++++++----------------- 6 files changed, 87 insertions(+), 73 deletions(-)
net/ipv4/devinet.c +9 -11
@@ -1267,17 +1267,15 @@ static int inet_fill_ifaddr(struct sk_buff *skb, struct in_ifaddr *ifa, ifm->ifa_scope = ifa->ifa_scope; ifm->ifa_index = ifa->ifa_dev->dev->ifindex; -if (ifa->ifa_address) -NLA_PUT_BE32 (skb,IFA_ADDRESS , ifa->ifa_address); - -if (ifa->ifa_local) -NLA_PUT_BE32 (skb,IFA_LOCAL , ifa->ifa_local); - -if (ifa->ifa_broadcast) -NLA_PUT_BE32 (skb,IFA_BROADCAST , ifa->ifa_broadcast); - -if (ifa->ifa_label[0 ]) -NLA_PUT_STRING (skb,IFA_LABEL , ifa->ifa_label); +if ((ifa->ifa_address && +nla_put_be32 (skb,IFA_ADDRESS , ifa->ifa_address)) || + (ifa->ifa_local && +nla_put_be32 (skb,IFA_LOCAL , ifa->ifa_local)) || + (ifa->ifa_broadcast && +nla_put_be32 (skb,IFA_BROADCAST , ifa->ifa_broadcast)) || + (ifa->ifa_label[0 ] && +nla_put_string (skb,IFA_LABEL , ifa->ifa_label))) + goto nla_put_failure;return nlmsg_end (skb, nlh);
net/ipv4/fib_rules.c +8 -8
@@ -221,15 +221,15 @@ static int fib4_rule_fill(struct fib_rule *rule, struct sk_buff *skb, frh->src_len = rule4->src_len; frh->tos = rule4->tos; -if (rule4->dst_len) -NLA_PUT_BE32 (skb,FRA_DST , rule4->dst); - -if (rule4->src_len) -NLA_PUT_BE32 (skb,FRA_SRC , rule4->src); - +if ((rule4->dst_len && +nla_put_be32 (skb,FRA_DST , rule4->dst)) || + (rule4->src_len && +nla_put_be32 (skb,FRA_SRC , rule4->src))) + goto nla_put_failure;#ifdef CONFIG_IP_ROUTE_CLASSID -if (rule4->tclassid) -NLA_PUT_U32 (skb,FRA_FLOW , rule4->tclassid); +if (rule4->tclassid && +nla_put_u32 (skb,FRA_FLOW , rule4->tclassid)) + goto nla_put_failure;#endif return 0 ;
net/ipv4/fib_semantics.c +26 -21
70 lines not on this page · raw message
net/ipv4/ip_gre.c +12 -11
@@ -1654,17 +1654,18 @@ static int ipgre_fill_info(struct sk_buff *skb, const struct net_device *dev)struct ip_tunnel *t =netdev_priv (dev);struct ip_tunnel_parm *p = &t->parms; -NLA_PUT_U32 (skb,IFLA_GRE_LINK , p->link); -NLA_PUT_BE16 (skb,IFLA_GRE_IFLAGS , p->i_flags); -NLA_PUT_BE16 (skb,IFLA_GRE_OFLAGS , p->o_flags); -NLA_PUT_BE32 (skb,IFLA_GRE_IKEY , p->i_key); -NLA_PUT_BE32 (skb,IFLA_GRE_OKEY , p->o_key); -NLA_PUT_BE32 (skb,IFLA_GRE_LOCAL , p->iph.saddr); -NLA_PUT_BE32 (skb,IFLA_GRE_REMOTE , p->iph.daddr); -NLA_PUT_U8 (skb,IFLA_GRE_TTL , p->iph.ttl); -NLA_PUT_U8 (skb,IFLA_GRE_TOS , p->iph.tos); -NLA_PUT_U8 (skb,IFLA_GRE_PMTUDISC , !!(p->iph.frag_off &htons (IP_DF ))); - +if (nla_put_u32 (skb,IFLA_GRE_LINK , p->link) || +nla_put_be16 (skb,IFLA_GRE_IFLAGS , p->i_flags) || +nla_put_be16 (skb,IFLA_GRE_OFLAGS , p->o_flags) || +nla_put_be32 (skb,IFLA_GRE_IKEY , p->i_key) || +nla_put_be32 (skb,IFLA_GRE_OKEY , p->o_key) || +nla_put_be32 (skb,IFLA_GRE_LOCAL , p->iph.saddr) || +nla_put_be32 (skb,IFLA_GRE_REMOTE , p->iph.daddr) || +nla_put_u8 (skb,IFLA_GRE_TTL , p->iph.ttl) || +nla_put_u8 (skb,IFLA_GRE_TOS , p->iph.tos) || +nla_put_u8 (skb,IFLA_GRE_PMTUDISC , + !!(p->iph.frag_off &htons (IP_DF )))) + goto nla_put_failure;return 0 ; nla_put_failure:
net/ipv4/ipmr.c +5 -4
@@ -2120,15 +2120,16 @@ static int ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb, rtm->rtm_src_len =32 ; rtm->rtm_tos =0 ; rtm->rtm_table = mrt->id; -NLA_PUT_U32 (skb,RTA_TABLE , mrt->id); +if (nla_put_u32 (skb,RTA_TABLE , mrt->id)) + goto nla_put_failure; rtm->rtm_type =RTN_MULTICAST ; rtm->rtm_scope =RT_SCOPE_UNIVERSE ; rtm->rtm_protocol =RTPROT_UNSPEC ; rtm->rtm_flags =0 ; -NLA_PUT_BE32 (skb,RTA_SRC , c->mfc_origin); -NLA_PUT_BE32 (skb,RTA_DST , c->mfc_mcastgrp); - +if (nla_put_be32 (skb,RTA_SRC , c->mfc_origin) || +nla_put_be32 (skb,RTA_DST , c->mfc_mcastgrp)) + goto nla_put_failure;if (__ipmr_fill_mroute (mrt, skb, c, rtm) <0 ) goto nla_put_failure;
net/ipv4/route.c +27 -18
72 lines not on this page · raw message
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 40/51 ieee802154: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/ieee802154/nl-mac.c | 146 +++++++++++++++++++++++------------------------ net/ieee802154/nl-phy.c | 29 +++++----- 2 files changed, 85 insertions(+), 90 deletions(-)
net/ieee802154/nl-mac.c +71 -75
@@ -63,15 +63,14 @@ int ieee802154_nl_assoc_indic(struct net_device *dev,if (!msg)return -ENOBUFS ; -NLA_PUT_STRING (msg,IEEE802154_ATTR_DEV_NAME , dev->name); -NLA_PUT_U32 (msg,IEEE802154_ATTR_DEV_INDEX , dev->ifindex); -NLA_PUT (msg,IEEE802154_ATTR_HW_ADDR ,IEEE802154_ADDR_LEN , - dev->dev_addr); - -NLA_PUT (msg,IEEE802154_ATTR_SRC_HW_ADDR ,IEEE802154_ADDR_LEN , - addr->hwaddr); - -NLA_PUT_U8 (msg,IEEE802154_ATTR_CAPABILITY , cap); +if (nla_put_string (msg,IEEE802154_ATTR_DEV_NAME , dev->name) || +nla_put_u32 (msg,IEEE802154_ATTR_DEV_INDEX , dev->ifindex) || +nla_put (msg,IEEE802154_ATTR_HW_ADDR ,IEEE802154_ADDR_LEN , + dev->dev_addr) || +nla_put (msg,IEEE802154_ATTR_SRC_HW_ADDR ,IEEE802154_ADDR_LEN , + addr->hwaddr) || +nla_put_u8 (msg,IEEE802154_ATTR_CAPABILITY , cap)) + goto nla_put_failure;return ieee802154_nl_mcast (msg, ieee802154_coord_mcgrp.id);
@@ -92,14 +91,13 @@ int ieee802154_nl_assoc_confirm(struct net_device *dev, u16 short_addr,if (!msg)return -ENOBUFS ; -NLA_PUT_STRING (msg,IEEE802154_ATTR_DEV_NAME , dev->name); -NLA_PUT_U32 (msg,IEEE802154_ATTR_DEV_INDEX , dev->ifindex); -NLA_PUT (msg,IEEE802154_ATTR_HW_ADDR ,IEEE802154_ADDR_LEN , - dev->dev_addr); - -NLA_PUT_U16 (msg,IEEE802154_ATTR_SHORT_ADDR , short_addr); -NLA_PUT_U8 (msg,IEEE802154_ATTR_STATUS , status); - +if (nla_put_string (msg,IEEE802154_ATTR_DEV_NAME , dev->name) || +nla_put_u32 (msg,IEEE802154_ATTR_DEV_INDEX , dev->ifindex) || +nla_put (msg,IEEE802154_ATTR_HW_ADDR ,IEEE802154_ADDR_LEN , + dev->dev_addr) || +nla_put_u16 (msg,IEEE802154_ATTR_SHORT_ADDR , short_addr) || +nla_put_u8 (msg,IEEE802154_ATTR_STATUS , status)) + goto nla_put_failure;return ieee802154_nl_mcast (msg, ieee802154_coord_mcgrp.id); nla_put_failure:
@@ -119,20 +117,22 @@ int ieee802154_nl_disassoc_indic(struct net_device *dev,if (!msg)return -ENOBUFS ; -NLA_PUT_STRING (msg,IEEE802154_ATTR_DEV_NAME , dev->name); -NLA_PUT_U32 (msg,IEEE802154_ATTR_DEV_INDEX , dev->ifindex); -NLA_PUT (msg,IEEE802154_ATTR_HW_ADDR ,IEEE802154_ADDR_LEN , - dev->dev_addr); - -if (addr->addr_type ==IEEE802154_ADDR_LONG ) -NLA_PUT (msg,IEEE802154_ATTR_SRC_HW_ADDR ,IEEE802154_ADDR_LEN , - addr->hwaddr); -else -NLA_PUT_U16 (msg,IEEE802154_ATTR_SRC_SHORT_ADDR , - addr->short_addr); - -NLA_PUT_U8 (msg,IEEE802154_ATTR_REASON , reason); - +if (nla_put_string (msg,IEEE802154_ATTR_DEV_NAME , dev->name) || +nla_put_u32 (msg,IEEE802154_ATTR_DEV_INDEX , dev->ifindex) || +nla_put (msg,IEEE802154_ATTR_HW_ADDR ,IEEE802154_ADDR_LEN , + dev->dev_addr)) + goto nla_put_failure; +if (addr->addr_type ==IEEE802154_ADDR_LONG ) { +if (nla_put (msg,IEEE802154_ATTR_SRC_HW_ADDR ,IEEE802154_ADDR_LEN , + addr->hwaddr)) + goto nla_put_failure; + }else { +if (nla_put_u16 (msg,IEEE802154_ATTR_SRC_SHORT_ADDR , + addr->short_addr)) + goto nla_put_failure; + } +if (nla_put_u8 (msg,IEEE802154_ATTR_REASON , reason)) + goto nla_put_failure;return ieee802154_nl_mcast (msg, ieee802154_coord_mcgrp.id); nla_put_failure:
@@ -151,13 +151,12 @@ int ieee802154_nl_disassoc_confirm(struct net_device *dev, u8 status)if (!msg)return -ENOBUFS ; -NLA_PUT_STRING (msg,IEEE802154_ATTR_DEV_NAME , dev->name); -NLA_PUT_U32 (msg,IEEE802154_ATTR_DEV_INDEX , dev->ifindex); -NLA_PUT (msg,IEEE802154_ATTR_HW_ADDR ,IEEE802154_ADDR_LEN , - dev->dev_addr); - -NLA_PUT_U8 (msg,IEEE802154_ATTR_STATUS , status); - +if (nla_put_string (msg,IEEE802154_ATTR_DEV_NAME , dev->name) || +nla_put_u32 (msg,IEEE802154_ATTR_DEV_INDEX , dev->ifindex) || +nla_put (msg,IEEE802154_ATTR_HW_ADDR ,IEEE802154_ADDR_LEN , + dev->dev_addr) || +nla_put_u8 (msg,IEEE802154_ATTR_STATUS , status)) + goto nla_put_failure;return ieee802154_nl_mcast (msg, ieee802154_coord_mcgrp.id); nla_put_failure:
@@ -177,13 +176,13 @@ int ieee802154_nl_beacon_indic(struct net_device *dev,if (!msg)return -ENOBUFS ; -NLA_PUT_STRING (msg,IEEE802154_ATTR_DEV_NAME , dev->name); -NLA_PUT_U32 (msg,IEEE802154_ATTR_DEV_INDEX , dev->ifindex); -NLA_PUT (msg,IEEE802154_ATTR_HW_ADDR ,IEEE802154_ADDR_LEN , - dev->dev_addr); -NLA_PUT_U16 (msg,IEEE802154_ATTR_COORD_SHORT_ADDR , coord_addr); -NLA_PUT_U16 (msg,IEEE802154_ATTR_COORD_PAN_ID , panid); - +if (nla_put_string (msg,IEEE802154_ATTR_DEV_NAME , dev->name) || +nla_put_u32 (msg,IEEE802154_ATTR_DEV_INDEX , dev->ifindex) || +nla_put (msg,IEEE802154_ATTR_HW_ADDR ,IEEE802154_ADDR_LEN , + dev->dev_addr) || +nla_put_u16 (msg,IEEE802154_ATTR_COORD_SHORT_ADDR , coord_addr) || +nla_put_u16 (msg,IEEE802154_ATTR_COORD_PAN_ID , panid)) + goto nla_put_failure;return ieee802154_nl_mcast (msg, ieee802154_coord_mcgrp.id); nla_put_failure:
@@ -204,19 +203,17 @@ int ieee802154_nl_scan_confirm(struct net_device *dev,if (!msg)return -ENOBUFS ; -NLA_PUT_STRING (msg,IEEE802154_ATTR_DEV_NAME , dev->name); -NLA_PUT_U32 (msg,IEEE802154_ATTR_DEV_INDEX , dev->ifindex); -NLA_PUT (msg,IEEE802154_ATTR_HW_ADDR ,IEEE802154_ADDR_LEN , - dev->dev_addr); - -NLA_PUT_U8 (msg,IEEE802154_ATTR_STATUS , status); -NLA_PUT_U8 (msg,IEEE802154_ATTR_SCAN_TYPE , scan_type); -NLA_PUT_U32 (msg,IEEE802154_ATTR_CHANNELS , unscanned); -NLA_PUT_U8 (msg,IEEE802154_ATTR_PAGE , page); - -if (edl) -NLA_PUT (msg,IEEE802154_ATTR_ED_LIST ,27 , edl); - +if (nla_put_string (msg,IEEE802154_ATTR_DEV_NAME , dev->name) || +nla_put_u32 (msg,IEEE802154_ATTR_DEV_INDEX , dev->ifindex) || +nla_put (msg,IEEE802154_ATTR_HW_ADDR ,IEEE802154_ADDR_LEN , + dev->dev_addr) || +nla_put_u8 (msg,IEEE802154_ATTR_STATUS , status) || +nla_put_u8 (msg,IEEE802154_ATTR_SCAN_TYPE , scan_type) || +nla_put_u32 (msg,IEEE802154_ATTR_CHANNELS , unscanned) || +nla_put_u8 (msg,IEEE802154_ATTR_PAGE , page) || + (edl && +nla_put (msg,IEEE802154_ATTR_ED_LIST ,27 , edl))) + goto nla_put_failure;return ieee802154_nl_mcast (msg, ieee802154_coord_mcgrp.id); nla_put_failure:
@@ -235,13 +232,12 @@ int ieee802154_nl_start_confirm(struct net_device *dev, u8 status)if (!msg)return -ENOBUFS ; -NLA_PUT_STRING (msg,IEEE802154_ATTR_DEV_NAME , dev->name); -NLA_PUT_U32 (msg,IEEE802154_ATTR_DEV_INDEX , dev->ifindex); -NLA_PUT (msg,IEEE802154_ATTR_HW_ADDR ,IEEE802154_ADDR_LEN , - dev->dev_addr); - -NLA_PUT_U8 (msg,IEEE802154_ATTR_STATUS , status); - +if (nla_put_string (msg,IEEE802154_ATTR_DEV_NAME , dev->name) || +nla_put_u32 (msg,IEEE802154_ATTR_DEV_INDEX , dev->ifindex) || +nla_put (msg,IEEE802154_ATTR_HW_ADDR ,IEEE802154_ADDR_LEN , + dev->dev_addr) || +nla_put_u8 (msg,IEEE802154_ATTR_STATUS , status)) + goto nla_put_failure;return ieee802154_nl_mcast (msg, ieee802154_coord_mcgrp.id); nla_put_failure:
@@ -266,16 +262,16 @@ static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 pid, phy =ieee802154_mlme_ops (dev)->get_phy (dev);BUG_ON (!phy); -NLA_PUT_STRING (msg,IEEE802154_ATTR_DEV_NAME , dev->name); -NLA_PUT_STRING (msg,IEEE802154_ATTR_PHY_NAME ,wpan_phy_name (phy)); -NLA_PUT_U32 (msg,IEEE802154_ATTR_DEV_INDEX , dev->ifindex); - -NLA_PUT (msg,IEEE802154_ATTR_HW_ADDR ,IEEE802154_ADDR_LEN , - dev->dev_addr); -NLA_PUT_U16 (msg,IEEE802154_ATTR_SHORT_ADDR , -ieee802154_mlme_ops (dev)->get_short_addr (dev)); -NLA_PUT_U16 (msg,IEEE802154_ATTR_PAN_ID , -ieee802154_mlme_ops (dev)->get_pan_id (dev)); +if (nla_put_string (msg,IEEE802154_ATTR_DEV_NAME , dev->name) || +nla_put_string (msg,IEEE802154_ATTR_PHY_NAME ,wpan_phy_name (phy)) || +nla_put_u32 (msg,IEEE802154_ATTR_DEV_INDEX , dev->ifindex) || +nla_put (msg,IEEE802154_ATTR_HW_ADDR ,IEEE802154_ADDR_LEN , + dev->dev_addr) || +nla_put_u16 (msg,IEEE802154_ATTR_SHORT_ADDR , +ieee802154_mlme_ops (dev)->get_short_addr (dev)) || +nla_put_u16 (msg,IEEE802154_ATTR_PAN_ID , +ieee802154_mlme_ops (dev)->get_pan_id (dev))) + goto nla_put_failure;wpan_phy_put (phy);return genlmsg_end (msg, hdr);
net/ieee802154/nl-phy.c +14 -15
@@ -53,18 +53,18 @@ static int ieee802154_nl_fill_phy(struct sk_buff *msg, u32 pid, goto out;mutex_lock (&phy->pib_lock); -NLA_PUT_STRING (msg,IEEE802154_ATTR_PHY_NAME ,wpan_phy_name (phy)); - -NLA_PUT_U8 (msg,IEEE802154_ATTR_PAGE , phy->current_page); -NLA_PUT_U8 (msg,IEEE802154_ATTR_CHANNEL , phy->current_channel); +if (nla_put_string (msg,IEEE802154_ATTR_PHY_NAME ,wpan_phy_name (phy)) || +nla_put_u8 (msg,IEEE802154_ATTR_PAGE , phy->current_page) || +nla_put_u8 (msg,IEEE802154_ATTR_CHANNEL , phy->current_channel)) + goto nla_put_failure;for (i =0 ; i <32 ; i++) {if (phy->channels_supported[i]) buf[pages++] = phy->channels_supported[i] | (i <<27 ); } -if (pages) -NLA_PUT (msg,IEEE802154_ATTR_CHANNEL_PAGE_LIST , - pages *sizeof (uint32_t ), buf); - +if (pages && +nla_put (msg,IEEE802154_ATTR_CHANNEL_PAGE_LIST , + pages *sizeof (uint32_t ), buf)) + goto nla_put_failure;mutex_unlock (&phy->pib_lock);kfree (buf);return genlmsg_end (msg, hdr);
@@ -245,9 +245,9 @@ static int ieee802154_add_iface(struct sk_buff *skb, goto dev_unregister; } -NLA_PUT_STRING (msg,IEEE802154_ATTR_PHY_NAME ,wpan_phy_name (phy)); -NLA_PUT_STRING (msg,IEEE802154_ATTR_DEV_NAME , dev->name); - +if (nla_put_string (msg,IEEE802154_ATTR_PHY_NAME ,wpan_phy_name (phy)) || +nla_put_string (msg,IEEE802154_ATTR_DEV_NAME , dev->name)) + goto nla_put_failure;dev_put (dev);wpan_phy_put (phy);
@@ -333,10 +333,9 @@ static int ieee802154_del_iface(struct sk_buff *skb,rtnl_unlock (); - -NLA_PUT_STRING (msg,IEEE802154_ATTR_PHY_NAME ,wpan_phy_name (phy)); -NLA_PUT_STRING (msg,IEEE802154_ATTR_DEV_NAME , name); - +if (nla_put_string (msg,IEEE802154_ATTR_PHY_NAME ,wpan_phy_name (phy)) || +nla_put_string (msg,IEEE802154_ATTR_DEV_NAME , name)) + goto nla_put_failure;wpan_phy_put (phy);return ieee802154_nl_reply (msg, info);
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 41/51 fib_rules: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/core/fib_rules.c | 32 +++++++++++++++----------------- 1 files changed, 15 insertions(+), 17 deletions(-)
net/core/fib_rules.c +15 -17
@@ -542,7 +542,8 @@ static int fib_nl_fill_rule(struct sk_buff *skb, struct fib_rule *rule, frh =nlmsg_data (nlh); frh->family = ops->family; frh->table = rule->table; -NLA_PUT_U32 (skb,FRA_TABLE , rule->table); +if (nla_put_u32 (skb,FRA_TABLE , rule->table)) + goto nla_put_failure; frh->res1 =0 ; frh->res2 =0 ; frh->action = rule->action;
@@ -553,31 +554,28 @@ static int fib_nl_fill_rule(struct sk_buff *skb, struct fib_rule *rule, frh->flags |=FIB_RULE_UNRESOLVED ;if (rule->iifname[0 ]) { -NLA_PUT_STRING (skb,FRA_IIFNAME , rule->iifname); - +if (nla_put_string (skb,FRA_IIFNAME , rule->iifname)) + goto nla_put_failure;if (rule->iifindex ==-1 ) frh->flags |=FIB_RULE_IIF_DETACHED ; }if (rule->oifname[0 ]) { -NLA_PUT_STRING (skb,FRA_OIFNAME , rule->oifname); - +if (nla_put_string (skb,FRA_OIFNAME , rule->oifname)) + goto nla_put_failure;if (rule->oifindex ==-1 ) frh->flags |=FIB_RULE_OIF_DETACHED ; } -if (rule->pref) -NLA_PUT_U32 (skb,FRA_PRIORITY , rule->pref); - -if (rule->mark) -NLA_PUT_U32 (skb,FRA_FWMARK , rule->mark); - -if (rule->mark_mask || rule->mark) -NLA_PUT_U32 (skb,FRA_FWMASK , rule->mark_mask); - -if (rule->target) -NLA_PUT_U32 (skb,FRA_GOTO , rule->target); - +if ((rule->pref && +nla_put_u32 (skb,FRA_PRIORITY , rule->pref)) || + (rule->mark && +nla_put_u32 (skb,FRA_FWMARK , rule->mark)) || + ((rule->mark_mask || rule->mark) && +nla_put_u32 (skb,FRA_FWMASK , rule->mark_mask)) || + (rule->target && +nla_put_u32 (skb,FRA_GOTO , rule->target))) + goto nla_put_failure;if (ops->fill (rule, skb, frh) <0 ) goto nla_put_failure;
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 42/51 gen_stats: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/core/gen_stats.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
net/core/gen_stats.c +2 -1
@@ -27,7 +27,8 @@static inline int gnet_stats_copy (struct gnet_dump *d,int type,void *buf,int size) { -NLA_PUT (d->skb, type, size, buf); +if (nla_put (d->skb, type, size, buf)) + goto nla_put_failure;return 0 ; nla_put_failure:
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 43/51 caif: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/caif/chnl_net.c | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-)
net/caif/chnl_net.c +7 -7
@@ -421,14 +421,14 @@ static int ipcaif_fill_info(struct sk_buff *skb, const struct net_device *dev)struct chnl_net *priv;u8 loop; priv =netdev_priv (dev); -NLA_PUT_U32 (skb,IFLA_CAIF_IPV4_CONNID , - priv->conn_req.sockaddr.u.dgm.connection_id); -NLA_PUT_U32 (skb,IFLA_CAIF_IPV6_CONNID , - priv->conn_req.sockaddr.u.dgm.connection_id); +if (nla_put_u32 (skb,IFLA_CAIF_IPV4_CONNID , + priv->conn_req.sockaddr.u.dgm.connection_id) || +nla_put_u32 (skb,IFLA_CAIF_IPV6_CONNID , + priv->conn_req.sockaddr.u.dgm.connection_id)) + goto nla_put_failure; loop = priv->conn_req.protocol ==CAIFPROTO_DATAGRAM_LOOP ; -NLA_PUT_U8 (skb,IFLA_CAIF_LOOPBACK , loop); - - +if (nla_put_u8 (skb,IFLA_CAIF_LOOPBACK , loop)) + goto nla_put_failure;return 0 ; nla_put_failure:return -EMSGSIZE ;
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 44/51 bridge: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/bridge/br_fdb.c | 8 ++++---- net/bridge/br_netlink.c | 25 +++++++++++-------------- 2 files changed, 15 insertions(+), 18 deletions(-)
net/bridge/br_fdb.c +4 -4
@@ -487,14 +487,14 @@ static int fdb_fill_info(struct sk_buff *skb, const struct net_bridge *br, ndm->ndm_ifindex = fdb->dst ? fdb->dst->dev->ifindex : br->dev->ifindex; ndm->ndm_state =fdb_to_nud (fdb); -NLA_PUT (skb,NDA_LLADDR ,ETH_ALEN , &fdb->addr); - +if (nla_put (skb,NDA_LLADDR ,ETH_ALEN , &fdb->addr)) + goto nla_put_failure; ci.ndm_used =jiffies_to_clock_t (now - fdb->used); ci.ndm_confirmed =0 ; ci.ndm_updated =jiffies_to_clock_t (now - fdb->updated); ci.ndm_refcnt =0 ; -NLA_PUT (skb,NDA_CACHEINFO ,sizeof (ci), &ci); - +if (nla_put (skb,NDA_CACHEINFO ,sizeof (ci), &ci)) + goto nla_put_failure;return nlmsg_end (skb, nlh); nla_put_failure:
net/bridge/br_netlink.c +11 -14
@@ -60,20 +60,17 @@ static int br_fill_ifinfo(struct sk_buff *skb, const struct net_bridge_port *por hdr->ifi_flags =dev_get_flags (dev); hdr->ifi_change =0 ; -NLA_PUT_STRING (skb,IFLA_IFNAME , dev->name); -NLA_PUT_U32 (skb,IFLA_MASTER , br->dev->ifindex); -NLA_PUT_U32 (skb,IFLA_MTU , dev->mtu); -NLA_PUT_U8 (skb,IFLA_OPERSTATE , operstate); - -if (dev->addr_len) -NLA_PUT (skb,IFLA_ADDRESS , dev->addr_len, dev->dev_addr); - -if (dev->ifindex != dev->iflink) -NLA_PUT_U32 (skb,IFLA_LINK , dev->iflink); - -if (event ==RTM_NEWLINK ) -NLA_PUT_U8 (skb,IFLA_PROTINFO , port->state); - +if (nla_put_string (skb,IFLA_IFNAME , dev->name) || +nla_put_u32 (skb,IFLA_MASTER , br->dev->ifindex) || +nla_put_u32 (skb,IFLA_MTU , dev->mtu) || +nla_put_u8 (skb,IFLA_OPERSTATE , operstate) || + (dev->addr_len && +nla_put (skb,IFLA_ADDRESS , dev->addr_len, dev->dev_addr)) || + (dev->ifindex != dev->iflink && +nla_put_u32 (skb,IFLA_LINK , dev->iflink)) || + (event ==RTM_NEWLINK && +nla_put_u8 (skb,IFLA_PROTINFO , port->state))) + goto nla_put_failure;return nlmsg_end (skb, nlh); nla_put_failure:
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 45/51 vlan: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- net/8021q/vlan_netlink.c | 16 ++++++++++------ 1 files changed, 10 insertions(+), 6 deletions(-)
net/8021q/vlan_netlink.c +10 -6
@@ -166,11 +166,13 @@ static int vlan_fill_info(struct sk_buff *skb, const struct net_device *dev)struct nlattr *nest;unsigned int i; -NLA_PUT_U16 (skb,IFLA_VLAN_ID ,vlan_dev_priv (dev)->vlan_id); +if (nla_put_u16 (skb,IFLA_VLAN_ID ,vlan_dev_priv (dev)->vlan_id)) + goto nla_put_failure;if (vlan->flags) { f.flags = vlan->flags; f.mask = ~0 ; -NLA_PUT (skb,IFLA_VLAN_FLAGS ,sizeof (f), &f); +if (nla_put (skb,IFLA_VLAN_FLAGS ,sizeof (f), &f)) + goto nla_put_failure; }if (vlan->nr_ingress_mappings) { nest =nla_nest_start (skb,IFLA_VLAN_INGRESS_QOS );
@@ -183,8 +185,9 @@ static int vlan_fill_info(struct sk_buff *skb, const struct net_device *dev) m.from = i; m.to = vlan->ingress_priority_map[i]; -NLA_PUT (skb,IFLA_VLAN_QOS_MAPPING , -sizeof (m), &m); +if (nla_put (skb,IFLA_VLAN_QOS_MAPPING , +sizeof (m), &m)) + goto nla_put_failure; }nla_nest_end (skb, nest); }
@@ -202,8 +205,9 @@ static int vlan_fill_info(struct sk_buff *skb, const struct net_device *dev) m.from = pm->priority; m.to = (pm->vlan_qos >>13 ) &0x7 ; -NLA_PUT (skb,IFLA_VLAN_QOS_MAPPING , -sizeof (m), &m); +if (nla_put (skb,IFLA_VLAN_QOS_MAPPING , +sizeof (m), &m)) + goto nla_put_failure; } }nla_nest_end (skb, nest);
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 46/51 ath6kl: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- drivers/net/wireless/ath/ath6kl/testmode.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/ath6kl/testmode.c +3 -2
@@ -55,8 +55,9 @@ void ath6kl_tm_rx_event(struct ath6kl *ar, void *buf, size_t buf_len)ath6kl_warn ("failed to allocate testmode rx skb!\n" );return ; } -NLA_PUT_U32 (skb,ATH6KL_TM_ATTR_CMD ,ATH6KL_TM_CMD_TCMD ); -NLA_PUT (skb,ATH6KL_TM_ATTR_DATA , buf_len, buf); +if (nla_put_u32 (skb,ATH6KL_TM_ATTR_CMD ,ATH6KL_TM_CMD_TCMD ) || +nla_put (skb,ATH6KL_TM_ATTR_DATA , buf_len, buf)) + goto nla_put_failure;cfg80211_testmode_event (skb,GFP_KERNEL );return ;
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 47/51 iwlwifi: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- drivers/net/wireless/iwlwifi/iwl-testmode.c | 71 +++++++++++++++----------- 1 files changed, 41 insertions(+), 30 deletions(-)
drivers/net/wireless/iwlwifi/iwl-testmode.c +41 -30
@@ -184,9 +184,10 @@ static void iwl_testmode_ucode_rx_pkt(struct iwl_priv *priv, "Run out of memory for messages to user space ?\n");return ; } -NLA_PUT_U32 (skb,IWL_TM_ATTR_COMMAND ,IWL_TM_CMD_DEV2APP_UCODE_RX_PKT ); -/* the length doesn't include len_n_flags field, so add it manually */ -NLA_PUT (skb,IWL_TM_ATTR_UCODE_RX_PKT , length +sizeof (__le32), data); +if (nla_put_u32 (skb,IWL_TM_ATTR_COMMAND ,IWL_TM_CMD_DEV2APP_UCODE_RX_PKT ) || +/* the length doesn't include len_n_flags field, so add it manually */ +nla_put (skb,IWL_TM_ATTR_UCODE_RX_PKT , length +sizeof (__le32), data)) + goto nla_put_failure;cfg80211_testmode_event (skb,GFP_ATOMIC );return ;
@@ -314,8 +315,9 @@ static int iwl_testmode_ucode(struct ieee80211_hw *hw, struct nlattr **tb)memcpy (reply_buf, &(pkt->hdr), reply_len);iwl_free_resp (&cmd); -NLA_PUT_U32 (skb,IWL_TM_ATTR_COMMAND ,IWL_TM_CMD_DEV2APP_UCODE_RX_PKT ); -NLA_PUT (skb,IWL_TM_ATTR_UCODE_RX_PKT , reply_len, reply_buf); +if (nla_put_u32 (skb,IWL_TM_ATTR_COMMAND ,IWL_TM_CMD_DEV2APP_UCODE_RX_PKT ) || +nla_put (skb,IWL_TM_ATTR_UCODE_RX_PKT , reply_len, reply_buf)) + goto nla_put_failure;return cfg80211_testmode_reply (skb); nla_put_failure:
@@ -379,7 +381,8 @@ static int iwl_testmode_reg(struct ieee80211_hw *hw, struct nlattr **tb)IWL_ERR (priv,"Memory allocation fail\n" );return -ENOMEM ; } -NLA_PUT_U32 (skb,IWL_TM_ATTR_REG_VALUE32 , val32); +if (nla_put_u32 (skb,IWL_TM_ATTR_REG_VALUE32 , val32)) + goto nla_put_failure; status =cfg80211_testmode_reply (skb);if (status <0 )IWL_ERR (priv,"Error sending msg : %d\n" , status);
@@ -478,10 +481,11 @@ static int iwl_testmode_driver(struct ieee80211_hw *hw, struct nlattr **tb)IWL_ERR (priv,"Memory allocation fail\n" );return -ENOMEM ; } -NLA_PUT_U32 (skb,IWL_TM_ATTR_COMMAND , -IWL_TM_CMD_DEV2APP_SYNC_RSP ); -NLA_PUT (skb,IWL_TM_ATTR_SYNC_RSP , - rsp_data_len, rsp_data_ptr); +if (nla_put_u32 (skb,IWL_TM_ATTR_COMMAND , +IWL_TM_CMD_DEV2APP_SYNC_RSP ) || +nla_put (skb,IWL_TM_ATTR_SYNC_RSP , + rsp_data_len, rsp_data_ptr)) + goto nla_put_failure; status =cfg80211_testmode_reply (skb);if (status <0 )IWL_ERR (priv,"Error sending msg : %d\n" , status);
@@ -536,11 +540,12 @@ static int iwl_testmode_driver(struct ieee80211_hw *hw, struct nlattr **tb)IWL_ERR (priv,"Memory allocation fail\n" );return -ENOMEM ; } -NLA_PUT_U32 (skb,IWL_TM_ATTR_COMMAND , -IWL_TM_CMD_DEV2APP_EEPROM_RSP ); -NLA_PUT (skb,IWL_TM_ATTR_EEPROM , -cfg (priv)->base_params->eeprom_size, - priv->shrd->eeprom); +if (nla_put_u32 (skb,IWL_TM_ATTR_COMMAND , +IWL_TM_CMD_DEV2APP_EEPROM_RSP ) || +nla_put (skb,IWL_TM_ATTR_EEPROM , +cfg (priv)->base_params->eeprom_size, + priv->shrd->eeprom)) + goto nla_put_failure; status =cfg80211_testmode_reply (skb);if (status <0 ) IWL_ERR(priv, "Error sending msg : %d\n",
@@ -566,8 +571,9 @@ static int iwl_testmode_driver(struct ieee80211_hw *hw, struct nlattr **tb)IWL_ERR (priv,"Memory allocation fail\n" );return -ENOMEM ; } -NLA_PUT_U32 (skb,IWL_TM_ATTR_FW_VERSION , - priv->fw->ucode_ver); +if (nla_put_u32 (skb,IWL_TM_ATTR_FW_VERSION , + priv->fw->ucode_ver)) + goto nla_put_failure; status =cfg80211_testmode_reply (skb);if (status <0 )IWL_ERR (priv,"Error sending msg : %d\n" , status);
@@ -582,7 +588,8 @@ static int iwl_testmode_driver(struct ieee80211_hw *hw, struct nlattr **tb)IWL_ERR (priv,"Memory allocation fail\n" );return -ENOMEM ; } -NLA_PUT_U32 (skb,IWL_TM_ATTR_DEVICE_ID , devid); +if (nla_put_u32 (skb,IWL_TM_ATTR_DEVICE_ID , devid)) + goto nla_put_failure; status =cfg80211_testmode_reply (skb);if (status <0 )IWL_ERR (priv,"Error sending msg : %d\n" , status);
@@ -602,9 +609,10 @@ static int iwl_testmode_driver(struct ieee80211_hw *hw, struct nlattr **tb) inst_size = img->sec[IWL_UCODE_SECTION_INST ].len; data_size = img->sec[IWL_UCODE_SECTION_DATA ].len; } -NLA_PUT_U32 (skb,IWL_TM_ATTR_FW_TYPE , priv->shrd->ucode_type); -NLA_PUT_U32 (skb,IWL_TM_ATTR_FW_INST_SIZE , inst_size); -NLA_PUT_U32 (skb,IWL_TM_ATTR_FW_DATA_SIZE , data_size); +if (nla_put_u32 (skb,IWL_TM_ATTR_FW_TYPE , priv->shrd->ucode_type) || +nla_put_u32 (skb,IWL_TM_ATTR_FW_INST_SIZE , inst_size) || +nla_put_u32 (skb,IWL_TM_ATTR_FW_DATA_SIZE , data_size)) + goto nla_put_failure; status =cfg80211_testmode_reply (skb);if (status <0 )IWL_ERR (priv,"Error sending msg : %d\n" , status);
@@ -678,9 +686,10 @@ static int iwl_testmode_trace(struct ieee80211_hw *hw, struct nlattr **tb)iwl_trace_cleanup (priv);return -ENOMEM ; } -NLA_PUT (skb,IWL_TM_ATTR_TRACE_ADDR , -sizeof (priv->testmode_trace.dma_addr), - (u64 *)&priv->testmode_trace.dma_addr); +if (nla_put (skb,IWL_TM_ATTR_TRACE_ADDR , +sizeof (priv->testmode_trace.dma_addr), + (u64 *)&priv->testmode_trace.dma_addr)) + goto nla_put_failure; status =cfg80211_testmode_reply (skb);if (status <0 ) {IWL_ERR (priv,"Error sending msg : %d\n" , status);
@@ -725,9 +734,10 @@ static int iwl_testmode_trace_dump(struct ieee80211_hw *hw, length = priv->testmode_trace.buff_size %DUMP_CHUNK_SIZE ; -NLA_PUT (skb,IWL_TM_ATTR_TRACE_DUMP , length, - priv->testmode_trace.trace_addr + - (DUMP_CHUNK_SIZE * idx)); +if (nla_put (skb,IWL_TM_ATTR_TRACE_DUMP , length, + priv->testmode_trace.trace_addr + + (DUMP_CHUNK_SIZE * idx))) + goto nla_put_failure; idx++; cb->args[4 ] = idx;return 0 ;
@@ -922,9 +932,10 @@ static int iwl_testmode_buffer_dump(struct ieee80211_hw *hw, length = priv->testmode_mem.buff_size %DUMP_CHUNK_SIZE ; -NLA_PUT (skb,IWL_TM_ATTR_BUFFER_DUMP , length, - priv->testmode_mem.buff_addr + - (DUMP_CHUNK_SIZE * idx)); +if (nla_put (skb,IWL_TM_ATTR_BUFFER_DUMP , length, + priv->testmode_mem.buff_addr + + (DUMP_CHUNK_SIZE * idx))) + goto nla_put_failure; idx++; cb->args[4 ] = idx;return 0 ;
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 48/51 mac80211_hwsim: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- drivers/net/wireless/mac80211_hwsim.c | 24 +++++++++++++++--------- 1 files changed, 15 insertions(+), 9 deletions(-)
drivers/net/wireless/mac80211_hwsim.c +15 -9
@@ -582,11 +582,13 @@ static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw, goto nla_put_failure; } -NLA_PUT (skb,HWSIM_ATTR_ADDR_TRANSMITTER , -sizeof (struct mac_address ), data->addresses[1 ].addr); +if (nla_put (skb,HWSIM_ATTR_ADDR_TRANSMITTER , +sizeof (struct mac_address ), data->addresses[1 ].addr)) + goto nla_put_failure;/* We get the skb->data */ -NLA_PUT (skb,HWSIM_ATTR_FRAME , my_skb->len, my_skb->data); +if (nla_put (skb,HWSIM_ATTR_FRAME , my_skb->len, my_skb->data)) + goto nla_put_failure;/* We get the flags for this transmission, and we translate them to wmediumd flags */
@@ -597,7 +599,8 @@ static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,if (info->flags &IEEE80211_TX_CTL_NO_ACK ) hwsim_flags |=HWSIM_TX_CTL_NO_ACK ; -NLA_PUT_U32 (skb,HWSIM_ATTR_FLAGS , hwsim_flags); +if (nla_put_u32 (skb,HWSIM_ATTR_FLAGS , hwsim_flags)) + goto nla_put_failure;/* We get the tx control (rate and retries) info*/
@@ -606,12 +609,14 @@ static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw, tx_attempts[i].count = info->status.rates[i].count; } -NLA_PUT (skb,HWSIM_ATTR_TX_INFO , -sizeof (struct hwsim_tx_rate )*IEEE80211_TX_MAX_RATES , - tx_attempts); +if (nla_put (skb,HWSIM_ATTR_TX_INFO , +sizeof (struct hwsim_tx_rate )*IEEE80211_TX_MAX_RATES , + tx_attempts)) + goto nla_put_failure;/* We create a cookie to identify this skb */ -NLA_PUT_U64 (skb,HWSIM_ATTR_COOKIE , (unsigned long ) my_skb); +if (nla_put_u64 (skb,HWSIM_ATTR_COOKIE , (unsigned long ) my_skb)) + goto nla_put_failure;genlmsg_end (skb, msg_head);genlmsg_unicast (&init_net, skb, dst_pid);
@@ -1108,7 +1113,8 @@ static int mac80211_hwsim_testmode_cmd(struct ieee80211_hw *hw, nla_total_size(sizeof(u32)));if (!skb)return -ENOMEM ; -NLA_PUT_U32 (skb,HWSIM_TM_ATTR_PS , hwsim->ps); +if (nla_put_u32 (skb,HWSIM_TM_ATTR_PS , hwsim->ps)) + goto nla_put_failure;return cfg80211_testmode_reply (skb);default :return -EOPNOTSUPP ;
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 49/51 wl12xx: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- drivers/net/wireless/wl12xx/testmode.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/net/wireless/wl12xx/testmode.c +6 -3
@@ -116,7 +116,8 @@ static int wl1271_tm_cmd_test(struct wl1271 *wl, struct nlattr *tb[]) goto out_sleep; } -NLA_PUT (skb,WL1271_TM_ATTR_DATA , buf_len, buf); +if (nla_put (skb,WL1271_TM_ATTR_DATA , buf_len, buf)) + goto nla_put_failure; ret =cfg80211_testmode_reply (skb);if (ret <0 ) goto out_sleep;
@@ -178,7 +179,8 @@ static int wl1271_tm_cmd_interrogate(struct wl1271 *wl, struct nlattr *tb[]) goto out_free; } -NLA_PUT (skb,WL1271_TM_ATTR_DATA ,sizeof (*cmd), cmd); +if (nla_put (skb,WL1271_TM_ATTR_DATA ,sizeof (*cmd), cmd)) + goto nla_put_failure; ret =cfg80211_testmode_reply (skb);if (ret <0 ) goto out_free;
@@ -297,7 +299,8 @@ static int wl12xx_tm_cmd_get_mac(struct wl1271 *wl, struct nlattr *tb[]) goto out; } -NLA_PUT (skb,WL1271_TM_ATTR_DATA ,ETH_ALEN , mac_addr); +if (nla_put (skb,WL1271_TM_ATTR_DATA ,ETH_ALEN , mac_addr)) + goto nla_put_failure; ret =cfg80211_testmode_reply (skb);if (ret <0 ) goto out;
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 51/51 netlink: Delete all NLA_PUT*() macros.
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
They were error prone due to an embedded goto, and the entire tree has been converted away from using them.
--- include/net/netlink.h | 68 ------------------------------------------------- 1 files changed, 0 insertions(+), 68 deletions(-)
include/net/netlink.h +0 -68
@@ -102,20 +102,6 @@* nla_put_flag(skb, type) add flag attribute to skb * nla_put_msecs(skb, type, jiffies) add msecs attribute to skb * -* Exceptions Based Attribute Construction: -* NLA_PUT(skb, type, len, data) add attribute to skb -* NLA_PUT_U8(skb, type, value) add u8 attribute to skb -* NLA_PUT_U16(skb, type, value) add u16 attribute to skb -* NLA_PUT_U32(skb, type, value) add u32 attribute to skb -* NLA_PUT_U64(skb, type, value) add u64 attribute to skb -* NLA_PUT_STRING(skb, type, str) add string attribute to skb -* NLA_PUT_FLAG(skb, type) add flag attribute to skb -* NLA_PUT_MSECS(skb, type, jiffies) add msecs attribute to skb -* -* The meaning of these functions is equal to their lower case -* variants but they jump to the label nla_put_failure in case -* of a failure. -* * Nested Attributes Construction: * nla_nest_start(skb, type) start a nested attribute * nla_nest_end(skb, nla) finalize a nested attribute
@@ -927,60 +913,6 @@ static inline int nla_put_msecs(struct sk_buff *skb, int attrtype,return nla_put (skb, attrtype,sizeof (u64), &tmp); } -#define NLA_PUT (skb, attrtype, attrlen, data) \ - do { \ - if (unlikely(nla_put(skb, attrtype, attrlen, data) < 0)) \ - goto nla_put_failure; \ - } while(0) - -#define NLA_PUT_TYPE (skb, type, attrtype, value) \ - do { \ - type __tmp = value; \ - NLA_PUT(skb, attrtype, sizeof(type), &__tmp); \ - } while(0) - -#define NLA_PUT_U8 (skb, attrtype, value) \ - NLA_PUT_TYPE(skb, u8, attrtype, value) - -#define NLA_PUT_U16 (skb, attrtype, value) \ - NLA_PUT_TYPE(skb, u16, attrtype, value) - -#define NLA_PUT_LE16 (skb, attrtype, value) \ - NLA_PUT_TYPE(skb, __le16, attrtype, value) - -#define NLA_PUT_BE16 (skb, attrtype, value) \ - NLA_PUT_TYPE(skb, __be16, attrtype, value) - -#define NLA_PUT_NET16 (skb, attrtype, value) \ - NLA_PUT_BE16(skb, attrtype | NLA_F_NET_BYTEORDER, value) - -#define NLA_PUT_U32 (skb, attrtype, value) \ - NLA_PUT_TYPE(skb, u32, attrtype, value) - -#define NLA_PUT_BE32 (skb, attrtype, value) \ - NLA_PUT_TYPE(skb, __be32, attrtype, value) - -#define NLA_PUT_NET32 (skb, attrtype, value) \ - NLA_PUT_BE32(skb, attrtype | NLA_F_NET_BYTEORDER, value) - -#define NLA_PUT_U64 (skb, attrtype, value) \ - NLA_PUT_TYPE(skb, u64, attrtype, value) - -#define NLA_PUT_BE64 (skb, attrtype, value) \ - NLA_PUT_TYPE(skb, __be64, attrtype, value) - -#define NLA_PUT_NET64 (skb, attrtype, value) \ - NLA_PUT_BE64(skb, attrtype | NLA_F_NET_BYTEORDER, value) - -#define NLA_PUT_STRING (skb, attrtype, value) \ - NLA_PUT(skb, attrtype, strlen(value) + 1, value) - -#define NLA_PUT_FLAG (skb, attrtype) \ - NLA_PUT(skb, attrtype, 0, NULL) - -#define NLA_PUT_MSECS (skb, attrtype, jiffies) \ - NLA_PUT_U64(skb, attrtype, jiffies_to_msecs(jiffies)) -/** * nla_get_u32 - return payload of u32 attribute * @nla: u32 netlink attribute
Signature · 1 line
1.7.7.6
David S. Miller
maintainerPATCH 50/51 xfrm: Stop using NLA_PUT*().
In reply to David S. MillerFrom: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
--- include/net/xfrm.h | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
include/net/xfrm.h +3 -2
@@ -1682,8 +1682,9 @@ static inline int xfrm_mark_get(struct nlattr **attrs, struct xfrm_mark *m)static inline int xfrm_mark_put (struct sk_buff *skb,const struct xfrm_mark *m) { -if (m->m | m->v) -NLA_PUT (skb,XFRMA_MARK ,sizeof (struct xfrm_mark ), m); +if ((m->m | m->v) && +nla_put (skb,XFRMA_MARK ,sizeof (struct xfrm_mark ), m)) + goto nla_put_failure;return 0 ; nla_put_failure:
Signature · 1 line
1.7.7.6
Re: [PATCH 21/51] ipvs: Stop using NLA_PUT*().
In reply to David S. MillerQuoted 6 lines · David S. Miller
From: "David S. Miller" <[email protected]>
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit.
Signed-off-by David S. Miller <[email protected]>
Hi Dave,
do you want me to take this patch or do you plan to take it directly?
In any case
David Miller
maintainerRe: [PATCH 21/51] ipvs: Stop using NLA_PUT*().
From: Simon Horman <[email protected]>
Date: Mon, 2 Apr 2012 14:01:49 +0900
Quoted 1 line
do you want me to take this patch or do you plan to take it directly?
I plan to take the whole series, otherwise I can't put the commit in at the end that deletes these interfaces.
Quoted 1 line
Acked-by Simon Horman <[email protected]>
Thanks.
Simon Horman
maintainerRe: [PATCH 21/51] ipvs: Stop using NLA_PUT*().
Quoted 7 lines · David Miller
From: Simon Horman <[email protected]>
Date: Mon, 2 Apr 2012 14:01:49 +0900Quoted 1 line
do you want me to take this patch or do you plan to take it directly?
I plan to take the whole series, otherwise I can't put the commit in at the end that deletes these interfaces.
Thanks, got it.