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 089AF369D72; Sat, 12 Sep 2026 12:45:25 +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=1789217127; cv=none; b=YYHbcHuAV8mrnf1j3YFimoMUaZOGJEmcuODFsJz9dOLmDbldevzTzxwekhCLVKZZOqTE8iuXUgN3pwxJXqD0opW6v2B3kcIlMRt6YClJwuyz4kn7ASZmUNRQFNOrIguwMQ3UxfHo0cv+NmlSgUI8UO7xZNaTMtkfUa1CbgmRf9Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789217127; c=relaxed/simple; bh=VfWLUR+SNffC2Xnt2SQ3V0Qk3ljZBMdtxgWuZyU/drY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LTolgoT3kcTGv4sJF6mIKetOWtZ4v0o0mZBzxrYMaDFm6bT6D6ZmtTshPrKaoq8u+y1b9dH4rBNRGFFJQdnD9zayXZbPsTGFi805xsKhrG36YpRAsbJIXw97G3LAFeG+1F5NbRGUS92TNhl5P0nYZFbwrihYJ8J2FPj+2hEw1iI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=nGmATqNn; 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="nGmATqNn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 849681F000FF; Sat, 12 Sep 2026 12:45:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789217125; bh=Aehk8XHr/UH0pzZbKXxnTnuKhf0TVeEx3Y6fBYudI54=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nGmATqNn0NAmV20HR0NL29u5unW8K0EVsmnvGKh6WvtxCSM3iI/HD38VvPEOted5c SbcLWZwqMZRizoX0onWBS5taZ+sWovuN0EPFU274YLp6eg/YzeoYuAr+n9IGyRL65P TggbY1FJGFC4LdzZrYyfwHJ5m0bpLD1KUOGk1w/A= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zheng Qixing , Tang Yizhou , Yu Kuai , Tao Cui , Nilay Shroff , Jens Axboe , Sasha Levin Subject: [PATCH 6.12 0875/1376] blk-cgroup: skip dying blkg in blkcg_activate_policy() Date: Sat, 12 Sep 2026 08:55:01 +0200 Message-ID: <20260912065627.058573794@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065607.535295758@linuxfoundation.org> References: <20260912065607.535295758@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-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zheng Qixing [ Upstream commit 5e9220389920f33b6a804d50c548cd0cd1b04634 ] When switching IO schedulers on a block device, blkcg_activate_policy() can race with concurrent blkcg deletion, leading to a use-after-free in rcu_accelerate_cbs. T1: T2: blkg_destroy kill(&blkg->refcnt) // blkg->refcnt=1->0 blkg_release // call_rcu(__blkg_release) ... blkg_free_workfn ->pd_free_fn(pd) elv_iosched_store elevator_switch ... iterate blkg list blkg_get(blkg) // blkg->refcnt=0->1 list_del_init(&blkg->q_node) blkg_put(pinned_blkg) // blkg->refcnt=1->0 blkg_release // call_rcu again rcu_accelerate_cbs // uaf Fix this by checking hlist_unhashed(&blkg->blkcg_node) before getting a reference to the blkg. This is the same check used in blkg_destroy() to detect if a blkg has already been destroyed. If the blkg is already unhashed, skip processing it since it's being destroyed. Fixes: f1c006f1c685 ("blk-cgroup: synchronize pd_free_fn() from blkg_free_workfn() and blkcg_deactivate_policy()") Signed-off-by: Zheng Qixing Reviewed-by: Tang Yizhou Signed-off-by: Yu Kuai Reviewed-by: Tao Cui Reviewed-by: Nilay Shroff Link: https://patch.msgid.link/20260802112525.3933753-4-yukuai@kernel.org Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/blk-cgroup.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index d95104f0fcdcf..8e7e2db4d1c27 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -1573,6 +1573,8 @@ int blkcg_activate_policy(struct gendisk *disk, const struct blkcg_policy *pol) if (blkg->pd[pol->plid]) continue; + if (hlist_unhashed(&blkg->blkcg_node)) + continue; /* If prealloc matches, use it; otherwise try GFP_NOWAIT */ if (blkg == pinned_blkg) { -- 2.53.0