From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794590708; b=IMasFPxuQM/V1E1d4GG9OihQkykbrpCvBMP2f8VsMR2UVPTwMxtbUUhTzg6XQm1fpbMt oht+1HksITnyErbRPJwmdLzslewg2EYsrNfQIhaaxhlHtQZiYHCOP2Ew4erZ9fx2S/qRl hRyuWhVRBjJTSJo9AgoGAVtGAsFrgQkFj5PHBxfs/bBoEnpzwz0q6ZGamJypQ0w6nd3oS 3szkEA4fyu9boVvhevUOZLJUbhjVKMPaxEZqMya7/ahDCKsyRc0B5resvoXLreTJJ72NO IZE9dN20xXM6hwBzGa9B7dBqOBttzkQUogKo9t7+vyhymPRh3eycwwM/f1i2c3nPbhg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794590708; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=2m0ZEdk9tyqIU4f3VTkA8TKSiQMVZkViwFr+k0ZaPIE=; b=k784wm3bpwrY/bCpCSl0yObjj6bWR5lCkTxWDWi5x1EXYZPXppqNjAdGXXqRft+c9Sek PziZCerw40oE/BDNjG/gUe8GAIKN6VX8w++iuhtM/RXBcYDaON0vXhyROydFDf7A5Xisg hdx8IaDfyJ3Cn4k8To5yRUhrgghqFN0SIN5N1Um9h6gtkT17N35tI9y7YdqCaqsNDnxmk wvh6bq7s+NFH8obOMnOBhNaOLJtHhY3q5G7EGWP7oYJ08HWzit+TZkKqoKN0Nw2eDDSTJ 75029ln5758Y3QDM//0YoQma42IlDBX+EvgSOrD0uoBnU16ETMyBqHn1yIbIwyP/Viw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=suG9Z5mK; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 918AE607A5DC; Fri, 13 Nov 2026 17:25:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=suG9Z5mK Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36BBA1F000C6; Fri, 13 Nov 2026 17:25:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794590708; bh=2m0ZEdk9tyqIU4f3VTkA8TKSiQMVZkViwFr+k0ZaPIE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=suG9Z5mKTE0ZUvrBiHOv+an21cZ+04iw63Vk2DjMTIyHt6HtRcOi0KwiI5cmnwema 0tNCIff556KUtd0L60xZtGIauekNvKiQNEJUPIHqbr3nHLBvG3kyj2aNHv5GJ28iVa 7tps0ohrOfvXwbOKX8RQK43SgUi7Iisdipg/AkTA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ackerley Tng , Andrew Morton , Muchun Song , Joshua Hahn , Alex Shi , David Hildenbrand , David Rientjes , Dongliang Mu , Frank van der Linden , Hongxiang Lou , James Houghton , Johannes Weiner , Jonathan Corbet , "Liam R. Howlett" , Lorenzo Stoakes , Ma Wupeng , Miaohe Lin , Michal Hocko , Mike Rapoport , Nhat Pham , Oscar Salvador , Peter Xu , Roman Gushchin , Shakeel Butt , Suren Baghdasaryan , Vishal Annapurve , Vlastimil Babka , Yanteng Si , Sasha Levin Subject: [PATCH 6.18 618/686] mm: hugetlb: drop refcount before freeing on memcg charge failure Date: Fri, 13 Nov 2026 10:52:31 -0500 Message-ID: <20261113153842.814684849@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261113153820.902362109@linuxfoundation.org> References: <20261113153820.902362109@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ackerley Tng [ Upstream commit e95d29c5df84f19881cd30b491fc81aa98f44b45 ] When mem_cgroup_charge_hugetlb(folio, gfp) returns -ENOMEM, the folio has its refcount set to 1 via folio_ref_unfreeze(folio, 1). The error path calls free_huge_folio(folio) directly, which expects a refcount of 0. Hence, VM_BUG_ON_FOLIO(folio_ref_count(folio), folio) is triggered. Even with CONFIG_DEBUG_VM disabled, returning a folio with refcount 1 to the freelist can corrupt allocator state later. Use folio_put(folio) instead of free_huge_folio(folio) to properly drop the reference before freeing it. Link: https://lore.kernel.org/20260909-hugetlb-alloc-folio-memcg-charge-error-handling-v2-2-4b4a8a19a7f7@google.com Fixes: 991135774c0e ("memcg/hugetlb: introduce mem_cgroup_charge_hugetlb") Signed-off-by: Ackerley Tng Signed-off-by: Andrew Morton Reviewed-by: Muchun Song Reviewed-by: Joshua Hahn Cc: Alex Shi Cc: David Hildenbrand Cc: David Rientjes Cc: Dongliang Mu Cc: Frank van der Linden Cc: Hongxiang Lou Cc: James Houghton Cc: Johannes Weiner Cc: Jonathan Corbet Cc: Liam R. Howlett Cc: Lorenzo Stoakes Cc: Ma Wupeng Cc: Miaohe Lin Cc: Michal Hocko Cc: Mike Rapoport Cc: Nhat Pham Cc: Oscar Salvador Cc: Peter Xu Cc: Roman Gushchin Cc: Shakeel Butt Cc: Suren Baghdasaryan Cc: Vishal Annapurve Cc: Vlastimil Babka Cc: Yanteng Si Cc: Signed-off-by: Sasha Levin --- mm/hugetlb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 1bfeaecf9b4fa..225c04d583adc 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3133,7 +3133,7 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, lruvec_stat_mod_folio(folio, NR_HUGETLB, pages_per_huge_page(h)); if (ret == -ENOMEM) { - free_huge_folio(folio); + folio_put(folio); /* * Return -ENOSPC, since retrying the fault is futile: * the OOM killer is not triggered for HugeTLB. -- 2.53.0