]> git.baikalelectronics.ru Git - kernel.git/commit
blkcg: Fix multiple bugs in blkcg_activate_policy()
authorTejun Heo <tj@kernel.org>
Tue, 15 Oct 2019 16:03:47 +0000 (09:03 -0700)
committerJens Axboe <axboe@kernel.dk>
Tue, 15 Oct 2019 16:13:00 +0000 (10:13 -0600)
commitcad152e6e9874355ddc49d7a54e83ea24178eef9
treeebce8fe05f478889be94075edf4e75e34763e349
parent133103d433c72060d6a6f34294553e50d4bb6598
blkcg: Fix multiple bugs in blkcg_activate_policy()

blkcg_activate_policy() has the following bugs.

6783a45170f2 ("blkcg: pass @q and @blkcg into
  blkcg_pol_alloc_pd_fn()") added @blkcg to ->pd_alloc_fn(); however,
  blkcg_activate_policy() ends up using pd's allocated for the root
  blkcg for all preallocations, so ->pd_init_fn() for non-root blkcgs
  can be passed in pd's which are allocated for the root blkcg.

  For blk-iocost, this means that ->pd_init_fn() can write beyond the
  end of the allocated object as it determines the length of the flex
  array at the end based on the blkcg's nesting level.

* Each pd is initialized as they get allocated.  If alloc fails, the
  policy will get freed with pd's initialized on it.

* After the above partial failure, the partial pds are not freed.

This patch fixes all the above issues by

* Restructuring blkcg_activate_policy() so that alloc and init passes
  are separate.  Init takes place only after all allocs succeeded and
  on failure all allocated pds are freed.

* Unifying and fixing the cleanup of the remaining pd_prealloc.

Signed-off-by: Tejun Heo <tj@kernel.org>
Fixes: 6783a45170f2 ("blkcg: pass @q and @blkcg into blkcg_pol_alloc_pd_fn()")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-cgroup.c