[Devel] [PATCH rh7] mm/memcg, ub: fix overflow in mem_cgroup_apply_beancounter()
Andrey Ryabinin
aryabinin at virtuozzo.com
Thu Jun 1 12:46:08 MSK 2017
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 <vmeshkov at cloudlinux.com>
Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
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
More information about the Devel
mailing list