ovs: queue_userspace_packet: bail out if nla_nest_start returns NULL
Subsystems (3)
PATCH 1/1 ovs: queue_userspace_packet: bail out if nla_nest_start returns NULL
The return value of nla_nest_start() is not checked, and can be NULL, which is then being dereferenced in nla_nest_end(). Add a check to prevent such situations.
---
On top of "net-next" tree.
net/openvswitch/datapath.c | 4 ++++ 1 file changed, 4 insertions(+)
net/openvswitch/datapath.c +4 -0
@@ -427,6 +427,10 @@ static int queue_userspace_packet(struct net *net, int dp_ifindex, upcall->dp_ifindex = dp_ifindex; nla =nla_nest_start (user_skb,OVS_PACKET_ATTR_KEY ); +if (unlikely (!nla)) { + err = -ENOMEM ; + goto out; + }ovs_flow_to_nlattrs (upcall_info->key, user_skb);nla_nest_end (user_skb, nla);
Signature · 1 line
1.7.11.7
Quoted 16 lines · Daniel Borkmann
The return value of
nla_nest_start()is not checked, and can be NULL, which is then being dereferenced innla_nest_end(). Add a check to prevent such situations.Signed-off-by Daniel Borkmann <[email protected]>---
On top of "net-next" tree.net/openvswitch/datapath.c | 4 ++++ 1 file changed, 4 insertions(+)net/openvswitch/datapath.c +0
-0
net/openvswitch/datapath.c static int queue_userspace_packet(struct net *net, int dp_ifindex, · line 433
Quoted 7 lines
net/openvswitch/datapath.c +4
-0@@ -427,6 +427,10 @@ static int queue_userspace_packet(struct net *net, int dp_ifindex, upcall->dp_ifindex = dp_ifindex; nla =nla_nest_start (user_skb,OVS_PACKET_ATTR_KEY ); +if (unlikely (!nla)) { + err = -ENOMEM ; + goto out; + }
nla_nest_start() doesn't allocate any memory, it only fails if there isn't enough space, so the correct error code would be -EMSGSIZE. However, we just calculated the correct size a few lines earlier and we don't double check the size anywhere else, so this doesn't make a lot of sense to me.
Quoted 19 lines · Jesse Gross
Quoted 18 lines · Daniel Borkmann
The return value of
nla_nest_start()is not checked, and can be NULL, which is then being dereferenced innla_nest_end(). Add a check to prevent such situations.Signed-off-by Daniel Borkmann <[email protected]>---
On top of "net-next" tree.net/openvswitch/datapath.c | 4 ++++ 1 file changed, 4 insertions(+)net/openvswitch/datapath.c +0
-0@@ -427,6 +427,10 @@ static int queue_userspace_packet(struct net *net, int dp_ifindex, upcall->dp_ifindex = dp_ifindex;
Quoted 11 lines
net/openvswitch/datapath.c static int queue_userspace_packet(struct net *net, int dp_ifindex, · line 433
Quoted 5 lines
net/openvswitch/datapath.c +4
-0nla =nla_nest_start (user_skb,OVS_PACKET_ATTR_KEY ); +if (unlikely (!nla)) { + err = -ENOMEM ; + goto out; + }
nla_nest_start()doesn't allocate any memory, it only fails if there isn't enough space, so the correct error code would be-EMSGSIZE. However, we just calculated the correct size a few lines earlier and we don't double check the size anywhere else, so this doesn't make a lot of sense to me.
Fair enough, please drop this then.