All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: cgroup: fix out of bounds accesses
@ 2012-07-09  7:45 Eric Dumazet
  2012-07-09  8:15 ` Gao feng
  2012-07-09 11:01 ` Neil Horman
  0 siblings, 2 replies; 15+ messages in thread
From: Eric Dumazet @ 2012-07-09  7:45 UTC (permalink / raw)
  To: David Miller; +Cc: nhorman, linux-kernel, netdev, lizefan, tj, Gao feng

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 <gaofeng@cn.fujitsu.com>
---
net/core/dev.c            |    8 ++++++--
net/core/netprio_cgroup.c |    4 ++--
2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index 84f01ba..0f28a9e 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2444,8 +2444,12 @@ static void skb_update_prio(struct sk_buff *skb)
 {
 	struct netprio_map *map = rcu_dereference_bh(skb->dev->priomap);
 
-	if ((!skb->priority) && (skb->sk) && map)
-		skb->priority = map->priomap[skb->sk->sk_cgrp_prioidx];
+	if (!skb->priority && skb->sk && map) {
+		unsigned int prioidx = skb->sk->sk_cgrp_prioidx;
+
+		if (prioidx < map->priomap_len)
+			skb->priority = map->priomap[prioidx];
+	}
 }
 #else
 #define skb_update_prio(skb)
diff --git a/net/core/netprio_cgroup.c b/net/core/netprio_cgroup.c
index aa907ed..3e953ea 100644
--- a/net/core/netprio_cgroup.c
+++ b/net/core/netprio_cgroup.c
@@ -142,7 +142,7 @@ static void cgrp_destroy(struct cgroup *cgrp)
 	rtnl_lock();
 	for_each_netdev(&init_net, dev) {
 		map = rtnl_dereference(dev->priomap);
-		if (map)
+		if (map && cs->prioidx < map->priomap_len)
 			map->priomap[cs->prioidx] = 0;
 	}
 	rtnl_unlock();
@@ -166,7 +166,7 @@ static int read_priomap(struct cgroup *cont, struct cftype *cft,
 	rcu_read_lock();
 	for_each_netdev_rcu(&init_net, dev) {
 		map = rcu_dereference(dev->priomap);
-		priority = map ? map->priomap[prioidx] : 0;
+		priority = (map && prioidx < map->priomap_len) ? map->priomap[prioidx] : 0;
 		cb->fill(cb, dev->name, priority);
 	}
 	rcu_read_unlock();



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

end of thread, other threads:[~2012-07-10  9:36 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-09  7:45 [PATCH] net: cgroup: fix out of bounds accesses Eric Dumazet
2012-07-09  8:15 ` Gao feng
2012-07-09 21:51   ` David Miller
2012-07-10  2:33     ` Gao feng
2012-07-10  2:37       ` David Miller
2012-07-09 11:01 ` Neil Horman
2012-07-09 11:50   ` Eric Dumazet
2012-07-09 12:13     ` Neil Horman
2012-07-09 12:40       ` Eric Dumazet
2012-07-09 12:56         ` Neil Horman
2012-07-10  2:31         ` [PATCH] net: cgroup: fix access the unallocated memory in netprio cgroup Gao feng
2012-07-10  4:14           ` Eric Dumazet
2012-07-10  8:53             ` Gao feng
2012-07-10  9:15               ` Eric Dumazet
2012-07-10  9:36                 ` Gao feng

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.