From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from n169-114.mail.139.com (n169-114.mail.139.com [120.232.169.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B39D8391831 for ; Mon, 27 Apr 2026 07:26:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=120.232.169.114 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777274805; cv=none; b=tWvikM3/HVJXF7YYbguBryjifWi7Hh4FdVDVRBO10VsVnx1S10d8MCPAQS3ZkZxUUF85VeQsi/BjyhVmKw4H3cT5gMMRmKdeeFrJ9m2t6ptgABmeDtXss8TC2WljR5XGnNbu52iZw+xoJtOsdazBPZF3XRMEmSiycextTMs3aMU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777274805; c=relaxed/simple; bh=BQQqT4AOzgFMp/SQ1dyADRcp2O5bWJyigf5phSoYQRw=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=N/e2PnYOq12TKgWI4lEidBybXvP07kNZn8jqTG149nz3bXKlh/DJQtZIitPJX/GbBbQBWEXghY1pIWJeMrDc0661S97M/FihMxbB9hLm3qpu0Sx2k452Gzup7QqPifOhjIqSGDmSSF+Ub//JnAsDV/wowU8LvPF/ptwbtmmHdJE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=139.com; spf=pass smtp.mailfrom=139.com; dkim=pass (1024-bit key) header.d=139.com header.i=@139.com header.b=AcVokKVG; arc=none smtp.client-ip=120.232.169.114 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=139.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=139.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=139.com header.i=@139.com header.b="AcVokKVG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=139.com; s=dkim; l=0; h=from:subject:message-id:to:mime-version; bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=; b=AcVokKVGHZQ2c1UCBBDYn2AMOM6W7FOqeDXPguqSEbAWjPXva50ADALJj1W92aAu4Fx2IfuBC6sZB L+qZEB4Dr1TAOYqIgUHsKUEc/n7WkyFT9MOYLj6Wa8Bt0b5uy9ZHiXYDMScX8wzPqAlqy7/AuN/2PX aVPTw0h9oBwQyzbU= X-RM-TagInfo: emlType=0 X-RM-SPAM: X-RM-SPAM-FLAG:00000000 Received:from China-Mobile-Kernel-Team (unknown[39.144.79.222]) by rmsmtp-lg-appmail-45-12076 (RichMail) with SMTP id 2f2c69ef0fa4527-f0d9e; Mon, 27 Apr 2026 15:26:31 +0800 (CST) X-RM-TRANSID:2f2c69ef0fa4527-f0d9e From: Leon Chen To: yukuai3@huawei.com, tj@kernel.org, hch@lst.de, axboe@kernel.dk, stable@vger.kernel.org Subject: [PATCH 6.1.y] blk-cgroup: dropping parent refcount after pd_free_fn() is done Date: Mon, 27 Apr 2026 15:26:28 +0800 Message-Id: <20260427072628.8511-1-leonchen.oss@139.com> X-Mailer: git-send-email 2.35.3 Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Yu Kuai [ Upstream commit c7241babf0855d8a6180cd1743ff0ec34de40b4e ] Some cgroup policies will access parent pd through child pd even after pd_offline_fn() is done. If pd_free_fn() for parent is called before child, then UAF can be triggered. Hence it's better to guarantee the order of pd_free_fn(). Currently refcount of parent blkg is dropped in __blkg_release(), which is before pd_free_fn() is called in blkg_free_work_fn() while blkg_free_work_fn() is called asynchronously. This patch make sure pd_free_fn() called from removing cgroup is ordered by delaying dropping parent refcount after calling pd_free_fn() for child. BTW, pd_free_fn() will also be called from blkcg_deactivate_policy() from deleting device, and following patches will guarantee the order. Signed-off-by: Yu Kuai Acked-by: Tejun Heo Reviewed-by: Christoph Hellwig Link: https://lore.kernel.org/r/20230119110350.2287325-2-yukuai1@huaweicloud.com Signed-off-by: Jens Axboe Signed-off-by: Leon Chen --- block/blk-cgroup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index f314192b6de8..2f25ae78506c 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -93,6 +93,8 @@ static void blkg_free_workfn(struct work_struct *work) if (blkg->pd[i]) blkcg_policy[i]->pd_free_fn(blkg->pd[i]); + if (blkg->parent) + blkg_put(blkg->parent); if (blkg->q) blk_put_queue(blkg->q); free_percpu(blkg->iostat_cpu); @@ -127,8 +129,6 @@ static void __blkg_release(struct rcu_head *rcu) /* release the blkcg and parent blkg refs this blkg has been holding */ css_put(&blkg->blkcg->css); - if (blkg->parent) - blkg_put(blkg->parent); blkg_free(blkg); } -- 2.35.3