From nobody Thu Apr 2 14:10:32 2026 Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) (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 5D51B332634 for ; Sat, 28 Mar 2026 06:09:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.69 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774678182; cv=none; b=o8GM0QnjK80PwzfPffaYMPXpLV6gXSZZol5SXBbvdZJ+SxajjKLrJKhZXLnt6VvhQ63/MgUQE0apedpSs/hGULeg/E8uTvpZbbHOvBqryBT1k36OCfpiIgxMfkNcn+z2gZ7Y5nxAL8krAxRGBx77XIj89ZasbgoYvsAR/JQ8M6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774678182; c=relaxed/simple; bh=Uf91+psySiGr7VyOOSF7xEZesm5a4CEZmG8oFV5jW9s=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=u3ngz15FfyNBmb61bkABvrX5DWTR79ZChjuV0MUrK4XKiD0Uh2EgSpK20+ctPi2B3XfcmCWITR8inEhATWDYScwha7dM1ltNDS0yWCcYNUddDhLVBAPPI9jy3Q3mCwzG9xhcHUEbG4XnupwFNWPSQ3045DJMF7plviDa6QWZ0yk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com; arc=none smtp.client-ip=209.85.210.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com Received: by mail-ot1-f69.google.com with SMTP id 46e09a7af769-7d7c5b6c1c6so5650835a34.3 for ; Fri, 27 Mar 2026 23:09:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774678180; x=1775282980; h=to:from:subject:message-id:in-reply-to:date:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8ad+0+BFCLw1m3pT4ya0F8Ie+pVGY4468fr6OUMgtu0=; b=RLI3XogvhqjHlNbauzfVF6fJsXqPhQmBX6SWJ9MAFe7ePcsXp4oWUqyva0L1aiECPe NFhZMX9ogs16Y4hf5GQ2XZiRuewt+iLHTHRe+NkKfKU359IHXexnSBrtQIYhAP62LxBX BUKu2Mmm6TokbRTuKauJjdrMst9I+0oi6m+Kf3wDEtfJVuS9MhJw1CiutD5wYrl48szl 5vi2EJQ+d+0eAIYhcuZV9CRaNg2/Fd9ZWxyilCt8oYQvf26kh+TigV1207mFchdX7uLv igqDYSI5vI+L9AAThNKshKbm6JyvQIpUEXLDi87jFeHTpVPp3YwrrMzxgUgySce4Q14G YUFA== X-Gm-Message-State: AOJu0YzXW9DutHlYdxc8BTtXVHWxzXwGGEbi3xSg0Qms1a8DfJqbShX/ YUTQZXlcsbL4suJGXkK2qps7vBZT/CBoY+lkQ2N+rG2JWpusXZf5DRE4l3O237hPeL5gSN1mpNe KYnZYbdA+CBd1Phog5rfPJDuaXQxNFxGhpzeS0J2cYLqsoNanGMl/baKpAKA= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a05:6820:a294:10b0:67e:1a1c:43c7 with SMTP id 006d021491bc7-67e1a1c4790mr1859371eaf.21.1774678180444; Fri, 27 Mar 2026 23:09:40 -0700 (PDT) Date: Fri, 27 Mar 2026 23:09:40 -0700 In-Reply-To: <69c763b5.a70a0220.128fd0.001a.GAE@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <69c770a4.a70a0220.128fd0.001c.GAE@google.com> Subject: Forwarded: [PATCH] mm/hugetlb: fix hugetlb cgroup rsvd charge/uncharge mismatch From: syzbot To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For archival purposes, forwarding an incoming command email to linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com. *** Subject: [PATCH] mm/hugetlb: fix hugetlb cgroup rsvd charge/uncharge mismat= ch Author: kartikey406@gmail.com #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git main In alloc_hugetlb_folio(), a single h_cg pointer is used for both the rsvd and non-rsvd hugetlb cgroup charges. When map_chg is set, hugetlb_cgroup_charge_cgroup_rsvd() stores the charged cgroup in h_cg, but the immediately following hugetlb_cgroup_charge_cgroup() overwrites h_cg with the non-rsvd cgroup pointer. As a result, hugetlb_cgroup_commit_charge_rsvd() stores the wrong (non-rsvd) cgroup pointer into the folio's rsvd slot. When the folio is later freed, free_huge_folio() unconditionally calls both hugetlb_cgroup_uncharge_folio() and hugetlb_cgroup_uncharge_folio_rsvd(). The rsvd uncharge reads back the wrong cgroup from the folio and decrements a counter that was never charged for that cgroup, causing a page_counter underflow: page_counter underflow: -512 nr_pages=3D512 WARNING: mm/page_counter.c:61 at page_counter_cancel Fix this by introducing a separate h_cg_rsvd pointer exclusively for the rsvd charge path, keeping the rsvd and non-rsvd charges fully independent through their charge, commit, and error uncharge paths. Reported-by: syzbot+226c1f947186f8fef796@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3D226c1f947186f8fef796 Signed-off-by: Deepanshu --- mm/hugetlb.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 327eaa4074d3..5be36a888e70 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2915,6 +2915,7 @@ struct folio *alloc_hugetlb_folio(struct vm_area_stru= ct *vma, map_chg_state map_chg; int ret, idx; struct hugetlb_cgroup *h_cg =3D NULL; + struct hugetlb_cgroup *h_cg_rsvd =3D NULL; gfp_t gfp =3D htlb_alloc_mask(h) | __GFP_RETRY_MAYFAIL; =20 idx =3D hstate_index(h); @@ -2965,7 +2966,7 @@ struct folio *alloc_hugetlb_folio(struct vm_area_stru= ct *vma, */ if (map_chg) { ret =3D hugetlb_cgroup_charge_cgroup_rsvd( - idx, pages_per_huge_page(h), &h_cg); + idx, pages_per_huge_page(h), &h_cg_rsvd); if (ret) goto out_subpool_put; } @@ -3007,7 +3008,7 @@ struct folio *alloc_hugetlb_folio(struct vm_area_stru= ct *vma, */ if (map_chg) { hugetlb_cgroup_commit_charge_rsvd(idx, pages_per_huge_page(h), - h_cg, folio); + h_cg_rsvd, folio); } =20 spin_unlock_irq(&hugetlb_lock); @@ -3059,7 +3060,7 @@ struct folio *alloc_hugetlb_folio(struct vm_area_stru= ct *vma, out_uncharge_cgroup_reservation: if (map_chg) hugetlb_cgroup_uncharge_cgroup_rsvd(idx, pages_per_huge_page(h), - h_cg); + h_cg_rsvd); out_subpool_put: /* * put page to subpool iff the quota of subpool's rsv_hpages is used --=20 2.43.0