* [PATCH net] openvswitch: Zero flows on allocation.
@ 2015-09-19 2:06 Jesse Gross
2015-09-19 3:38 ` Pravin Shelar
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Jesse Gross @ 2015-09-19 2:06 UTC (permalink / raw)
To: David Miller; +Cc: netdev
OVS tries to be clever about not touching the parts of a flow that
aren't used. This can include leaving pieces of memory uninitialized
if the mask is zero and therefore the value would be ignored anyways.
While this works fine for the purposes of matching (which must always
look at the mask), serialization to netlink can be problematic. Since
the flow and the mask are serialized separately, the uninitialized
portions of the flow can be encoded with whatever values happen to be
present.
In terms of functionality, this has little effect since these fields
will be masked out by definition. However, it leaks kernel memory to
userspace, which is a potential security vulnerability.
This zeros the flows as they are allocated and installed. This was
always intended to be the case as the memory optimizations were only
supposed to apply to per-packet flow operations.
Fixes: 07148121 ("openvswitch: Eliminate memset() from flow_extract.")
Signed-off-by: Jesse Gross <jesse@nicira.com>
---
net/openvswitch/flow_table.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/openvswitch/flow_table.c b/net/openvswitch/flow_table.c
index d22d8e9..5248322 100644
--- a/net/openvswitch/flow_table.c
+++ b/net/openvswitch/flow_table.c
@@ -80,7 +80,7 @@ struct sw_flow *ovs_flow_alloc(void)
struct flow_stats *stats;
int node;
- flow = kmem_cache_alloc(flow_cache, GFP_KERNEL);
+ flow = kmem_cache_alloc(flow_cache, GFP_KERNEL | __GFP_ZERO);
if (!flow)
return ERR_PTR(-ENOMEM);
--
2.1.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net] openvswitch: Zero flows on allocation.
2015-09-19 2:06 [PATCH net] openvswitch: Zero flows on allocation Jesse Gross
@ 2015-09-19 3:38 ` Pravin Shelar
2015-09-20 16:32 ` Eric Dumazet
2015-09-21 6:24 ` David Miller
2 siblings, 0 replies; 5+ messages in thread
From: Pravin Shelar @ 2015-09-19 3:38 UTC (permalink / raw)
To: Jesse Gross; +Cc: David Miller, netdev
On Fri, Sep 18, 2015 at 7:06 PM, Jesse Gross <jesse@nicira.com> wrote:
> OVS tries to be clever about not touching the parts of a flow that
> aren't used. This can include leaving pieces of memory uninitialized
> if the mask is zero and therefore the value would be ignored anyways.
>
> While this works fine for the purposes of matching (which must always
> look at the mask), serialization to netlink can be problematic. Since
> the flow and the mask are serialized separately, the uninitialized
> portions of the flow can be encoded with whatever values happen to be
> present.
>
> In terms of functionality, this has little effect since these fields
> will be masked out by definition. However, it leaks kernel memory to
> userspace, which is a potential security vulnerability.
>
> This zeros the flows as they are allocated and installed. This was
> always intended to be the case as the memory optimizations were only
> supposed to apply to per-packet flow operations.
>
Good catch.
> Fixes: 07148121 ("openvswitch: Eliminate memset() from flow_extract.")
> Signed-off-by: Jesse Gross <jesse@nicira.com>
> ---
> net/openvswitch/flow_table.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/openvswitch/flow_table.c b/net/openvswitch/flow_table.c
> index d22d8e9..5248322 100644
> --- a/net/openvswitch/flow_table.c
> +++ b/net/openvswitch/flow_table.c
> @@ -80,7 +80,7 @@ struct sw_flow *ovs_flow_alloc(void)
> struct flow_stats *stats;
> int node;
>
> - flow = kmem_cache_alloc(flow_cache, GFP_KERNEL);
> + flow = kmem_cache_alloc(flow_cache, GFP_KERNEL | __GFP_ZERO);
> if (!flow)
> return ERR_PTR(-ENOMEM);
There are few flow members set to zero that are unnecessary after this change.
>
> --
> 2.1.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] openvswitch: Zero flows on allocation.
2015-09-19 2:06 [PATCH net] openvswitch: Zero flows on allocation Jesse Gross
2015-09-19 3:38 ` Pravin Shelar
@ 2015-09-20 16:32 ` Eric Dumazet
2015-09-21 6:24 ` David Miller
2 siblings, 0 replies; 5+ messages in thread
From: Eric Dumazet @ 2015-09-20 16:32 UTC (permalink / raw)
To: Jesse Gross; +Cc: David Miller, netdev
On Fri, 2015-09-18 at 19:06 -0700, Jesse Gross wrote:
>
> Fixes: 07148121 ("openvswitch: Eliminate memset() from flow_extract.")
> Signed-off-by: Jesse Gross <jesse@nicira.com>
> ---
> net/openvswitch/flow_table.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/openvswitch/flow_table.c b/net/openvswitch/flow_table.c
> index d22d8e9..5248322 100644
> --- a/net/openvswitch/flow_table.c
> +++ b/net/openvswitch/flow_table.c
> @@ -80,7 +80,7 @@ struct sw_flow *ovs_flow_alloc(void)
> struct flow_stats *stats;
> int node;
>
> - flow = kmem_cache_alloc(flow_cache, GFP_KERNEL);
> + flow = kmem_cache_alloc(flow_cache, GFP_KERNEL | __GFP_ZERO);
Or kmem_cache_zalloc(flow_cache, GFP_KERNEL) ?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] openvswitch: Zero flows on allocation.
2015-09-19 2:06 [PATCH net] openvswitch: Zero flows on allocation Jesse Gross
2015-09-19 3:38 ` Pravin Shelar
2015-09-20 16:32 ` Eric Dumazet
@ 2015-09-21 6:24 ` David Miller
2015-09-22 1:11 ` Jesse Gross
2 siblings, 1 reply; 5+ messages in thread
From: David Miller @ 2015-09-21 6:24 UTC (permalink / raw)
To: jesse; +Cc: netdev
From: Jesse Gross <jesse@nicira.com>
Date: Fri, 18 Sep 2015 19:06:14 -0700
> @@ -80,7 +80,7 @@ struct sw_flow *ovs_flow_alloc(void)
> struct flow_stats *stats;
> int node;
>
> - flow = kmem_cache_alloc(flow_cache, GFP_KERNEL);
> + flow = kmem_cache_alloc(flow_cache, GFP_KERNEL | __GFP_ZERO);
> if (!flow)
Like Eric, I prefer that you use kmem_cache_zalloc() to fix
this.
Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] openvswitch: Zero flows on allocation.
2015-09-21 6:24 ` David Miller
@ 2015-09-22 1:11 ` Jesse Gross
0 siblings, 0 replies; 5+ messages in thread
From: Jesse Gross @ 2015-09-22 1:11 UTC (permalink / raw)
To: David Miller; +Cc: netdev
On Sun, Sep 20, 2015 at 11:24 PM, David Miller <davem@davemloft.net> wrote:
> From: Jesse Gross <jesse@nicira.com>
> Date: Fri, 18 Sep 2015 19:06:14 -0700
>
>> @@ -80,7 +80,7 @@ struct sw_flow *ovs_flow_alloc(void)
>> struct flow_stats *stats;
>> int node;
>>
>> - flow = kmem_cache_alloc(flow_cache, GFP_KERNEL);
>> + flow = kmem_cache_alloc(flow_cache, GFP_KERNEL | __GFP_ZERO);
>> if (!flow)
>
> Like Eric, I prefer that you use kmem_cache_zalloc() to fix
> this.
Sure, I'll make both changes and send out a new patch in a bit.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-09-22 1:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-19 2:06 [PATCH net] openvswitch: Zero flows on allocation Jesse Gross
2015-09-19 3:38 ` Pravin Shelar
2015-09-20 16:32 ` Eric Dumazet
2015-09-21 6:24 ` David Miller
2015-09-22 1:11 ` Jesse Gross
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).