From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.119 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796352403; b=sJLFT6p0lRx9HVr6GG/XQ6Q9PLp+dW3eIHZ7O9M2W77JWRm88YFh31LeBGvcL1smbmcY wmvXH8ZEeYe1oxy5N61nWjJUO1QmZHIH/DqjDhmLMyf/Koloh3ltuNPfWFLN6FWnJuiqd ne+xZn/KSdELuzl0mQ5wwjSF+ex6+I9tTdIxTBLuGqVWIZntGuY+FA0vf1DFIoEYG9onE YVcvZySWPGV0mln0usM5PeLnikGc1c8hsMMa0+mrtZwH7iHf+etGaBBtX5AXHI+ceoAOQ P4Df7qmvGavScJxAqbgzAOe0vc3pqqDNuJWSlCEckvqRdahMQKNwswQW+kbN0UzVtSg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796352403; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Content-Type:Mime-Version:Subject:From: In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References: To:X-Mailer; bh=ABuLmkjKD2Rukccnsn/NeuHSUjr+9Gz3RWqeXIzXZ3E=; b=J06WJX2Z4ufPbTGf7pgmlnyr3fmAqfSVGEqUuzjsCG4jpU0mqZuLA7wHKlJvHqgagRne IXU9OK1Jx/YTB5fAa3HXov8PWfcA9zK6U95HhXirTl7HfP9FQcCyQrk3AkqXNrNJT13wj f/IDp9is4qXIrfboeGcTasvfb4XPj40CgWpTnWRkNHa7xyFPx+drR/w0xzYb1Jl5grMvm llyRtV3mnSJ9A9ZeK3LlTHRfbY1SRR7F9Zg0nl0nFekUQjvR74pVg00w/ELlFKxUyQF99 hWLh/2XKjKqCR343kkOPJi5V1+MG6qs+xVRt18qyif/o/02+JFxE/6jjRt0USxD2MBg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=c6vVChX8; arc=none smtp.remote-ip=95.215.58.119 Received: from mta1.migadu.com (out-119.mta1.migadu.com [95.215.58.119]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86B5B606A32D for ; Fri, 4 Dec 2026 02:46:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 86B5B606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=c6vVChX8 X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=cZ9icYB7v070N1nmfMpSItEkdow+Wl16uSZF/U8v+f8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796352400; v=1; x=1796957200; b=c6vVChX81R6+9EOmJ0B/3jjbbQiTB1rQNpn7o/TatRWEzggjlIO9epUdeaNRObtn4vGrfbQg GhNTTwtycvuv7XSnPdt7EDcBL6muqu2jBv+gMdy7deZdGSAbcmwYK5aqpMbm5ELNz1Jp26vXNKt wf+Hcty6VUWFl1EWBJRE4OI0= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id a49a3887af3df35d; Fri, 04 Dec 2026 02:46:40 +0000 X-Mizu-Trace-ID: a49a3887af3df35d X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset=us-ascii X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3901.200.71.1.16\)) Subject: Re: [PATCH v2 RESEND] mm/hugetlb_cgroup: prevent use-after-free during cgroup offlining From: Muchun Song In-Reply-To: <20261106060347.637480-1-4ncienth@gmail.com> Date: Fri, 4 Dec 2026 10:46:25 +0800 Cc: Muchun Song , osalvador@suse.de, akpm@linux-foundation.org, david@kernel.org, tj@kernel.org, hongfu.li@linux.dev, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Content-Transfer-Encoding: 7bit Message-Id: <0E846EB7-13E2-4F99-B1F7-77DAF4ACDCA9@linux.dev> References: <20261106060347.637480-1-4ncienth@gmail.com> To: Daehyeon Ko <4ncienth@gmail.com> X-Mailer: Apple Mail (2.3901.200.71.1.16) > On Nov 6, 2026, at 14:03, Daehyeon Ko <4ncienth@gmail.com> wrote: > > A normal hugetlb charge obtains the current task's hugetlb cgroup with > css_tryget(), charges its page counter, and drops the CSS reference before > the folio is committed under hugetlb_lock. > > The task can be migrated while the allocation is in progress. If the old > CSS is then offlined, its final active-folio scan can finish before the > charge becomes visible. The allocation can subsequently charge that dying > CSS and commit its pointer to the folio. Once the CSS is freed, uncharging > the folio accesses the freed hugetlb_cgroup, including its page counter and > per-node usage. > > Keep the reference acquired by the charge until commit or cancellation. At > commit time, while holding hugetlb_lock, move an uncommitted charge out of > each dying CSS to the first live ancestor. The hierarchical charge already > includes every ancestor, so moving it only requires canceling each dying > CSS's local count. > > This orders commit against the offline active-folio scan: either the scan > runs after commit and reparents the folio, or commit observes the dying CSS > after the scan and selects a live ancestor. The retained reference also > keeps the originally selected hugetlb_cgroup alive through this decision. > Reservation charges retain their existing CSS lifetime and are not > reparented. > > On an unmodified v7.3 kernel with a 128-page 2 MiB pool, a > capability-free uid 1000 allocator racing administrator rmdir reproduced > KASAN writes to a freed hugetlb_cgroup in three of three boots. Controller > disable reproduced the same fault. With this change, 5,000 rmdir rounds > with over 1 million successful faults and 2,000 controller-disable rounds > with over 1.6 million successful faults completed without KASAN, LOCKDEP, > page-counter, or refcount reports. > > AI-assisted source review was used to identify the race and to help draft > the reproducer and fix. The interleaving and the resulting allocation, > free, and use-after-free stacks were verified with tracefs and KASAN. > > Fixes: da1def55919f ("hugetlb/cgroup: add support for cgroup removal") > Cc: stable@vger.kernel.org > Signed-off-by: Daehyeon Ko <4ncienth@gmail.com> Acked-by: Muchun Song (ByteDance) Thanks.