diff mbox series

openvswitch: Avoid OOB read when parsing flow nlattrs

Message ID 20190114091656.28594-1-ross.lagerwall@citrix.com
State Accepted
Delegated to: David Miller
Headers show
Series openvswitch: Avoid OOB read when parsing flow nlattrs | expand

Commit Message

Ross Lagerwall Jan. 14, 2019, 9:16 a.m. UTC
For nested and variable attributes, the expected length of an attribute
is not known and marked by a negative number.  This results in an OOB
read when the expected length is later used to check if the attribute is
all zeros. Fix this by using the actual length of the attribute rather
than the expected length.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
---
 net/openvswitch/flow_netlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Pravin Shelar Jan. 15, 2019, 12:19 a.m. UTC | #1
On Mon, Jan 14, 2019 at 1:17 AM Ross Lagerwall
<ross.lagerwall@citrix.com> wrote:
>
> For nested and variable attributes, the expected length of an attribute
> is not known and marked by a negative number.  This results in an OOB
> read when the expected length is later used to check if the attribute is
> all zeros. Fix this by using the actual length of the attribute rather
> than the expected length.
>
> Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
> ---
>  net/openvswitch/flow_netlink.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/openvswitch/flow_netlink.c b/net/openvswitch/flow_netlink.c
> index 435a4bdf8f89..691da853bef5 100644
> --- a/net/openvswitch/flow_netlink.c
> +++ b/net/openvswitch/flow_netlink.c
> @@ -500,7 +500,7 @@ static int __parse_flow_nlattrs(const struct nlattr *attr,
>                         return -EINVAL;
>                 }
>
> -               if (!nz || !is_all_zero(nla_data(nla), expected_len)) {
> +               if (!nz || !is_all_zero(nla_data(nla), nla_len(nla))) {
>                         attrs |= 1 << type;
>                         a[type] = nla;
>                 }

Good Catch.
Acked-by: Pravin B Shelar <pshelar@ovn.org>
David Miller Jan. 16, 2019, 9:35 p.m. UTC | #2
From: Ross Lagerwall <ross.lagerwall@citrix.com>
Date: Mon, 14 Jan 2019 09:16:56 +0000

> For nested and variable attributes, the expected length of an attribute
> is not known and marked by a negative number.  This results in an OOB
> read when the expected length is later used to check if the attribute is
> all zeros. Fix this by using the actual length of the attribute rather
> than the expected length.
> 
> Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>

Applied.
diff mbox series

Patch

diff --git a/net/openvswitch/flow_netlink.c b/net/openvswitch/flow_netlink.c
index 435a4bdf8f89..691da853bef5 100644
--- a/net/openvswitch/flow_netlink.c
+++ b/net/openvswitch/flow_netlink.c
@@ -500,7 +500,7 @@  static int __parse_flow_nlattrs(const struct nlattr *attr,
 			return -EINVAL;
 		}
 
-		if (!nz || !is_all_zero(nla_data(nla), expected_len)) {
+		if (!nz || !is_all_zero(nla_data(nla), nla_len(nla))) {
 			attrs |= 1 << type;
 			a[type] = nla;
 		}