All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] openvswitch: check return value of nla_nest_start
@ 2017-04-23  6:43 ` Pan Bian
  0 siblings, 0 replies; 4+ messages in thread
From: Pan Bian @ 2017-04-23  6:43 UTC (permalink / raw)
  To: Pravin Shelar, David S. Miller, netdev, dev, linux-kernel; +Cc: Pan Bian

Function nla_nest_start() will return a NULL pointer on error, and its
return value should be validated before it is used. However, in function
queue_userspace_packet(), its return value is ignored. This may result
in NULL dereference when calling nla_nest_end(). This patch fixes the
bug.

Signed-off-by: Pan Bian <bianpan2016@163.com>
---
 net/openvswitch/datapath.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index 9c62b63..34c0fbd 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -489,7 +489,8 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
 		err = ovs_nla_put_tunnel_info(user_skb,
 					      upcall_info->egress_tun_info);
 		BUG_ON(err);
-		nla_nest_end(user_skb, nla);
+		if (nla)
+			nla_nest_end(user_skb, nla);
 	}
 
 	if (upcall_info->actions_len) {
@@ -497,7 +498,7 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
 		err = ovs_nla_put_actions(upcall_info->actions,
 					  upcall_info->actions_len,
 					  user_skb);
-		if (!err)
+		if (!err && nla)
 			nla_nest_end(user_skb, nla);
 		else
 			nla_nest_cancel(user_skb, nla);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 1/1] openvswitch: check return value of nla_nest_start
@ 2017-04-23  6:43 ` Pan Bian
  0 siblings, 0 replies; 4+ messages in thread
From: Pan Bian @ 2017-04-23  6:43 UTC (permalink / raw)
  To: Pravin Shelar, David S. Miller, netdev-u79uwXL29TY76Z2rM5mHXA,
	dev-yBygre7rU0TnMu66kgdUjQ, linux-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: Pan Bian

Function nla_nest_start() will return a NULL pointer on error, and its
return value should be validated before it is used. However, in function
queue_userspace_packet(), its return value is ignored. This may result
in NULL dereference when calling nla_nest_end(). This patch fixes the
bug.

Signed-off-by: Pan Bian <bianpan2016-9Onoh4P/yGk@public.gmane.org>
---
 net/openvswitch/datapath.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index 9c62b63..34c0fbd 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -489,7 +489,8 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
 		err = ovs_nla_put_tunnel_info(user_skb,
 					      upcall_info->egress_tun_info);
 		BUG_ON(err);
-		nla_nest_end(user_skb, nla);
+		if (nla)
+			nla_nest_end(user_skb, nla);
 	}
 
 	if (upcall_info->actions_len) {
@@ -497,7 +498,7 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
 		err = ovs_nla_put_actions(upcall_info->actions,
 					  upcall_info->actions_len,
 					  user_skb);
-		if (!err)
+		if (!err && nla)
 			nla_nest_end(user_skb, nla);
 		else
 			nla_nest_cancel(user_skb, nla);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [ovs-dev] [PATCH 1/1] openvswitch: check return value of nla_nest_start
@ 2017-04-23 20:22   ` Pravin Shelar
  0 siblings, 0 replies; 4+ messages in thread
From: Pravin Shelar @ 2017-04-23 20:22 UTC (permalink / raw)
  To: Pan Bian
  Cc: Pravin Shelar, David S. Miller, Linux Kernel Network Developers,
	ovs dev, linux-kernel

On Sat, Apr 22, 2017 at 11:43 PM, Pan Bian <bianpan2016@163.com> wrote:
> Function nla_nest_start() will return a NULL pointer on error, and its
> return value should be validated before it is used. However, in function
> queue_userspace_packet(), its return value is ignored. This may result
> in NULL dereference when calling nla_nest_end(). This patch fixes the
> bug.
>
> Signed-off-by: Pan Bian <bianpan2016@163.com>
> ---
>  net/openvswitch/datapath.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
> index 9c62b63..34c0fbd 100644
> --- a/net/openvswitch/datapath.c
> +++ b/net/openvswitch/datapath.c
> @@ -489,7 +489,8 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
>                 err = ovs_nla_put_tunnel_info(user_skb,
>                                               upcall_info->egress_tun_info);
>                 BUG_ON(err);
> -               nla_nest_end(user_skb, nla);
> +               if (nla)
> +                       nla_nest_end(user_skb, nla);
There is enough memory allocated for the netlink message accounting
for all attributes beforehand. So it is not required to check retuned
'nla' after each attributes addition to the msg.


>         }
>
>         if (upcall_info->actions_len) {
> @@ -497,7 +498,7 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
>                 err = ovs_nla_put_actions(upcall_info->actions,
>                                           upcall_info->actions_len,
>                                           user_skb);
> -               if (!err)
> +               if (!err && nla)
>                         nla_nest_end(user_skb, nla);
>                 else
>                         nla_nest_cancel(user_skb, nla);
> --
> 1.9.1
>
>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] openvswitch: check return value of nla_nest_start
@ 2017-04-23 20:22   ` Pravin Shelar
  0 siblings, 0 replies; 4+ messages in thread
From: Pravin Shelar @ 2017-04-23 20:22 UTC (permalink / raw)
  To: Pan Bian
  Cc: ovs dev, Linux Kernel Network Developers, David S. Miller,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Sat, Apr 22, 2017 at 11:43 PM, Pan Bian <bianpan2016-9Onoh4P/yGk@public.gmane.org> wrote:
> Function nla_nest_start() will return a NULL pointer on error, and its
> return value should be validated before it is used. However, in function
> queue_userspace_packet(), its return value is ignored. This may result
> in NULL dereference when calling nla_nest_end(). This patch fixes the
> bug.
>
> Signed-off-by: Pan Bian <bianpan2016-9Onoh4P/yGk@public.gmane.org>
> ---
>  net/openvswitch/datapath.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
> index 9c62b63..34c0fbd 100644
> --- a/net/openvswitch/datapath.c
> +++ b/net/openvswitch/datapath.c
> @@ -489,7 +489,8 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
>                 err = ovs_nla_put_tunnel_info(user_skb,
>                                               upcall_info->egress_tun_info);
>                 BUG_ON(err);
> -               nla_nest_end(user_skb, nla);
> +               if (nla)
> +                       nla_nest_end(user_skb, nla);
There is enough memory allocated for the netlink message accounting
for all attributes beforehand. So it is not required to check retuned
'nla' after each attributes addition to the msg.


>         }
>
>         if (upcall_info->actions_len) {
> @@ -497,7 +498,7 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
>                 err = ovs_nla_put_actions(upcall_info->actions,
>                                           upcall_info->actions_len,
>                                           user_skb);
> -               if (!err)
> +               if (!err && nla)
>                         nla_nest_end(user_skb, nla);
>                 else
>                         nla_nest_cancel(user_skb, nla);
> --
> 1.9.1
>
>
> _______________________________________________
> dev mailing list
> dev-yBygre7rU0TnMu66kgdUjQ@public.gmane.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-04-23 20:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-23  6:43 [PATCH 1/1] openvswitch: check return value of nla_nest_start Pan Bian
2017-04-23  6:43 ` Pan Bian
2017-04-23 20:22 ` [ovs-dev] " Pravin Shelar
2017-04-23 20:22   ` Pravin Shelar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.