linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] block, bfq: fix UAF problem in bfqg_stats_init()
@ 2021-10-18  2:42 Zheng Liang
  2021-10-19 18:02 ` Tejun Heo
  2021-10-19 21:18 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Zheng Liang @ 2021-10-18  2:42 UTC (permalink / raw)
  To: tj, axboe; +Cc: paolo.valente, cgroups, linux-block, zhengliang6, yi.zhang

In bfq_pd_alloc(), the function bfqg_stats_init() init bfqg. If
blkg_rwstat_init() init bfqg_stats->bytes successful and init
bfqg_stats->ios failed, bfqg_stats_init() return failed, bfqg will
be freed. But blkg_rwstat->cpu_cnt is not deleted from the list of
percpu_counters. If we traverse the list of percpu_counters, It will
have UAF problem.

we should use blkg_rwstat_exit() to cleanup bfqg_stats bytes in the
above scenario.

Fixes: commit fd41e60331b ("bfq-iosched: stop using blkg->stat_bytes and ->stat_ios")
Signed-off-by: Zheng Liang <zhengliang6@huawei.com>
---
Changes since v1:
    Change some description for this patch
---
 block/bfq-cgroup.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c
index e2f14508f2d6..243ffbc1f106 100644
--- a/block/bfq-cgroup.c
+++ b/block/bfq-cgroup.c
@@ -463,7 +463,7 @@ static int bfqg_stats_init(struct bfqg_stats *stats, gfp_t gfp)
 {
 	if (blkg_rwstat_init(&stats->bytes, gfp) ||
 	    blkg_rwstat_init(&stats->ios, gfp))
-		return -ENOMEM;
+		goto error;
 
 #ifdef CONFIG_BFQ_CGROUP_DEBUG
 	if (blkg_rwstat_init(&stats->merged, gfp) ||
@@ -476,13 +476,15 @@ static int bfqg_stats_init(struct bfqg_stats *stats, gfp_t gfp)
 	    bfq_stat_init(&stats->dequeue, gfp) ||
 	    bfq_stat_init(&stats->group_wait_time, gfp) ||
 	    bfq_stat_init(&stats->idle_time, gfp) ||
-	    bfq_stat_init(&stats->empty_time, gfp)) {
-		bfqg_stats_exit(stats);
-		return -ENOMEM;
-	}
+	    bfq_stat_init(&stats->empty_time, gfp))
+		goto error;
 #endif
 
 	return 0;
+
+error:
+	bfqg_stats_exit(stats);
+	return -ENOMEM;
 }
 
 static struct bfq_group_data *cpd_to_bfqgd(struct blkcg_policy_data *cpd)
-- 
2.25.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] block, bfq: fix UAF problem in bfqg_stats_init()
  2021-10-18  2:42 [PATCH v2] block, bfq: fix UAF problem in bfqg_stats_init() Zheng Liang
@ 2021-10-19 18:02 ` Tejun Heo
  2021-10-19 21:18 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Tejun Heo @ 2021-10-19 18:02 UTC (permalink / raw)
  To: Zheng Liang; +Cc: axboe, paolo.valente, cgroups, linux-block, yi.zhang

On Mon, Oct 18, 2021 at 10:42:25AM +0800, Zheng Liang wrote:
> In bfq_pd_alloc(), the function bfqg_stats_init() init bfqg. If
> blkg_rwstat_init() init bfqg_stats->bytes successful and init
> bfqg_stats->ios failed, bfqg_stats_init() return failed, bfqg will
> be freed. But blkg_rwstat->cpu_cnt is not deleted from the list of
> percpu_counters. If we traverse the list of percpu_counters, It will
> have UAF problem.
> 
> we should use blkg_rwstat_exit() to cleanup bfqg_stats bytes in the
> above scenario.
> 
> Fixes: commit fd41e60331b ("bfq-iosched: stop using blkg->stat_bytes and ->stat_ios")
> Signed-off-by: Zheng Liang <zhengliang6@huawei.com>

Acked-by: Tejun Heo <tj@kernel.org>

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] block, bfq: fix UAF problem in bfqg_stats_init()
  2021-10-18  2:42 [PATCH v2] block, bfq: fix UAF problem in bfqg_stats_init() Zheng Liang
  2021-10-19 18:02 ` Tejun Heo
@ 2021-10-19 21:18 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2021-10-19 21:18 UTC (permalink / raw)
  To: Zheng Liang, tj; +Cc: Jens Axboe, paolo.valente, yi.zhang, cgroups, linux-block

On Mon, 18 Oct 2021 10:42:25 +0800, Zheng Liang wrote:
> In bfq_pd_alloc(), the function bfqg_stats_init() init bfqg. If
> blkg_rwstat_init() init bfqg_stats->bytes successful and init
> bfqg_stats->ios failed, bfqg_stats_init() return failed, bfqg will
> be freed. But blkg_rwstat->cpu_cnt is not deleted from the list of
> percpu_counters. If we traverse the list of percpu_counters, It will
> have UAF problem.
> 
> [...]

Applied, thanks!

[1/1] block, bfq: fix UAF problem in bfqg_stats_init()
      commit: 2fc428f6b7ca80794cb9928c90d4de524366659f

Best regards,
-- 
Jens Axboe



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-10-19 21:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-18  2:42 [PATCH v2] block, bfq: fix UAF problem in bfqg_stats_init() Zheng Liang
2021-10-19 18:02 ` Tejun Heo
2021-10-19 21:18 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).