diff options
author | Tejun Heo <tj@kernel.org> | 2017-02-08 15:19:07 -0500 |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2017-02-08 15:52:01 -0500 |
commit | 5f478e4ea5c5560b4e40eb136991a09f9389f331 (patch) | |
tree | fe56dd348c269126a8ec1bc7d290b30b0b3f60a7 /mm/backing-dev.c | |
parent | b35ba01ea6979125e9c23fb322517748278f15e6 (diff) |
block: fix double-free in the failure path of cgwb_bdi_init()
When !CONFIG_CGROUP_WRITEBACK, bdi has single bdi_writeback_congested
at bdi->wb_congested. cgwb_bdi_init() allocates it with kzalloc() and
doesn't do further initialization. This usually works fine as the
reference count gets bumped to 1 by wb_init() and the put from
wb_exit() releases it.
However, when wb_init() fails, it puts the wb base ref automatically
freeing the wb and the explicit kfree() in cgwb_bdi_init() error path
ends up trying to free the same pointer the second time causing a
double-free.
Fix it by explicitly initilizing the refcnt to 1 and putting the base
ref from cgwb_bdi_destroy().
Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Dmitry Vyukov <dvyukov@google.com>
Fixes: a13f35e87140 ("writeback: don't embed root bdi_writeback_congested in bdi_writeback")
Cc: stable@vger.kernel.org # v4.2+
Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'mm/backing-dev.c')
-rw-r--r-- | mm/backing-dev.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/mm/backing-dev.c b/mm/backing-dev.c index 28ce6cf7b2ff..39ce616a9d71 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c | |||
@@ -759,15 +759,20 @@ static int cgwb_bdi_init(struct backing_dev_info *bdi) | |||
759 | if (!bdi->wb_congested) | 759 | if (!bdi->wb_congested) |
760 | return -ENOMEM; | 760 | return -ENOMEM; |
761 | 761 | ||
762 | atomic_set(&bdi->wb_congested->refcnt, 1); | ||
763 | |||
762 | err = wb_init(&bdi->wb, bdi, 1, GFP_KERNEL); | 764 | err = wb_init(&bdi->wb, bdi, 1, GFP_KERNEL); |
763 | if (err) { | 765 | if (err) { |
764 | kfree(bdi->wb_congested); | 766 | wb_congested_put(bdi->wb_congested); |
765 | return err; | 767 | return err; |
766 | } | 768 | } |
767 | return 0; | 769 | return 0; |
768 | } | 770 | } |
769 | 771 | ||
770 | static void cgwb_bdi_destroy(struct backing_dev_info *bdi) { } | 772 | static void cgwb_bdi_destroy(struct backing_dev_info *bdi) |
773 | { | ||
774 | wb_congested_put(bdi->wb_congested); | ||
775 | } | ||
771 | 776 | ||
772 | #endif /* CONFIG_CGROUP_WRITEBACK */ | 777 | #endif /* CONFIG_CGROUP_WRITEBACK */ |
773 | 778 | ||