From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E48DE27466A for ; Tue, 18 Aug 2026 16:43:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787071434; cv=none; b=VgSvfKh+Y7sm15xxIMLogwXPjbGDZWLeF5b1PEziRq10Yx3cnsQoEMn6C3lbMuSoHV0TT1DPGO6a3AAsZEosG6kcXQFj/sJ89C19OX8wo31qjaa377SMrjSdlp44nTzrG95YGpGlPop+atwm7u4z6igm865FHmCeFNv2k+bUFM8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787071434; c=relaxed/simple; bh=x3yO1Xhzyjwg82TfFc4FISY/jp4ChnURfQzQ6iT7l7M=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=o6SuB4LdDrcJBCtAaWWGHhw+eSx54HB8nlgmCN2A4sbrxfO/jblO7qtaWDaQqe5hL5G2bt2WB4/1pPYyzI3ab3PaQDvgqU8p/avU+9sTLw39X4PZMdGbflLK/niUxZ+fmZ8VtGJlBBrRDDbAa7278Kb15YiDavXDy4rOIrzoX2U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=OOCwQwMb; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="OOCwQwMb" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4954a2e73a9so291765e9.3 for ; Tue, 18 Aug 2026 09:43:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1787071431; x=1787676231; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=hSPw/8r8Y7BIh1YcWJP4P9upFW6BW+TUQ3tuOxC68Hc=; b=OOCwQwMbW3gptgdjQBG3hOms5/l3scjuJiraazFIN+ej4JvnlyVKZeVQBy/hotMx0M Zb6HuIBliXePI0GQWXuwfMZJF4B6+UJgTCMuKVglKBqXy/ZUk6cYqwvfZ0mN0PT2dib7 +HreEyFI7+mZ+lLsQaheGjM9O8BTXlJiITTxTP3+z2K6XSGRcey7AI9OTDGsSo5Adk+y CIHyJ2f8kCQcMyylH/dxyquHZAzC/RujpCST1S1PyL5DTQOly0SqfePF6oNavolkvg0a /pIIYgBSMi7AYrZmZOwdildzVOlIeMhCHi7ZAxOzl889Z547g/dQoKU6RPjLs8B4B+cL DH/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787071431; x=1787676231; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=hSPw/8r8Y7BIh1YcWJP4P9upFW6BW+TUQ3tuOxC68Hc=; b=eGjAdsKhpfIFbSiqzkOuCjAxqiNP8mcZya7feK6FInDxKTgUxRIU8jJ/Wprg0NXcB3 hMu6svPvXY1vS1IT/CDAvFDs3bivriaaf2KiEFdG4al3DXAb4ftalEIDzx4fh7/vz/PD GA0uU9KQ7pipCT9i54NN363Xftq3VHn/JCiyVC56r/jF0wpY8llCCuq8voLyLNjef0M+ gXOo3prUPNSvVse8heULX1cuARABpsiHv1XZ7a6Pbsqi8eqmcFlS+bebWcGEll13amlW YaZrukdmNnxFq81ITFegcenwrhDI0xuj5v0kI0Nw9p5I3SN/IWTzU84hRbaKttGoTwnU EDtA== X-Forwarded-Encrypted: i=1; AHgh+Rpa+E9spJZr7E4q0rL03f3nUNf2NR4jb5Qu6vm467SAAnOnqHC1xLlk2sLSzolMk6hCNmB2fMiw96Nimw8=@vger.kernel.org X-Gm-Message-State: AOJu0YxVD9ioTiB7OE33vqYcEj3p7aIfIKltuYT9zcltfqh82Q/DJ7CR IhaVwdox8G+a8J4ypPizQtcskJdv7n+m6jVkoiIwPh5l5z3OEfyL/D0/xg1YanWDNyc= X-Gm-Gg: AR+sD10MMDq/8CYTdcJN2JBwDC2CanFnm0tSDRT8IMjvJLx2FasGN766afd+2C/Yy+3 swO8fheyFXZUo/CEMnMiEPDBYw6nG9AYr/Ov5E3GwhOicFACaVxdB1+GHnNUO2ObwMjFz+XvnPv RR07fth3nnTtHUzx33txLj5Mdk3g87348AP+YCnZURfMgsr2+usrDs9q/RySdkXY73RgmtLiyFc 9KuNW+T+LeIcKg1YrbEd99OkGJdLR/w4SdIJtJgoDhYuxJzDWe03Ll6jR4SmNowCa0DSH1VgC+v SxtI+8uFC9ts9lmVM0/jeBxMIs7a+x37zdfVkHnF2EXekAS34VwvtV87WWN+tN+QoZR9AIMhLvK bz2WgFYHApzX9sHWOrlA9430Tbq116Mkt/DcYaluQTOoT+sjrD4kOyiS0Rr0gAJgqYd1N3X7bwA TLNWH+tocvZZfpxbIdKvKE4xmQ8UY9LDKCl7wgqoCzO4YOPyCWHBKeSKH0XUU4/F3IW7/6CB1EU A== X-Received: by 2002:a05:600c:528d:b0:499:48be:3189 with SMTP id 5b1f17b1804b1-4999fa84b7dmr197625135e9.0.1787071431027; Tue, 18 Aug 2026 09:43:51 -0700 (PDT) Received: from localhost (109-81-87-166.rct.o2.cz. [109.81.87.166]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49996176b8asm225801765e9.11.2026.08.18.09.43.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2026 09:43:50 -0700 (PDT) Date: Tue, 18 Aug 2026 18:43:49 +0200 From: Michal Hocko To: Shakeel Butt Cc: Tao Cui , 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 Subject: Re: [PATCH] mm: page_counter: reject empty string in page_counter_memparse() Message-ID: References: <20260817042652.74136-1-cui.tao@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue 18-08-26 08:06:22, Shakeel Butt wrote: > On Tue, Aug 18, 2026 at 09:45:56AM +0200, Michal Hocko wrote: > > 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 > > > > > > > > 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 > > > > --- > > > > 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. > > Mainly I was wondering if this is intentional or unintentional. If this us > unintentional, can we fix it without anyone noticing? My guess would be this was just omission. Those happen and over years we have learned that userspace is quite creative at using those. > However if we are ok with this then let's make is formal and make this a > documented behavior. I don't have any strong opinion either way but I think you > are saying it safer to just assume this is intentional. Fine with me. My main question is why should we even bother to change this in the first place? Is that reason stronger than a theoretical breakage of userspace that we might learn much later? -- Michal Hocko SUSE Labs