aboutsummaryrefslogtreecommitdiffstats
path: root/net/l2tp/l2tp_netlink.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2012-04-01 19:59:31 -0400
committerDavid S. Miller <davem@davemloft.net>2012-04-02 04:33:41 -0400
commit60aed2abb3f6a713c3a9beda1436866079ee146c (patch)
treef404292a464d2d110330d3c63c29236d2ffc87bd /net/l2tp/l2tp_netlink.c
parent7cf7899d9ee31c88c86ea8459fc4db4bd11cc240 (diff)
l2tp: Stop using NLA_PUT*().
These macros contain a hidden goto, and are thus extremely error prone and make code hard to audit. Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/l2tp/l2tp_netlink.c')
-rw-r--r--net/l2tp/l2tp_netlink.c114
1 files changed, 64 insertions, 50 deletions
diff --git a/net/l2tp/l2tp_netlink.c b/net/l2tp/l2tp_netlink.c
index 93a41a09458b..bc8c3348f835 100644
--- a/net/l2tp/l2tp_netlink.c
+++ b/net/l2tp/l2tp_netlink.c
@@ -231,24 +231,28 @@ static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 pid, u32 seq, int flags,
231 if (IS_ERR(hdr)) 231 if (IS_ERR(hdr))
232 return PTR_ERR(hdr); 232 return PTR_ERR(hdr);
233 233
234 NLA_PUT_U8(skb, L2TP_ATTR_PROTO_VERSION, tunnel->version); 234 if (nla_put_u8(skb, L2TP_ATTR_PROTO_VERSION, tunnel->version) ||
235 NLA_PUT_U32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id); 235 nla_put_u32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id) ||
236 NLA_PUT_U32(skb, L2TP_ATTR_PEER_CONN_ID, tunnel->peer_tunnel_id); 236 nla_put_u32(skb, L2TP_ATTR_PEER_CONN_ID, tunnel->peer_tunnel_id) ||
237 NLA_PUT_U32(skb, L2TP_ATTR_DEBUG, tunnel->debug); 237 nla_put_u32(skb, L2TP_ATTR_DEBUG, tunnel->debug) ||
238 NLA_PUT_U16(skb, L2TP_ATTR_ENCAP_TYPE, tunnel->encap); 238 nla_put_u16(skb, L2TP_ATTR_ENCAP_TYPE, tunnel->encap))
239 goto nla_put_failure;
239 240
240 nest = nla_nest_start(skb, L2TP_ATTR_STATS); 241 nest = nla_nest_start(skb, L2TP_ATTR_STATS);
241 if (nest == NULL) 242 if (nest == NULL)
242 goto nla_put_failure; 243 goto nla_put_failure;
243 244
244 NLA_PUT_U64(skb, L2TP_ATTR_TX_PACKETS, tunnel->stats.tx_packets); 245 if (nla_put_u64(skb, L2TP_ATTR_TX_PACKETS, tunnel->stats.tx_packets) ||
245 NLA_PUT_U64(skb, L2TP_ATTR_TX_BYTES, tunnel->stats.tx_bytes); 246 nla_put_u64(skb, L2TP_ATTR_TX_BYTES, tunnel->stats.tx_bytes) ||
246 NLA_PUT_U64(skb, L2TP_ATTR_TX_ERRORS, tunnel->stats.tx_errors); 247 nla_put_u64(skb, L2TP_ATTR_TX_ERRORS, tunnel->stats.tx_errors) ||
247 NLA_PUT_U64(skb, L2TP_ATTR_RX_PACKETS, tunnel->stats.rx_packets); 248 nla_put_u64(skb, L2TP_ATTR_RX_PACKETS, tunnel->stats.rx_packets) ||
248 NLA_PUT_U64(skb, L2TP_ATTR_RX_BYTES, tunnel->stats.rx_bytes); 249 nla_put_u64(skb, L2TP_ATTR_RX_BYTES, tunnel->stats.rx_bytes) ||
249 NLA_PUT_U64(skb, L2TP_ATTR_RX_SEQ_DISCARDS, tunnel->stats.rx_seq_discards); 250 nla_put_u64(skb, L2TP_ATTR_RX_SEQ_DISCARDS,
250 NLA_PUT_U64(skb, L2TP_ATTR_RX_OOS_PACKETS, tunnel->stats.rx_oos_packets); 251 tunnel->stats.rx_seq_discards) ||
251 NLA_PUT_U64(skb, L2TP_ATTR_RX_ERRORS, tunnel->stats.rx_errors); 252 nla_put_u64(skb, L2TP_ATTR_RX_OOS_PACKETS,
253 tunnel->stats.rx_oos_packets) ||
254 nla_put_u64(skb, L2TP_ATTR_RX_ERRORS, tunnel->stats.rx_errors))
255 goto nla_put_failure;
252 nla_nest_end(skb, nest); 256 nla_nest_end(skb, nest);
253 257
254 sk = tunnel->sock; 258 sk = tunnel->sock;
@@ -259,13 +263,16 @@ static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 pid, u32 seq, int flags,
259 263
260 switch (tunnel->encap) { 264 switch (tunnel->encap) {
261 case L2TP_ENCAPTYPE_UDP: 265 case L2TP_ENCAPTYPE_UDP:
262 NLA_PUT_U16(skb, L2TP_ATTR_UDP_SPORT, ntohs(inet->inet_sport)); 266 if (nla_put_u16(skb, L2TP_ATTR_UDP_SPORT, ntohs(inet->inet_sport)) ||
263 NLA_PUT_U16(skb, L2TP_ATTR_UDP_DPORT, ntohs(inet->inet_dport)); 267 nla_put_u16(skb, L2TP_ATTR_UDP_DPORT, ntohs(inet->inet_dport)) ||
264 NLA_PUT_U8(skb, L2TP_ATTR_UDP_CSUM, (sk->sk_no_check != UDP_CSUM_NOXMIT)); 268 nla_put_u8(skb, L2TP_ATTR_UDP_CSUM,
269 (sk->sk_no_check != UDP_CSUM_NOXMIT)))
270 goto nla_put_failure;
265 /* NOBREAK */ 271 /* NOBREAK */
266 case L2TP_ENCAPTYPE_IP: 272 case L2TP_ENCAPTYPE_IP:
267 NLA_PUT_BE32(skb, L2TP_ATTR_IP_SADDR, inet->inet_saddr); 273 if (nla_put_be32(skb, L2TP_ATTR_IP_SADDR, inet->inet_saddr) ||
268 NLA_PUT_BE32(skb, L2TP_ATTR_IP_DADDR, inet->inet_daddr); 274 nla_put_be32(skb, L2TP_ATTR_IP_DADDR, inet->inet_daddr))
275 goto nla_put_failure;
269 break; 276 break;
270 } 277 }
271 278
@@ -563,43 +570,50 @@ static int l2tp_nl_session_send(struct sk_buff *skb, u32 pid, u32 seq, int flags
563 if (IS_ERR(hdr)) 570 if (IS_ERR(hdr))
564 return PTR_ERR(hdr); 571 return PTR_ERR(hdr);
565 572
566 NLA_PUT_U32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id); 573 if (nla_put_u32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id) ||
567 NLA_PUT_U32(skb, L2TP_ATTR_SESSION_ID, session->session_id); 574 nla_put_u32(skb, L2TP_ATTR_SESSION_ID, session->session_id) ||
568 NLA_PUT_U32(skb, L2TP_ATTR_PEER_CONN_ID, tunnel->peer_tunnel_id); 575 nla_put_u32(skb, L2TP_ATTR_PEER_CONN_ID, tunnel->peer_tunnel_id) ||
569 NLA_PUT_U32(skb, L2TP_ATTR_PEER_SESSION_ID, session->peer_session_id); 576 nla_put_u32(skb, L2TP_ATTR_PEER_SESSION_ID,
570 NLA_PUT_U32(skb, L2TP_ATTR_DEBUG, session->debug); 577 session->peer_session_id) ||
571 NLA_PUT_U16(skb, L2TP_ATTR_PW_TYPE, session->pwtype); 578 nla_put_u32(skb, L2TP_ATTR_DEBUG, session->debug) ||
572 NLA_PUT_U16(skb, L2TP_ATTR_MTU, session->mtu); 579 nla_put_u16(skb, L2TP_ATTR_PW_TYPE, session->pwtype) ||
573 if (session->mru) 580 nla_put_u16(skb, L2TP_ATTR_MTU, session->mtu) ||
574 NLA_PUT_U16(skb, L2TP_ATTR_MRU, session->mru); 581 (session->mru &&
575 582 nla_put_u16(skb, L2TP_ATTR_MRU, session->mru)))
576 if (session->ifname && session->ifname[0]) 583 goto nla_put_failure;
577 NLA_PUT_STRING(skb, L2TP_ATTR_IFNAME, session->ifname); 584
578 if (session->cookie_len) 585 if ((session->ifname && session->ifname[0] &&
579 NLA_PUT(skb, L2TP_ATTR_COOKIE, session->cookie_len, &session->cookie[0]); 586 nla_put_string(skb, L2TP_ATTR_IFNAME, session->ifname)) ||
580 if (session->peer_cookie_len) 587 (session->cookie_len &&
581 NLA_PUT(skb, L2TP_ATTR_PEER_COOKIE, session->peer_cookie_len, &session->peer_cookie[0]); 588 nla_put(skb, L2TP_ATTR_COOKIE, session->cookie_len,
582 NLA_PUT_U8(skb, L2TP_ATTR_RECV_SEQ, session->recv_seq); 589 &session->cookie[0])) ||
583 NLA_PUT_U8(skb, L2TP_ATTR_SEND_SEQ, session->send_seq); 590 (session->peer_cookie_len &&
584 NLA_PUT_U8(skb, L2TP_ATTR_LNS_MODE, session->lns_mode); 591 nla_put(skb, L2TP_ATTR_PEER_COOKIE, session->peer_cookie_len,
592 &session->peer_cookie[0])) ||
593 nla_put_u8(skb, L2TP_ATTR_RECV_SEQ, session->recv_seq) ||
594 nla_put_u8(skb, L2TP_ATTR_SEND_SEQ, session->send_seq) ||
595 nla_put_u8(skb, L2TP_ATTR_LNS_MODE, session->lns_mode) ||
585#ifdef CONFIG_XFRM 596#ifdef CONFIG_XFRM
586 if ((sk) && (sk->sk_policy[0] || sk->sk_policy[1])) 597 (((sk) && (sk->sk_policy[0] || sk->sk_policy[1])) &&
587 NLA_PUT_U8(skb, L2TP_ATTR_USING_IPSEC, 1); 598 nla_put_u8(skb, L2TP_ATTR_USING_IPSEC, 1)) ||
588#endif 599#endif
589 if (session->reorder_timeout) 600 (session->reorder_timeout &&
590 NLA_PUT_MSECS(skb, L2TP_ATTR_RECV_TIMEOUT, session->reorder_timeout); 601 nla_put_msecs(skb, L2TP_ATTR_RECV_TIMEOUT, session->reorder_timeout)))
591 602 goto nla_put_failure;
592 nest = nla_nest_start(skb, L2TP_ATTR_STATS); 603 nest = nla_nest_start(skb, L2TP_ATTR_STATS);
593 if (nest == NULL) 604 if (nest == NULL)
594 goto nla_put_failure; 605 goto nla_put_failure;
595 NLA_PUT_U64(skb, L2TP_ATTR_TX_PACKETS, session->stats.tx_packets); 606 if (nla_put_u64(skb, L2TP_ATTR_TX_PACKETS, session->stats.tx_packets) ||
596 NLA_PUT_U64(skb, L2TP_ATTR_TX_BYTES, session->stats.tx_bytes); 607 nla_put_u64(skb, L2TP_ATTR_TX_BYTES, session->stats.tx_bytes) ||
597 NLA_PUT_U64(skb, L2TP_ATTR_TX_ERRORS, session->stats.tx_errors); 608 nla_put_u64(skb, L2TP_ATTR_TX_ERRORS, session->stats.tx_errors) ||
598 NLA_PUT_U64(skb, L2TP_ATTR_RX_PACKETS, session->stats.rx_packets); 609 nla_put_u64(skb, L2TP_ATTR_RX_PACKETS, session->stats.rx_packets) ||
599 NLA_PUT_U64(skb, L2TP_ATTR_RX_BYTES, session->stats.rx_bytes); 610 nla_put_u64(skb, L2TP_ATTR_RX_BYTES, session->stats.rx_bytes) ||
600 NLA_PUT_U64(skb, L2TP_ATTR_RX_SEQ_DISCARDS, session->stats.rx_seq_discards); 611 nla_put_u64(skb, L2TP_ATTR_RX_SEQ_DISCARDS,
601 NLA_PUT_U64(skb, L2TP_ATTR_RX_OOS_PACKETS, session->stats.rx_oos_packets); 612 session->stats.rx_seq_discards) ||
602 NLA_PUT_U64(skb, L2TP_ATTR_RX_ERRORS, session->stats.rx_errors); 613 nla_put_u64(skb, L2TP_ATTR_RX_OOS_PACKETS,
614 session->stats.rx_oos_packets) ||
615 nla_put_u64(skb, L2TP_ATTR_RX_ERRORS, session->stats.rx_errors))
616 goto nla_put_failure;
603 nla_nest_end(skb, nest); 617 nla_nest_end(skb, nest);
604 618
605 return genlmsg_end(skb, hdr); 619 return genlmsg_end(skb, hdr);