Commit 3af33516 authored by Sha Zhengju's avatar Sha Zhengju Committed by Linus Torvalds

memcg: avoid overflow caused by PAGE_ALIGN

Since PAGE_ALIGN is aligning up(the next page boundary), so after
PAGE_ALIGN, the value might be overflow, such as write the MAX value to
*.limit_in_bytes.

  $ cat /cgroup/memory/memory.limit_in_bytes
  18446744073709551615

  # echo 18446744073709551615 > /cgroup/memory/memory.limit_in_bytes
  bash: echo: write error: Invalid argument

Some user programs might depend on such behaviours(like libcg, we read
the value in snapshot, then use the value to reset cgroup later), and
that will cause confusion.  So we need to fix it.
Signed-off-by: default avatarSha Zhengju <handai.szj@taobao.com>
Signed-off-by: default avatarQiang Huang <h.huangqiang@huawei.com>
Acked-by: default avatarMichal Hocko <mhocko@suse.cz>
Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Cc: Jeff Liu <jeff.liu@oracle.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 6de5a8bf
...@@ -195,6 +195,10 @@ int res_counter_memparse_write_strategy(const char *buf, ...@@ -195,6 +195,10 @@ int res_counter_memparse_write_strategy(const char *buf,
if (*end != '\0') if (*end != '\0')
return -EINVAL; return -EINVAL;
if (PAGE_ALIGN(*res) >= *res)
*res = PAGE_ALIGN(*res); *res = PAGE_ALIGN(*res);
else
*res = RES_COUNTER_MAX;
return 0; return 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment