mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-10 23:29:46 +00:00
rbd: don't leak parent_spec in rbd_dev_probe_parent()
Currently we leak parent_spec and trigger a "parent reference underflow" warning if rbd_dev_create() in rbd_dev_probe_parent() fails. The problem is we take the !parent out_err branch and that only drops refcounts; parent_spec that would've been freed had we called rbd_dev_unparent() remains and triggers rbd_warn() in rbd_dev_parent_put() - at that point we have parent_spec != NULL and parent_ref == 0, so counter ends up being -1 after the decrement. Redo rbd_dev_probe_parent() to fix this. Cc: stable@vger.kernel.org # 3.10+, needs backporting for < 4.2 Signed-off-by: Ilya Dryomov <idryomov@gmail.com> Reviewed-by: Alex Elder <elder@linaro.org>
This commit is contained in:
parent
7379047d55
commit
1f2c6651f6
@ -5134,41 +5134,37 @@ out_err:
|
|||||||
static int rbd_dev_probe_parent(struct rbd_device *rbd_dev)
|
static int rbd_dev_probe_parent(struct rbd_device *rbd_dev)
|
||||||
{
|
{
|
||||||
struct rbd_device *parent = NULL;
|
struct rbd_device *parent = NULL;
|
||||||
struct rbd_spec *parent_spec;
|
|
||||||
struct rbd_client *rbdc;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!rbd_dev->parent_spec)
|
if (!rbd_dev->parent_spec)
|
||||||
return 0;
|
return 0;
|
||||||
/*
|
|
||||||
* We need to pass a reference to the client and the parent
|
|
||||||
* spec when creating the parent rbd_dev. Images related by
|
|
||||||
* parent/child relationships always share both.
|
|
||||||
*/
|
|
||||||
parent_spec = rbd_spec_get(rbd_dev->parent_spec);
|
|
||||||
rbdc = __rbd_get_client(rbd_dev->rbd_client);
|
|
||||||
|
|
||||||
ret = -ENOMEM;
|
parent = rbd_dev_create(rbd_dev->rbd_client, rbd_dev->parent_spec,
|
||||||
parent = rbd_dev_create(rbdc, parent_spec, NULL);
|
NULL);
|
||||||
if (!parent)
|
if (!parent) {
|
||||||
|
ret = -ENOMEM;
|
||||||
goto out_err;
|
goto out_err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Images related by parent/child relationships always share
|
||||||
|
* rbd_client and spec/parent_spec, so bump their refcounts.
|
||||||
|
*/
|
||||||
|
__rbd_get_client(rbd_dev->rbd_client);
|
||||||
|
rbd_spec_get(rbd_dev->parent_spec);
|
||||||
|
|
||||||
ret = rbd_dev_image_probe(parent, false);
|
ret = rbd_dev_image_probe(parent, false);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out_err;
|
goto out_err;
|
||||||
|
|
||||||
rbd_dev->parent = parent;
|
rbd_dev->parent = parent;
|
||||||
atomic_set(&rbd_dev->parent_ref, 1);
|
atomic_set(&rbd_dev->parent_ref, 1);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
out_err:
|
|
||||||
if (parent) {
|
|
||||||
rbd_dev_unparent(rbd_dev);
|
|
||||||
rbd_dev_destroy(parent);
|
|
||||||
} else {
|
|
||||||
rbd_put_client(rbdc);
|
|
||||||
rbd_spec_put(parent_spec);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
out_err:
|
||||||
|
rbd_dev_unparent(rbd_dev);
|
||||||
|
if (parent)
|
||||||
|
rbd_dev_destroy(parent);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user