Skip to contentSkip to conversation

memcg: avoid "free" overflow in memcg_hierarchical_free_pages()

PATCH In review Greg Thelen 3 participants 3 messages Nov 9, 2010 – Nov 16, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 memcg: avoid "free" overflow in memcg_hierarchical_free_pages()

memcg limit and usage values are stored in res_counter, as 64-bit numbers, even on 32-bit machines. The "free" variable in memcg_hierarchical_free_pages() stores the difference between two 64-bit numbers (limit - current_usage), and thus should be stored in a 64-bit local rather than a machine defined unsigned long.

---
 mm/memcontrol.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
mm/memcontrol.c +3 -2
index 35870f9..d8a06d6 100644
@@ -1343,7 +1343,8 @@ static long mem_cgroup_local_page_stat(struct mem_cgroup *mem,
 static unsigned long
 memcg_hierarchical_free_pages(struct mem_cgroup *mem)
 {
-	unsigned long free, min_free;
+	u64 free;
+	unsigned long min_free;
 
 	min_free = global_page_state(NR_FREE_PAGES);
 
@@ -1351,7 +1352,7 @@ memcg_hierarchical_free_pages(struct mem_cgroup *mem)
 		free = (res_counter_read_u64(&mem->res, RES_LIMIT) -
 			res_counter_read_u64(&mem->res, RES_USAGE)) >>
 			PAGE_SHIFT;
-		min_free = min(min_free, free);
+		min_free = min((u64)min_free, free);
 		mem = parent_mem_cgroup(mem);
 	}
 
Signature · 8 lines
1.7.3.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Greg Thelen

memcg limit and usage values are stored in res_counter, as 64-bit numbers, even on 32-bit machines. The "free" variable in memcg_hierarchical_free_pages() stores the difference between two 64-bit numbers (limit - current_usage), and thus should be stored in a 64-bit local rather than a machine defined unsigned long.

It is converted to pages before the assignment, but even that might overflow on 32-bit if the difference is sufficiently large (> 1<<44).

Quoted 2 lines

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Acked-by on v1 1/1
#2 lore raw
In reply to Greg Thelen
Quoted 8 lines · On Tue, 9 Nov 2010 00:54:13 -0800 Greg Thelen <[email protected]> wrote:

memcg limit and usage values are stored in res_counter, as 64-bit numbers, even on 32-bit machines. The "free" variable in memcg_hierarchical_free_pages() stores the difference between two 64-bit numbers (limit - current_usage), and thus should be stored in a 64-bit local rather than a machine defined unsigned long.