From: Michal Hocko <mhocko@suse.com>
To: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Tao Cui <cui.tao@linux.dev>,
akpm@linux-foundation.org, linux-mm@kvack.org,
cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
hannes@cmpxchg.org, roman.gushchin@linux.dev,
muchun.song@linux.dev, Tao Cui <cuitao@kylinos.cn>
Subject: Re: [PATCH] mm: page_counter: reject empty string in page_counter_memparse()
Date: Tue, 18 Aug 2026 09:45:56 +0200 [thread overview]
Message-ID: <aoQNtIRvqXRh-x4u@tiehlicka> (raw)
In-Reply-To: <aoMzchLCCz5hiFHp@linux.dev>
On Mon 17-08-26 09:16:40, Shakeel Butt wrote:
> On Mon, Aug 17, 2026 at 12:26:52PM +0800, Tao Cui wrote:
> > From: Tao Cui <cuitao@kylinos.cn>
> >
> > memparse() consumes no characters on an empty input and leaves the
> > end pointer at the terminating NUL. The only validation in
> > page_counter_memparse() checks for trailing characters, so an empty
> > input slips through and the limit becomes 0.
> >
> > All limit write callbacks of the memory controller strstrip() the
> > input before calling this helper, so a script that writes an unset
> > variable hits this path:
> >
> > LIMIT=
> > echo "$LIMIT" > $CG/memory.max
> > echo $?
> > 0
> > cat $CG/memory.max
> > 0
> >
> > Nothing reports the mistake: the limit is now 0 and the OOM killer
> > goes after every task in the cgroup. The same happens for
> > memory.min, memory.low, memory.high, memory.swap.high,
> > memory.swap.max and memory.zswap.max, where 0 silently removes the
> > protection or disables swap and zswap.
> >
> > Reject the input when no characters were consumed, which is the one
> > case the trailing-character check cannot catch.
> >
> > Fixes: 3e32cb2e0a12 ("mm: memcontrol: lockless page counters")
> > Signed-off-by: Tao Cui <cuitao@kylinos.cn>
> > ---
> > mm/page_counter.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/mm/page_counter.c b/mm/page_counter.c
> > index 661e0f2a5127..d14db705b04f 100644
> > --- a/mm/page_counter.c
> > +++ b/mm/page_counter.c
> > @@ -281,7 +281,7 @@ int page_counter_memparse(const char *buf, const char *max,
> > }
> >
> > bytes = memparse(buf, &end);
> > - if (*end != '\0')
> > + if (*end != '\0' || end == buf)
> > return -EINVAL;
>
> I wonder if someone started depending on this behavior. In that case it is
> better to return error instead of silently ignore, so we will hear complains
> loudly. This looks good to me.
This is backward incompatible change and I am wondering why should we
even risk regression.
> Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
--
Michal Hocko
SUSE Labs
prev parent reply other threads:[~2026-08-18 7:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 4:26 [PATCH] mm: page_counter: reject empty string in page_counter_memparse() Tao Cui
2026-08-17 16:16 ` Shakeel Butt
2026-08-18 7:45 ` Michal Hocko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aoQNtIRvqXRh-x4u@tiehlicka \
--to=mhocko@suse.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=cui.tao@linux.dev \
--cc=cuitao@kylinos.cn \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox