Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1587369
| From | Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 4.4 23/25] block: fix double-free in the failure path of cgwb_bdi_init() |
| Date | 2017-02-24 09:40 +0100 |
| Message-ID | <tejzZ-5Xe-53@gated-at.bofh.it> (permalink) |
| References | <tejqh-5Sb-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
4.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tejun Heo <tj@kernel.org>
commit 5f478e4ea5c5560b4e40eb136991a09f9389f331 upstream.
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")
Signed-off-by: Jens Axboe <axboe@fb.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
mm/backing-dev.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
--- a/mm/backing-dev.c
+++ b/mm/backing-dev.c
@@ -757,15 +757,20 @@ static int cgwb_bdi_init(struct backing_
if (!bdi->wb_congested)
return -ENOMEM;
+ atomic_set(&bdi->wb_congested->refcnt, 1);
+
err = wb_init(&bdi->wb, bdi, 1, GFP_KERNEL);
if (err) {
- kfree(bdi->wb_congested);
+ wb_congested_put(bdi->wb_congested);
return err;
}
return 0;
}
-static void cgwb_bdi_destroy(struct backing_dev_info *bdi) { }
+static void cgwb_bdi_destroy(struct backing_dev_info *bdi)
+{
+ wb_congested_put(bdi->wb_congested);
+}
#endif /* CONFIG_CGROUP_WRITEBACK */
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 4.4 00/25] 4.4.52-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-24 09:40 +0100
[PATCH 4.4 23/25] block: fix double-free in the failure path of cgwb_bdi_init() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-24 09:40 +0100
[PATCH 4.4 15/25] USB: serial: ftdi_sio: fix extreme low-latency setting Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-24 09:40 +0100
[PATCH 4.4 06/25] packet: Do not call fanout_release from atomic contexts Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-24 09:40 +0100
[PATCH 4.4 13/25] USB: serial: cp210x: add new IDs for GE Bx50v3 boards Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-24 09:40 +0100
Re: [PATCH 4.4 00/25] 4.4.52-stable review Ben Hutchings <ben@decadent.org.uk> - 2017-02-24 15:00 +0100
Re: [PATCH 4.4 00/25] 4.4.52-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-24 15:50 +0100
Re: [PATCH 4.4 00/25] 4.4.52-stable review David Miller <davem@davemloft.net> - 2017-02-24 16:50 +0100
Re: [PATCH 4.4 00/25] 4.4.52-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-02-24 16:50 +0100
Re: [PATCH 4.4 00/25] 4.4.52-stable review Ben Hutchings <ben@decadent.org.uk> - 2017-02-24 17:40 +0100
Re: [PATCH 4.4 00/25] 4.4.52-stable review Guenter Roeck <linux@roeck-us.net> - 2017-02-24 17:30 +0100
Re: [PATCH 4.4 00/25] 4.4.52-stable review Shuah Khan <shuahkh@osg.samsung.com> - 2017-02-24 19:20 +0100
csiph-web