From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 7DACA33689F; Thu, 2 Jul 2026 16:52:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783011166; cv=none; b=gBsnHUbVxZZmm4xRTiU//nyF1uU9CAjbGoCHQbap81envM8Yq6zBwu+AzPAFmTFwhOGNP3nRy3I5n0BJvGGeECKpq4FDVi76te36tRiLahcJd27m71gCmtHuE0po8TlMm1Fl0RQIAtLp1gkC/IJiO7F5GXDkVv97Mew5iNKd8x8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783011166; c=relaxed/simple; bh=6NQEhYhKR+jcYWTptUKxA4HyvQUxHlzXcS0ino7WPYE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bfiT3q6Ifuh4z0dvl0iM1SWGM2rsDVz86Brvq/YZ90MnH03iYIoDinTlf0Ytbe2hVDAA+esocZLb7fy3+D4IPGC+sM/nk15o/Orzph4OVUQoROrEQw9Z96yz4d/nbo2QBiTz8p3rY57TELv/MYcaQAFLD+YtV8du66/zcfbiNfQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=TOOKKp/q; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="TOOKKp/q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB1301F000E9; Thu, 2 Jul 2026 16:52:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1783011165; bh=q7nWwbFyQoitSWRmMt6kYeRBbDvXtMVGUF/Lw2qV9lY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TOOKKp/qtdNWLUw1pZ4J6BQps4qcpJ5zPCVX4TyfORywilorytS4Ljk994HGfW6WW hM/JBrZb7L85mbm3TB39zdRQhOMyF+BEYs0Y7iCvK/qSpPT8V1GICx0Bc7ySxMu6aD jzPBFXl7u6PPPl+Sd1d5OMT7MBewvnr8jl0d56/U= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jay Shin , Tejun Heo , Waiman Long , coregee2000@gmail.com, Ming Lei , "Jose Fernandez (Anthropic)" , Jens Axboe Subject: [PATCH 6.6 147/175] blk-cgroup: fix UAF in __blkcg_rstat_flush() Date: Thu, 2 Jul 2026 18:20:48 +0200 Message-ID: <20260702155118.901771463@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260702155115.766838875@linuxfoundation.org> References: <20260702155115.766838875@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michal Koutný commit 0ab5ee5a1badb58cbb2242617cb01a4972b1f2a2 upstream. When multiple blkgs in the same blkcg are released concurrently, a use-after-free can occur. The race happens when one blkg's __blkcg_rstat_flush() removes another blkg's iostat entries via llist_del_all(). The second blkg sees an empty list and proceeds to free itself while the first is still iterating over its entries. Move the flush from __blkg_release() (RCU callback) to blkg_release() (before call_rcu). This ensures the RCU grace period waits for any concurrent flush's rcu_read_lock() section to complete before freeing. Cc: stable@vger.kernel.org Cc: Jay Shin Cc: Tejun Heo Cc: Waiman Long Fixes: 20cb1c2fb756 ("blk-cgroup: Flush stats before releasing blkcg_gq") Reported-by: coregee2000@gmail.com Closes: https://lore.kernel.org/linux-block/CAHPqNmwT9oRpem3J3erS_W0uSQND47LGGSBsNxP8E6uSUish1w@mail.gmail.com/ Signed-off-by: Ming Lei Tested-by: Jose Fernandez (Anthropic) Link: https://patch.msgid.link/20260205155425.342084-1-ming.lei@redhat.com Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/blk-cgroup.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -170,20 +170,10 @@ static void blkg_free(struct blkcg_gq *b static void __blkg_release(struct rcu_head *rcu) { struct blkcg_gq *blkg = container_of(rcu, struct blkcg_gq, rcu_head); - struct blkcg *blkcg = blkg->blkcg; - int cpu; #ifdef CONFIG_BLK_CGROUP_PUNT_BIO WARN_ON(!bio_list_empty(&blkg->async_bios)); #endif - /* - * Flush all the non-empty percpu lockless lists before releasing - * us, given these stat belongs to us. - * - * blkg_stat_lock is for serializing blkg stat update - */ - for_each_possible_cpu(cpu) - __blkcg_rstat_flush(blkcg, cpu); /* release the blkcg and parent blkg refs this blkg has been holding */ css_put(&blkg->blkcg->css); @@ -201,6 +191,17 @@ static void __blkg_release(struct rcu_he static void blkg_release(struct percpu_ref *ref) { struct blkcg_gq *blkg = container_of(ref, struct blkcg_gq, refcnt); + struct blkcg *blkcg = blkg->blkcg; + int cpu; + + /* + * Flush all the non-empty percpu lockless lists before releasing + * us, given these stat belongs to us. + * + * blkg_stat_lock is for serializing blkg stat update + */ + for_each_possible_cpu(cpu) + __blkcg_rstat_flush(blkcg, cpu); call_rcu(&blkg->rcu_head, __blkg_release); }