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 B62CA35AC1E; Sat, 12 Sep 2026 08:26:40 +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=1789201602; cv=none; b=KLUXsjMbZIXvlLVnsNgpT7Kse+jiegij/BkRzHtlRZAEh5+JFZDHgU/1XDUZQE9jfaOI3j2+nX5ZTeQMnalq44aTi+njyFOly9gm6rLDFU1xIWrrQ6bGRvsldck9DlytNnLIlUVzAMn70e2qOtUkypQUay7V+Dq9WPCRni1y0MM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789201602; c=relaxed/simple; bh=XsMIWYk7zwVZE85D3G5uO0W1FlQCGEb7qcvjHMrSxpc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=phK5vw7pRwnkOrkXFHBElg3BwmGRVrGxUKThkYvSmCCD7I3qXcfkLmer+iiYctZAC22hrp1/xla+5P53YmdcIIOLGypAvtInm38EM7xVJubrUEmpfRAohNXqDdaLr6gD/vdAUDZR84scgnb91a7XMs35+Jos7UlaxOjWHogXtG4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=BJvUF0Np; 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="BJvUF0Np" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C197C1F000FF; Sat, 12 Sep 2026 08:26:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789201600; bh=dtOAp63upr9oJo6OYwemnJXjs1hNXhwkLrRePrKL5hI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BJvUF0NpS4q9wLe0RhmR2QkrhB6WEz6DqbSgCGnwuH7Ny1BWne4djpdbAczi9bpxf 1giasTrQF5Iesr8Lq/x0HK9GV0jXRAcbQMIK8d7q2MunS9QQiHUoo9Aa0ql9FsqUj+ qU3EoskURfe7Oz8J7fxPosH0ieWTdiEhbJIFxpSM= 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 7.2 1029/1815] blk-cgroup: skip dying blkg in blkcg_activate_policy() Date: Sat, 12 Sep 2026 08:46:19 +0200 Message-ID: <20260912065713.175666095@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065648.999753832@linuxfoundation.org> References: <20260912065648.999753832@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 7.2-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 831df55a84454..52080c7c1a14b 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -1574,6 +1574,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