From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oa1-f42.google.com (mail-oa1-f42.google.com [209.85.160.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D829642DA5F for ; Mon, 20 Jul 2026 14:31:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784557895; cv=none; b=ev2OlzmQMjIhizXm4iF7ho5Qrcv2ewrIjveZ+aCVbLN3Wb5i+tlf5vDLSg2lIt8wjIaBFGVkOS3h7+qtLX1pBvMsip8yqrt/+ff7TNoJy+3QIPEbOZmcbjXDmstRhz8y+MQWobijxiFE2WTO7MKBLBbqHEieWdaHlou7c5V741w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784557895; c=relaxed/simple; bh=vVqVVHoX6AEsHPOpJp+jv2f9pa5JIZMqD3iA0FIGZQM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qrAHQeU1sVZCeU+4ND3nXe2ZG2OGDwKeKRwRWGfPK89XxpqO3WbxftG62kPms/AzOKtBGpm1rNqy0vc31wPVqEqpzVBAMpjS9YGRDU24elprjvgiP9ACc3bdmSv/vWmXPmOYwZIh/s7+HX+BjahmfA5G029q5ew3SaJDIvD0kX0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kIsGO8Zg; arc=none smtp.client-ip=209.85.160.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kIsGO8Zg" Received: by mail-oa1-f42.google.com with SMTP id 586e51a60fabf-455ee8f529dso1340714fac.1 for ; Mon, 20 Jul 2026 07:31:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784557893; x=1785162693; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=FRblZRKVWZtwBROzeWSAhOYR72G85c1lXXCcvEtUJeU=; b=kIsGO8ZgXo78/+TPSKf1OOEUBLSrqDhget5NNjvJS9EyW3Px7A1cliqHLqbUOqXvqJ oOoRZtTg70pOFVm2wlHWmaTH4fiJKZYg4DlCOKWqOnlfOTLXv/60Bs4NsEFxDThUL3vA QWy2hOuhryIztW6+Op5PXK/Os/O5t41XQu8oaSSXxDyxvo3z0VQKAR/zb4UwjU7ZYBnV TDGM99faGFAtbSIMi0NzhDj/mjQR3R5yieKZsCwyr8nIsrJwk9l6BvMp22PXPreR5xYb 1X6DWXOpsdd82styy1C+p8sYhXDOMMrhYBZLnNYZHAdMTq9X9BThiOx44bwdUE0pevUi jjNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784557893; x=1785162693; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=FRblZRKVWZtwBROzeWSAhOYR72G85c1lXXCcvEtUJeU=; b=Yz34uQb0/1twOrvixhzzzHYBYRYEa+GI8qJth4aDqr+7Su1HZx0EUEh1q+q/FEfinW uEVVpM+wJYrjnUbMHPT/BjSkTjmXxG4ipcUtrMMoS9yX1fXn0BNssEYUjZvNNqxXvJVU IoOMrdslg5bSQdS+qW0vypnv9kcbJiI0yLmdCEOCZYRSkX64dZZjROG7ngSivD0UIjhC 9+tWItVoW4ezeGIbm34w/MUFdUVeutUzlekrczyu/UQwiIfqY21Q/N05dwSfPaiW3DNC 73sSoCqsyPcxX9MGYsIxPTMuimQv3dK3GEdZJKT2hMMXdS6MKwNV7AaxvKxgHGtKtTWW sv6Q== X-Forwarded-Encrypted: i=1; AHgh+Rpn6o2GK3Dp7+wj8d/35f+RnSq2TWZR2EyJSjlWU1tMvnlvCCL+LYK7N6HAWhoz/6i1Rvjy1QMupGYqIss=@vger.kernel.org X-Gm-Message-State: AOJu0YxaTcv/MOlRqqpdjGtuq5FRMFhrn2HdZdd8VntItQs5QSEqzS9g wejueq2N3L9ax15U8h6cvf6ZzKFz4MUwoOKBj1eh9TmElBass7vW1Irp X-Gm-Gg: AR+sD12+fEiAt/r3GhoAthk+ELYyRyWbw1hpC3yEp6NO2/+hWyrOfZhngMjblWRrnVY RwxP+sH3imHBnKS/PG5oya7HPsXbhnYxkthDMsOx1muxf0wXmkQlQpeFwDL6Qh2/A+SFdh87CyH GbxXa6xjgUf58Q+R8+n7HtiInVksRHI6wxslkWZQ8MiXQC1SER44mVJCks4Oz76OROYTOWab4EO hQj4A5uuErcJ1SGrtlAwYmKtwUZVgMrnNjez0WFijbXTUFGgC0s2v2XqeQ7H7k80aEN9YsIvl52 s2xBMdv2wRi+gFEyqtFyELAQrs1U8zl8OZjfJwHyytV5pVbO2smtxTvgnVQntEv227AGZ2yyJpD IqJ/Wtcj7cydgfoxCgcfw+KJ7lMbgyzadfBS48LeU/AO5rmxNAJukZqKVgLtaw3+56q/STM7v/K i2R3bogC3fH6z39Uw+esRtZ9/aSXkj0fml X-Received: by 2002:a05:6870:248b:b0:447:7db4:d287 with SMTP id 586e51a60fabf-4569014b90fmr7202228fac.16.1784557892458; Mon, 20 Jul 2026 07:31:32 -0700 (PDT) Received: from localhost ([2a03:2880:10ff:5e::]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-4568e6a91eesm8991109fac.13.2026.07.20.07.31.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2026 07:31:31 -0700 (PDT) From: Joshua Hahn To: Yichong Chen Cc: Muchun Song , Oscar Salvador , Andrew Morton , David Hildenbrand , Andrew Barry , David Gibson , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] hugetlb: fix subpool release race Date: Mon, 20 Jul 2026 07:31:29 -0700 Message-ID: <20260720143130.516711-1-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260720085024.1392261-1-chenyichong@uniontech.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hello Yichong, thank you for the patch! > unlock_or_release_subpool() drops spool->lock before checking whether the > subpool can be freed. However, subpool_is_free() reads fields that are > updated under spool->lock, including count, used_hpages and rsv_hpages. > > Another thread can update those fields before the first thread evaluates > subpool_is_free(), allowing both threads to observe the final freeable > state and release the subpool. I don't think that the race you are mentioning can be hit in practice (i.e. there is no user-visible change for this) since two threads cannot actually observe the freeable state at the same time. subpool_is_free() does an early exit on spool->count so it will never reach the inside if block and have two threads try to decrement the spool->hstate and free the spool twice. I'm wondering if we need the Fixes tag in this case. I do think that this is not obvious though, so having the subpool_is_free check inside the locked section makes sense to me too. Reviewed-by: Joshua Hahn Have a great day! Joshua > Make the free decision while still holding spool->lock. Keep the actual > hugetlb_acct_memory() and kfree() calls after dropping the lock. > Fixes: 90481622d757 ("hugepages: fix use after free bug in "quota" handling") > Signed-off-by: Yichong Chen > --- > mm/hugetlb.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index e319c6a00555..46ab702c0fc0 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -140,12 +140,14 @@ static inline bool subpool_is_free(struct hugepage_subpool *spool) > static inline void unlock_or_release_subpool(struct hugepage_subpool *spool, > unsigned long irq_flags) > { > - spin_unlock_irqrestore(&spool->lock, irq_flags); > + bool free_subpool = subpool_is_free(spool); > > /* If no pages are used, and no other handles to the subpool > * remain, give up any reservations based on minimum size and > * free the subpool */ > - if (subpool_is_free(spool)) { > + spin_unlock_irqrestore(&spool->lock, irq_flags); > + > + if (free_subpool) { > if (spool->min_hpages != -1) > hugetlb_acct_memory(spool->hstate, > -spool->min_hpages); > -- > 2.51.0