From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0D438606A33D for ; Fri, 4 Dec 2026 09:31:05 +0000 (UTC) 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=IAb2hBQd Received: by kanga.kvack.org (Postfix) id 2ADAD6B05B3; Fri, 4 Dec 2026 04:31:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 284716B05BD; Fri, 4 Dec 2026 04:31:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C1AB6B05BE; Fri, 4 Dec 2026 04:31:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id AFE8E6B05B3 for ; Fri, 4 Dec 2026 04:31:03 -0500 (EST) Received: from smtpin21.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 44A7F1202DD for ; Fri, 4 Dec 2026 09:31:03 +0000 (UTC) X-FDA: 85505781606.21.2B26748 Received: from mta0.migadu.com (out-58.mta0.migadu.com [91.218.175.58]) by imf09.hostedemail.com (Postfix) with ESMTP id 12A49140006 for ; Fri, 4 Dec 2026 09:31:00 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=IAb2hBQd; spf=pass (imf09.hostedemail.com: domain of hongfu.li@linux.dev designates 91.218.175.58 as permitted sender) smtp.mailfrom=hongfu.li@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796376661; b=AZX4lAH2hDtbRYTllj0LE0kTr0QJImuYVJtDl//Zki6QTKonkhc6JQTKiseDyQIbZObr/7 yJBlAFQ8QflgEsHpn4kZmaSribwlmbWKomNOKM5noVvS1+uF3V2+yxFwZLupPiAXdm+6Z8 BgajKUhY+bL5cbTCb9M0YEeEgqNrU94= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796376661; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8EuOQXENECAImW3nBQ8jSvUcnpea04c7X9fSstGnk58=; b=0eai25VG12z0mVYVCAnsxic5uIRYoghTx5Nv3fxl1A6CEAZ5W0AvF1Q2MeGno04S5EcNVt ylgmyAQXJwCebCND7NC+Wwln5VydlBWEsCxy8fI1cTCZ/WJI9Gj7lEBzBd1jSRn3nrJyLO dBiR8PhjcZ9vtNn8KsQ0w+urUyf/fO4= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=IAb2hBQd; spf=pass (imf09.hostedemail.com: domain of hongfu.li@linux.dev designates 91.218.175.58 as permitted sender) smtp.mailfrom=hongfu.li@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Envelope-To: linux-mm@kvack.org DKIM-Signature: a=rsa-sha256; bh=90+04WmBH0ZbAcxRTSrpqNBzPPzNwPgEe/VnTwwBeVo=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796376659; v=1; x=1796981459; b=IAb2hBQdEsSKSvSJWmsq+TWx0d2QXdqU8S+IlxTM9M5upMjGwQZL8dkA8QR0Aq1CF4NkK73G PWmkgrVOGnV1Yln4ptma1UTppz61O4GYm5KzEKdwIciWG6UwWEV9WgiCqlbyA24KJjXxvCvCj/8 xjUFeuIEq6lyEpFHHRiHB5Qc= X-Envelope-To: linux-mm@kvack.org Received: by smtp.migadu.com with ESMTPS id 55e0d393c78171c1; Fri, 04 Dec 2026 09:30:59 +0000 X-Mizu-Trace-ID: 55e0d393c78171c1 X-Migadu-Flow: FLOW_OUT Message-ID: <24625dcd-227a-4b95-9646-13b221e6f309@linux.dev> Date: Fri, 4 Dec 2026 17:30:54 +0800 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: hongfu.li@linux.dev, david@kernel.org, tj@kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2 RESEND] mm/hugetlb_cgroup: prevent use-after-free during cgroup offlining To: Daehyeon Ko <4ncienth@gmail.com>, muchun.song@linux.dev, osalvador@suse.de, akpm@linux-foundation.org References: <20261106060347.637480-1-4ncienth@gmail.com> From: Hongfu Li In-Reply-To: <20261106060347.637480-1-4ncienth@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Queue-Id: 12A49140006 X-Rspamd-Server: rspam03 X-Stat-Signature: 7tttsweuqegrf4o1qx98tmzhat95bza4 X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796376660-502158 X-HE-Meta: U2FsdGVkX19h/nTnd4NdLvEYGK/7jIse7lj7+KzAEt/ypaQP4CDh8wfGMn2tLFKYOag830lO0W8C7n8JG9KNFt8QpbWaWH4l1ETZu1rZCHp02KexnNb9vc/lhacFc0ooVIpclxnLOFVIrJ5vpG1NGp6D2VjSUYCWeGW1qIidZPtTApG8nKpjzd/9xl/5TI4aWFRBEFNND0aX/z7Grttn7o4X3QlPMjcNLNuX6s0ic5iX1a4cUZ9hE6oKKeg14uUeuqcA2i/S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2Wzdm3q0q7Ms6Fg+/d6swyIBy6zNwp54ojYlSAwOt78cOd5MaB5wdI55j8mrFQ7yJGqry6YwXrpbNfK6uINNSxwgaaVL1pRUPHyLUbsahcEkDFTP/2m51QZkdvG7UoGIl62puKMusuVfUPimoJhfSmsGuCyRrT7tDyMee9pGcf7scPoK+WtMIlKvgAhNxocnTKFbpx1rGAg51zEdvHdCoM3J47wvBaszTYzmQZZX2zaAOBPR/e7oL5gOiRBPmu7Vzhj8 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 在 11/6/26 14:03, Daehyeon Ko 写道: > 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> Reviewed-by: Hongfu Li -- Best regards, Hongfu