From: "David S. Miller" <davem@davemloft.net>
To: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>
Subject: [PATCH 06/51] openvswitch: Stop using NLA_PUT*().
Date: Sun, 1 Apr 2012 22:57:56 -0400 [thread overview]
Message-ID: <1333335521-1348-7-git-send-email-davem@davemloft.net> (raw)
In-Reply-To: <1333335521-1348-1-git-send-email-davem@davemloft.net>
From: "David S. Miller" <davem@davemloft.net>
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>
---
net/openvswitch/datapath.c | 34 ++++++++++++++++++++--------------
net/openvswitch/flow.c | 18 +++++++++++-------
2 files changed, 31 insertions(+), 21 deletions(-)
diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index 2c03050..f5ca125 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -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)
diff --git a/net/openvswitch/flow.c b/net/openvswitch/flow.c
index 1252c30..7cb4163 100644
--- a/net/openvswitch/flow.c
+++ b/net/openvswitch/flow.c
@@ -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;
--
1.7.7.6
next prev parent reply other threads:[~2012-04-02 2:59 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-02 2:57 [PATCH 00/51] Get rid of NLA_PUT*() David S. Miller
2012-04-02 2:57 ` [PATCH 01/51] xfrm_user: Stop using NLA_PUT*() David S. Miller
2012-04-02 2:57 ` [PATCH 02/51] wireless: " David S. Miller
2012-04-02 2:57 ` [PATCH 03/51] pkt_sched: " David S. Miller
2012-04-02 2:57 ` [PATCH 04/51] phonet: " David S. Miller
2012-04-02 2:57 ` [PATCH 05/51] netlink: Add nla_put_be{16,32,64}() helpers David S. Miller
2012-04-02 2:57 ` David S. Miller [this message]
2012-04-02 2:57 ` [PATCH 07/51] nfc: Stop using NLA_PUT*() David S. Miller
2012-04-02 2:57 ` [PATCH 08/51] genetlink: " David S. Miller
2012-04-02 2:57 ` [PATCH 09/51] nfnetlink_queue: " David S. Miller
2012-04-02 2:58 ` [PATCH 10/51] nfnetlink_log: " David S. Miller
2012-04-02 2:58 ` [PATCH 11/51] nfnetlink_cttimeout: " David S. Miller
2012-04-02 2:58 ` [PATCH 12/51] nfnetlink_acct: " David S. Miller
2012-04-02 2:58 ` [PATCH 13/51] nf_conntrack_proto_udp{,lite}: " David S. Miller
2012-04-02 2:58 ` [PATCH 14/51] nf_conntrack_proto_tcp: " David S. Miller
2012-04-02 2:58 ` [PATCH 15/51] nf_conntrack_proto_sctp: " David S. Miller
2012-04-02 2:58 ` [PATCH 16/51] nf_conntrack_proto_gre: " David S. Miller
2012-04-02 2:58 ` [PATCH 17/51] nf_conntrack_proto_generic: " David S. Miller
2012-04-02 2:58 ` [PATCH 18/51] nf_conntrack_proto_dccp: " David S. Miller
2012-04-02 2:58 ` [PATCH 19/51] nf_conntrack_netlink: " David S. Miller
2012-04-02 2:58 ` [PATCH 20/51] nf_conntrack_core: " David S. Miller
2012-04-02 2:58 ` [PATCH 21/51] ipvs: " David S. Miller
2012-04-02 5:01 ` Simon Horman
2012-04-02 5:03 ` David Miller
2012-04-02 6:22 ` Simon Horman
2012-04-02 2:58 ` [PATCH 22/51] netlink: Add nla_put_net{16,32,64}() helpers David S. Miller
2012-04-02 2:58 ` [PATCH 23/51] ipset: Stop using NLA_PUT*() David S. Miller
2012-04-02 2:58 ` [PATCH 24/51] l2tp: " David S. Miller
2012-04-02 2:58 ` [PATCH 25/51] dcbnl: " David S. Miller
2012-04-02 2:58 ` [PATCH 26/51] neighbour: " David S. Miller
2012-04-02 2:58 ` [PATCH 27/51] rtnetlink: " David S. Miller
2012-04-02 2:58 ` [PATCH 28/51] netlink: Add nla_put_le{16,32,64}() helpers David S. Miller
2012-04-02 2:58 ` [PATCH 29/51] decnet: Stop using NLA_PUT*() David S. Miller
2012-04-02 2:58 ` [PATCH 30/51] crypto: " David S. Miller
2012-04-02 2:58 ` [PATCH 31/51] infiniband: " David S. Miller
2012-04-02 2:58 ` [PATCH 32/51] can: " David S. Miller
2012-04-02 2:58 ` [PATCH 33/51] enic: " David S. Miller
2012-04-02 2:58 ` [PATCH 34/51] macvlan: " David S. Miller
2012-04-02 2:58 ` [PATCH 35/51] team: " David S. Miller
2012-04-02 2:58 ` [PATCH 36/51] ipv6: " David S. Miller
2012-04-02 2:58 ` [PATCH 37/51] netfilter: " David S. Miller
2012-04-02 2:58 ` [PATCH 38/51] ipv4: " David S. Miller
2012-04-02 2:58 ` [PATCH 39/51] netfilter: " David S. Miller
2012-04-02 2:58 ` [PATCH 40/51] ieee802154: " David S. Miller
2012-04-02 2:58 ` [PATCH 41/51] fib_rules: " David S. Miller
2012-04-02 2:58 ` [PATCH 42/51] gen_stats: " David S. Miller
2012-04-02 2:58 ` [PATCH 43/51] caif: " David S. Miller
2012-04-02 2:58 ` [PATCH 44/51] bridge: " David S. Miller
2012-04-02 2:58 ` [PATCH 45/51] vlan: " David S. Miller
2012-04-02 2:58 ` [PATCH 46/51] ath6kl: " David S. Miller
2012-04-02 2:58 ` [PATCH 47/51] iwlwifi: " David S. Miller
2012-04-02 2:58 ` [PATCH 48/51] mac80211_hwsim: " David S. Miller
2012-04-02 2:58 ` [PATCH 49/51] wl12xx: " David S. Miller
2012-04-02 2:58 ` [PATCH 50/51] xfrm: " David S. Miller
2012-04-02 2:58 ` [PATCH 51/51] netlink: Delete all NLA_PUT*() macros David S. Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1333335521-1348-7-git-send-email-davem@davemloft.net \
--to=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).