From: Eric Dumazet <hidden> Date: 2012-07-09 07:45:16
From: Eric Dumazet <edumazet@google.com>
dev->priomap is allocated by extend_netdev_table() called from
update_netdev_tables().
And this is only called if write_priomap() is called.
But if write_priomap() is not called, it seems we can have out of bounds
accesses in cgrp_destroy(), read_priomap() & skb_update_prio()
With help from Gao Feng
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Neil Horman <nhorman@tuxdriver.com>
Cc: Gao feng <redacted>
---
net/core/dev.c | 8 ++++++--
net/core/netprio_cgroup.c | 4 ++--
2 files changed, 8 insertions(+), 4 deletions(-)
From: Eric Dumazet <edumazet@google.com>
dev->priomap is allocated by extend_netdev_table() called from
update_netdev_tables().
And this is only called if write_priomap() is called.
But if write_priomap() is not called, it seems we can have out of bounds
accesses in cgrp_destroy(), read_priomap() & skb_update_prio()
With help from Gao Feng
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Neil Horman <nhorman@tuxdriver.com>
Cc: Gao feng <redacted>
---
net/core/dev.c | 8 ++++++--
net/core/netprio_cgroup.c | 4 ++--
2 files changed, 8 insertions(+), 4 deletions(-)
From: Neil Horman <nhorman@tuxdriver.com> Date: 2012-07-09 11:02:07
On Mon, Jul 09, 2012 at 09:45:10AM +0200, Eric Dumazet wrote:
From: Eric Dumazet <edumazet@google.com>
dev->priomap is allocated by extend_netdev_table() called from
update_netdev_tables().
And this is only called if write_priomap() is called.
But if write_priomap() is not called, it seems we can have out of bounds
accesses in cgrp_destroy(), read_priomap() & skb_update_prio()
With help from Gao Feng
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Neil Horman <nhorman@tuxdriver.com>
Cc: Gao feng <redacted>
---
net/core/dev.c | 8 ++++++--
net/core/netprio_cgroup.c | 4 ++--
2 files changed, 8 insertions(+), 4 deletions(-)
Thank you for doing this Eric, Gao. Just to be sure (I asked in the previous
thread), would it be better to avoid the length check in skb_update_prio, and
instead update the netdev tables to be long enough in cgrp_create and in
netprio_device_event on device registration?
Neil
From: Eric Dumazet <hidden> Date: 2012-07-09 11:50:59
On Mon, 2012-07-09 at 07:01 -0400, Neil Horman wrote:
Thank you for doing this Eric, Gao. Just to be sure (I asked in the previous
thread), would it be better to avoid the length check in skb_update_prio, and
instead update the netdev tables to be long enough in cgrp_create and in
netprio_device_event on device registration?
Yes probably, and it is even needed because extend_netdev_table() can
acutally fail to expand the table if kzalloc() returned NULL.
Current code just ignores this allocation failure so we also can crash
in write_priomap()
From: Neil Horman <nhorman@tuxdriver.com> Date: 2012-07-09 12:14:30
On Mon, Jul 09, 2012 at 01:50:52PM +0200, Eric Dumazet wrote:
On Mon, 2012-07-09 at 07:01 -0400, Neil Horman wrote:
quoted
Thank you for doing this Eric, Gao. Just to be sure (I asked in the previous
thread), would it be better to avoid the length check in skb_update_prio, and
instead update the netdev tables to be long enough in cgrp_create and in
netprio_device_event on device registration?
Yes probably, and it is even needed because extend_netdev_table() can
acutally fail to expand the table if kzalloc() returned NULL.
Current code just ignores this allocation failure so we also can crash
in write_priomap()
ACK, can you follow up with a patch please?
Thanks!
Neil
From: Eric Dumazet <hidden> Date: 2012-07-09 12:40:32
On Mon, 2012-07-09 at 08:13 -0400, Neil Horman wrote:
On Mon, Jul 09, 2012 at 01:50:52PM +0200, Eric Dumazet wrote:
quoted
On Mon, 2012-07-09 at 07:01 -0400, Neil Horman wrote:
quoted
Thank you for doing this Eric, Gao. Just to be sure (I asked in the previous
thread), would it be better to avoid the length check in skb_update_prio, and
instead update the netdev tables to be long enough in cgrp_create and in
netprio_device_event on device registration?
Yes probably, and it is even needed because extend_netdev_table() can
acutally fail to expand the table if kzalloc() returned NULL.
Current code just ignores this allocation failure so we also can crash
in write_priomap()
ACK, can you follow up with a patch please?
Gao was working on this allocation problem (he privately sent me a v1 of
his patch), so I think we can wait Gao submit a v2 to combine all the
work/ideas in a single patch.
(ie make sure we dont need additional bound checkings in fast path)
From: Neil Horman <nhorman@tuxdriver.com> Date: 2012-07-09 12:56:36
On Mon, Jul 09, 2012 at 02:40:25PM +0200, Eric Dumazet wrote:
On Mon, 2012-07-09 at 08:13 -0400, Neil Horman wrote:
quoted
On Mon, Jul 09, 2012 at 01:50:52PM +0200, Eric Dumazet wrote:
quoted
On Mon, 2012-07-09 at 07:01 -0400, Neil Horman wrote:
quoted
Thank you for doing this Eric, Gao. Just to be sure (I asked in the previous
thread), would it be better to avoid the length check in skb_update_prio, and
instead update the netdev tables to be long enough in cgrp_create and in
netprio_device_event on device registration?
Yes probably, and it is even needed because extend_netdev_table() can
acutally fail to expand the table if kzalloc() returned NULL.
Current code just ignores this allocation failure so we also can crash
in write_priomap()
ACK, can you follow up with a patch please?
Gao was working on this allocation problem (he privately sent me a v1 of
his patch), so I think we can wait Gao submit a v2 to combine all the
work/ideas in a single patch.
(ie make sure we dont need additional bound checkings in fast path)
From: Eric Dumazet <edumazet@google.com>
dev->priomap is allocated by extend_netdev_table() called from
update_netdev_tables().
And this is only called if write_priomap() is called.
But if write_priomap() is not called, it seems we can have out of bounds
accesses in cgrp_destroy(), read_priomap() & skb_update_prio()
With help from Gao Feng
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Neil Horman <nhorman@tuxdriver.com>
Cc: Gao feng <redacted>
---
net/core/dev.c | 8 ++++++--
net/core/netprio_cgroup.c | 4 ++--
2 files changed, 8 insertions(+), 4 deletions(-)
there are some out of bound accesses in netprio cgroup.
when creating a new netprio cgroup,we only set a prioidx for
the new cgroup,without allocate memory for dev->priomap.
because we don't want to see additional bound checkings in
fast path, so I think the best way is to allocate memory when we
creating a new netprio cgroup.
and because netdev can be created or registered after cgroup being
created, so extend_netdev_table is also needed in write_priomap.
this patch add a return value for update_netdev_tables & extend_netdev_table,
so when new_priomap is allocated failed,write_priomap will stop to access
the priomap,and return -ENOMEM back to the userspace to tell the user
what happend.
Signed-off-by: Gao feng <redacted>
Cc: Neil Horman <nhorman@tuxdriver.com>
Cc: Eric Dumazet <edumazet@google.com>
---
net/core/netprio_cgroup.c | 43 +++++++++++++++++++++++++++++--------------
1 files changed, 29 insertions(+), 14 deletions(-)
@@ -102,34 +104,44 @@ static void update_netdev_tables(void)for_each_netdev(&init_net,dev){map=rtnl_dereference(dev->priomap);if((!map)||-(map->priomap_len<max_len))-extend_netdev_table(dev,max_len);+(map->priomap_len<max_len)){+ret=extend_netdev_table(dev,max_len);+if(ret<0)+break;+}}rtnl_unlock();+returnret;}staticstructcgroup_subsys_state*cgrp_create(structcgroup*cgrp){structcgroup_netprio_state*cs;-intret;+intret=-EINVAL;cs=kzalloc(sizeof(*cs),GFP_KERNEL);if(!cs)returnERR_PTR(-ENOMEM);-if(cgrp->parent&&cgrp_netprio_state(cgrp->parent)->prioidx){-kfree(cs);-returnERR_PTR(-EINVAL);-}+if(cgrp->parent&&cgrp_netprio_state(cgrp->parent)->prioidx)+gotoout;ret=get_prioidx(&cs->prioidx);-if(ret!=0){+if(ret<0){pr_warn("No space in priority index array\n");-kfree(cs);-returnERR_PTR(ret);+gotoout;+}++ret=update_netdev_tables();+if(ret<0){+put_prioidx(cs->prioidx);+gotoout;}return&cs->css;+out:+kfree(cs);+returnERR_PTR(ret);}staticvoidcgrp_destroy(structcgroup*cgrp)
From: Eric Dumazet <edumazet@google.com>
dev->priomap is allocated by extend_netdev_table() called from
update_netdev_tables().
And this is only called if write_priomap() is called.
But if write_priomap() is not called, it seems we can have out of bounds
accesses in cgrp_destroy(), read_priomap() & skb_update_prio()
With help from Gao Feng
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Neil Horman <nhorman@tuxdriver.com>
Cc: Gao feng <redacted>
---
net/core/dev.c | 8 ++++++--
net/core/netprio_cgroup.c | 4 ++--
2 files changed, 8 insertions(+), 4 deletions(-)
Acked-by: Gao feng <redacted>
Applied.
Hi David
Please see my patch in this thread, I think it's a better way to fix this bug.
Thanks.
From: Eric Dumazet <hidden> Date: 2012-07-10 04:14:17
On Tue, 2012-07-10 at 10:31 +0800, Gao feng wrote:
there are some out of bound accesses in netprio cgroup.
when creating a new netprio cgroup,we only set a prioidx for
the new cgroup,without allocate memory for dev->priomap.
because we don't want to see additional bound checkings in
fast path, so I think the best way is to allocate memory when we
creating a new netprio cgroup.
and because netdev can be created or registered after cgroup being
created, so extend_netdev_table is also needed in write_priomap.
this patch add a return value for update_netdev_tables & extend_netdev_table,
so when new_priomap is allocated failed,write_priomap will stop to access
the priomap,and return -ENOMEM back to the userspace to tell the user
what happend.
Signed-off-by: Gao feng <redacted>
Cc: Neil Horman <nhorman@tuxdriver.com>
Cc: Eric Dumazet <edumazet@google.com>
---
quoted hunk
static void cgrp_destroy(struct cgroup *cgrp)
@@ -221,7 +233,10 @@ static int write_priomap(struct cgroup *cgrp, struct cftype *cft, if (!dev) goto out_free_devname;- update_netdev_tables();+ ret = update_netdev_tables();+ if (ret < 0)+ goto out_free_devname;+ ret = 0; rcu_read_lock(); map = rcu_dereference(dev->priomap);
Hi Gao
Is it still needed to call update_netdev_tables() from write_priomap() ?
Hi Gao
Is it still needed to call update_netdev_tables() from write_priomap() ?
Yes, I think it's needed,because read_priomap will show all of the net devices,
But we may add the netdev after create a netprio cgroup, so the new added netdev's
priomap will not be allocated. if we don't call update_netdev_tables in write_priomap,
we may access this unallocated memory.
From: Eric Dumazet <hidden> Date: 2012-07-10 09:15:25
On Tue, 2012-07-10 at 16:53 +0800, Gao feng wrote:
quoted
Hi Gao
Is it still needed to call update_netdev_tables() from write_priomap() ?
Yes, I think it's needed,because read_priomap will show all of the net devices,
But we may add the netdev after create a netprio cgroup, so the new added netdev's
priomap will not be allocated. if we don't call update_netdev_tables in write_priomap,
we may access this unallocated memory.
I realize my question was not clear.
If we write in write_priomap() a field of a single netdevice,
why should we allocate memory for all netdevices on the machine ?
So the question was : Do we really need to call
update_netdev_tables(alldevs), instead of extend_netdev_table(dev)
On Tue, 2012-07-10 at 16:53 +0800, Gao feng wrote:
quoted
quoted
Hi Gao
Is it still needed to call update_netdev_tables() from write_priomap() ?
Yes, I think it's needed,because read_priomap will show all of the net devices,
But we may add the netdev after create a netprio cgroup, so the new added netdev's
priomap will not be allocated. if we don't call update_netdev_tables in write_priomap,
we may access this unallocated memory.
I realize my question was not clear.
If we write in write_priomap() a field of a single netdevice,
why should we allocate memory for all netdevices on the machine ?
So the question was : Do we really need to call
update_netdev_tables(alldevs), instead of extend_netdev_table(dev)
I get it.
You are right,Indeed we only need to call extend_netdev_table
for the netdev witch we want to change.
and I read the commit f5c38208d32412d72b97a4f0d44af0eb39feb20b,
found why we need delay allocation.
I will send a v2 patch.
Thanks!