Re: [PATCH 3/4] memcg: avoid overflow caused by PAGE_ALIGN

Michal Hocko
2013-07-31T08:14:41Z

On Wed 31-07-13 15:31:24, Qiang Huang wrote:
> 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: Sha Zhengju <handai.szj@taobao.com>
> Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>

Reviewed-by: Michal Hocko <mhocko@suse.cz>

> ---
> kernel/res_counter.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/res_counter.c b/kernel/res_counter.c
> index 3f0417f..085d3ae 100644
> --- a/kernel/res_counter.c
> +++ b/kernel/res_counter.c
> @@ -195,6 +195,10 @@ int res_counter_memparse_write_strategy(const char *buf,
> if (*end != '\0')
> return -EINVAL;
>
> - *res = PAGE_ALIGN(*res);
> + if (PAGE_ALIGN(*res) >= *res)
> + *res = PAGE_ALIGN(*res);
> + else
> + *res = RES_COUNTER_MAX;
> +
> return 0;
> }
> --
> 1.8.3
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe cgroups" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html

--
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: email@kvack.org