From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.58 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796376663; b=vBiYZK81qdM7Pw5qU++uaBC0apBVgjfx9X2Lh8KTFWNGH2M1nEWKTGNSbGHsBaFx7Yw4 bUvT3CAyD5yfQ8sp2K3a9QwykiOeogLEuET4KjpMjuJlRJGSZx9gDwkIDuTIqRRtXeaHo i1XyiMDnWMzqAOMA4uMSPc/7/P+KLjh9PvwYvhUv4YUWtVyopIWd5vtJa9PkjezNJPnyC z3ELHTWgzM0dfGP1e5Yd6EmPEJ0gVgROGIGU3c2hYgYi5DxOZFyzndxBLzLS4fHbZc50Y nwKfc4OnE1zavjLPtp/P7M5BovunB/t8ywvpaKe6u/DeHws3j+GG6u2jNwcldZJl5UA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796376663; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Cc:Subject:To:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=8EuOQXENECAImW3nBQ8jSvUcnpea04c7X9fSstGnk58=; b=EpjOEz7PRBKHtYawZK3XUp+DKat5tuX4gVuOHdJmdYm48MnlSG9ZDWiLFC5Qa21OBjqd gwgyL4F5eHPdHdI9nH0QBVixliLL4jGhP5HOoSgFivDEj0u/QC5hDadTEhTwKp/U8G7+1 0Yz0Tyj9PiFFGhPGRR/MgAAzRhPixGez9VdWizR6BwfWck0sBCRxItmUW+6TkYA8ZSrbt yND/CwNJmix4q22zBO/IDWomePICf12T2RA3rFx/MN6SSdKIZMlHgKcI6iKZjamY9ymau +tFDEiRnm/aFqAFmvCgl3hBwl82DCVo9J7t6tgekZdH5DCd7jojFSO6Wm5sm5AUov5w== 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=IAb2hBQd; arc=none smtp.remote-ip=91.218.175.58 Received: from mta0.migadu.com (out-58.mta0.migadu.com [91.218.175.58]) (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 23BBE606A680 for ; Fri, 4 Dec 2026 09:31:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 23BBE606A680 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=IAb2hBQd X-Envelope-To: linux-kernel@vger.kernel.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-kernel@vger.kernel.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-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 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 在 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