From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 40F943AD517 for ; Tue, 18 Aug 2026 07:46:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787039164; cv=none; b=clLyvzgqYV6zURUlwhz2bDFjsv4BoY2gvM2WDAEtKsP/IvVySfs2iIaEoZj1wAYx+ufYMTDL6q2AmgxbohKVKlvTuO52GD+Z1+8X6NqU8N7WAyPENr7WalwGHjIg/DQDUQ7q1XjyCdbBOQsgMn4NNOHgURCn9kny2TjEyjKhb+0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787039164; c=relaxed/simple; bh=bohRl9TUaRTqMRjXrawVRxnM/0uh7YvaAyzKfG4nqLY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jRVScoa1UdYcjLERnwwt25HwG4C18e3qbJnXiaONaPA483H9oleivO0/1PNEDuGZiaimaeYqk6TQfcM3w7KP8ye7+tTrwFolauXwAp5W5gdQJ3HYs+js817tJALNisiz2Sat2AgYzGfpG20Hf/cR7skpyY8BTxUOBnMfcDt67h8= 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=FFuDYEKf; arc=none smtp.client-ip=209.85.128.42 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="FFuDYEKf" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-49800c6a846so50383595e9.3 for ; Tue, 18 Aug 2026 00:45:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1787039158; x=1787643958; 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=Y8DtTDcSzfGuvLMZ1kDSosdRxVmDTPGGThapUM2N22w=; b=FFuDYEKfibV4+DMORliNvP13R44rv3u7rYIWWvwbVEaDfdVXaItosni/vCfPYNWP5+ EQNN0pzFofXDWgYgk7xf/abPA018bnCG+wJ0XLlQog9wFJ9j1Rh+r+1r4VX/ybtFE2LL orcM8fumXclzJnz111jKFtUUhSnHoKHgOm7yMzyiVH+eVc/ZvBAVVmdYR+xW0lZQKsmW cnE9pv2SDicoCgbfWZn++xvc6O8Yisx28YXAEm2URA2OCdUtfeEtwDnUhcTPwtHUAshu jKEO+2v86yNXkQNXSKvWbp2fpFwauP1tGMs+zhhuXHQCYI4FhStmTVNbCXLGREnkJv2/ Al5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787039158; x=1787643958; 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=Y8DtTDcSzfGuvLMZ1kDSosdRxVmDTPGGThapUM2N22w=; b=SycNtwD5VcUT+WBlEhwG2HNpZAHW5nbZQbFCY0Hp0hfbLjFM5Gtp6NGQMTHz7U3h6L UXA405vyFKKnZ8WXl0THAyl/zEHM2Wk7GdOI+F9WMu5bjp0oUvqc0FascKvvvh1MLH4H DJnLCpnNhpXmP8giBeSe9hwYkX8IGIgghF0qqfzhfGmAk/itxGCO/CRHXhsjULkYnrbL iKOK1Z80jUTWFJjS5X/m3G61VHrNw4Mb1I2VcoO8+6NV7aJAP+ZTENbHASDEwBtGixmq CDE1NVniXSjE5dYfBTYayOPYvZbPV/PcEM9XrWktlQn1bJ/uczbrV7GLpyIrLleSv87f TuYg== X-Forwarded-Encrypted: i=1; AHgh+RrGOfJljn1499PnfC5qPiJkDLfFdF8vDRIHjnKfAHeylxZw49mObcy0DRPUrLbZU9JmsPzC6j6pWeAvez0=@vger.kernel.org X-Gm-Message-State: AOJu0Yxj4QtpaVHyT3ucx4P+upDFBCFlf2uoKlbE5UJom06K2ADiBqtK GCCBMaayD0sASEo+D8rdKlhEp4LEQbLHVgcpM82TaWqJs8u+uxIvQMmE80Ms1RyCB2I= X-Gm-Gg: AR+sD13HLpWyXigy5HJRyPb3LR7B8TxPAeFRtyWGzqvzgJmU6jbdbxOo4BVE0ODpUP4 ge/a4chYon3UeAVECBo2lOq/ke1FYyuBioVroV60YFDugcx90XPXzJf/MiiCNYyAFd5qsArWN6f ipmvn2eKjinxXR4W88JIljZyJzcKSYdY/HoL/mkW9Cm+Ee2cyZMtnB0RAKonobZQus5GYt+YM5C 4sIcQHBiozgFl8xCCcyY//R74IaMn4lFLAAzs86JTTNIA1nHJ3NBNr4epyIl4/xT/1nKCm4tjka yenFPBnvM6B6ON7HGUlPTRwxcBK+sLJsKUQ4KvbA9vnz1TyG784NRNugmSgyDJAXKPQ28tvX9Q4 4wsDHpqwozGTMjz6UtN8Gj+4uRqd0t9oCz76vtx8CKOBgLRk98M6gpH1EhBqHSDBBIMmq+PvM9X yiPh+NFdE3X0hpngP4puRPSYU3oEHIOYHY9aOcjBihR4eGx/akQu9H+e8AdKjopSFg0QDQT+ZS4 k7UftHfEA== X-Received: by 2002:a05:600c:8714:b0:499:8704:242c with SMTP id 5b1f17b1804b1-499878ca13bmr557228035e9.0.1787039157680; Tue, 18 Aug 2026 00:45:57 -0700 (PDT) Received: from localhost (109-81-86-48.rct.o2.cz. [109.81.86.48]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4998ca63e5csm129781225e9.2.2026.08.18.00.45.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2026 00:45:57 -0700 (PDT) Date: Tue, 18 Aug 2026 09:45:56 +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 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. > Acked-by: Shakeel Butt -- Michal Hocko SUSE Labs