If UBC has unlimited UB_PHYSPAGES/UB_SWAPPAGES mem_cgroup_apply_beancounter()
will set memcg limits to negative values due to overflow. This will
lead to bogus -ENOMEM.

Add proper check for overflow and also make sure that we don't mem and memsw
bigger than PAGE_COUNTER_MAX as this is maximal possible value for page 
counters.

Reported-by: Vladimir Meshkov <[email protected]>
Signed-off-by: Andrey Ryabinin <[email protected]>
---
 mm/memcontrol.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index fff4cb021b6c..66d51b7b07c5 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4732,10 +4732,14 @@ int mem_cgroup_apply_beancounter(struct mem_cgroup 
*memcg,
 
        mem = ub->ub_parms[UB_PHYSPAGES].limit;
        memsw = ub->ub_parms[UB_SWAPPAGES].limit;
-       if (memsw < PAGE_COUNTER_MAX - mem)
-               memsw += mem;
-       else
+
+       if (mem > PAGE_COUNTER_MAX)
+               mem = PAGE_COUNTER_MAX;
+
+       if (memsw + mem < mem || memsw + mem > PAGE_COUNTER_MAX)
                memsw = PAGE_COUNTER_MAX;
+       else
+               memsw += mem;
 
        oomguar = ub->ub_parms[UB_OOMGUARPAGES].barrier;
 
-- 
2.13.0

_______________________________________________
Devel mailing list
[email protected]
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to