From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.85 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796352403; b=WLO8EQ5nRjIsc9siXL6Zze2i58qIurHseH2VSqg+Fw5D9GXNeLX0ypKye5JOwj/Bx5jJ SuBwIKQMUXwMoFBMe3w8ZjjRIczsq0IOcmPijzN3OSLL9mcPX9lhzeTmWlxdQFLn6LmKC MuooODvIV2M+4jcbgwM9TbqjPiDmPqg66/9BjezPdCTLj1rzuVQSeWd4jn8ZuCiJ3ZxmA o33IfmHC6snAvaqSfBI4hMbB8KrWfcwL9/38taTaHga1gvzBDYeAlbp14jtWfBYlB2yTy n3rsK9dVaD9TV4NZi18v4xg3Gaw6ruI9nEVUswTDnOHqtwxW6xj74sJRSs4w2hWEGyg== 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=J+UQSDnsF6URuwlNU0OHFWwC5WMFrIVmYp0PMImRo92yxGOlZcjDpepWA/4+erB6v//S Rmf/Lp6kBjAjLjjqZQBYViYiGr5ms7iM6hWg+BcZsMTIcxG43OYhqDsfPejzjvkeMB9tT daA3uQztL1sh6O9GBqRRLSOUPUq7CuptLUn4MVK+hYvHGVBgRQf1IfvyTVbj2DVjE/efH 3snbjnFEY0fM33anv0BRCjOGOW+fTojWSw1LsdPYqjVmrgr1KAwAD3atA/N2wf9ko71Z9 fj/TSkhtBI7GW5lVHP7jPYHHOKQc4hC5zOpC9lXtOsqqmRbxlltXww7BAIO/OBuhFTg== 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=91.218.175.85 Received: from mta0.migadu.com (out-85.mta0.migadu.com [91.218.175.85]) (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 834AD606A322 for ; Fri, 4 Dec 2026 02:46:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 834AD606A322 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: stable@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: stable@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: stable@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.