Backports of 1f2c6651f69c and 6d69bb536bac
Subsystems (3)
Ilya Dryomov
maintainerHi Greg,
These are backports of mainline 1f2c6651f69c ("rbd: don't leak parent_spec in rbd_dev_probe_parent()") and 6d69bb536bac ("rbd: prevent kernel stack blow up on rbd map") for 3.10, 3.14 and 4.1. Please apply:
- 1st and 2nd patches for 3.10
- 1st and 3rd patches for 3.14
- 1st and 4th patches for 4.1
- for 4.2 cherry-pick from mainline
Thanks,
Ilya
Ilya Dryomov
maintainerPATCH 1/1 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.
--- drivers/block/rbd.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-)
drivers/block/rbd.c +15 -20
@@ -5145,41 +5145,36 @@ out_err:static int rbd_dev_probe_parent (struct rbd_device *rbd_dev) {struct rbd_device *parent =NULL ; -struct rbd_spec *parent_spec; -struct rbd_client *rbdc;int ret;if (!rbd_dev->parent_spec)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 (rbdc, parent_spec); -if (!parent) + parent =rbd_dev_create (rbd_dev->rbd_client, rbd_dev->parent_spec); +if (!parent) { + ret = -ENOMEM ; 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);if (ret <0 ) goto out_err; + rbd_dev->parent = parent;atomic_set (&rbd_dev->parent_ref,1 ); -return 0 ; + out_err: -if (parent) { -rbd_dev_unparent (rbd_dev); +rbd_dev_unparent (rbd_dev); +if (parent)rbd_dev_destroy (parent); - }else { -rbd_put_client (rbdc); -rbd_spec_put (parent_spec); - } -return ret; }
Signature · 1 line
2.4.3
Ilya Dryomov
maintainerPATCH 1/1 rbd: prevent kernel stack blow up on rbd map
In reply to Ilya DryomovMapping an image with a long parent chain (e.g. image foo, whose parent is bar, whose parent is baz, etc) currently leads to a kernel stack overflow, due to the following recursion in the reply path:
rbd_osd_req_callback()
rbd_obj_request_complete()
rbd_img_obj_callback()
rbd_img_parent_read_callback()
rbd_obj_request_complete()
...Limit the parent chain to 16 images, which is ~5K worth of stack. When the above recursion is eliminated, this limit can be lifted.
--- drivers/block/rbd.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-)
drivers/block/rbd.c +21 -8
@@ -93,6 +93,8 @@ static int atomic_dec_return_safe(atomic_t *v)#define RBD_MINORS_PER_MAJOR 256/* max minors per blkdev */ +#define RBD_MAX_PARENT_CHAIN_LEN 16 +#define RBD_SNAP_DEV_NAME_PREFIX "snap_"#define RBD_MAX_SNAP_NAME_LEN \ (NAME_MAX - (sizeof (RBD_SNAP_DEV_NAME_PREFIX) - 1))
@@ -394,7 +396,7 @@ static ssize_t rbd_add(struct bus_type *bus, const char *buf, size_t count);static ssize_t rbd_remove (struct bus_type *bus,const char *buf,size_t count); -static int rbd_dev_image_probe (struct rbd_device *rbd_dev,bool mapping); +static int rbd_dev_image_probe (struct rbd_device *rbd_dev,int depth);static void rbd_spec_put (struct rbd_spec *spec);static struct bus_attribute rbd_bus_attrs[] = {
@@ -4828,7 +4830,12 @@ out_err:return ret; } -static int rbd_dev_probe_parent (struct rbd_device *rbd_dev) +/* +* @depth is rbd_dev_image_probe() -> rbd_dev_probe_parent() -> +* rbd_dev_image_probe() recursion depth, which means it's also the +* length of the already discovered part of the parent chain. +*/ +static int rbd_dev_probe_parent (struct rbd_device *rbd_dev,int depth) {struct rbd_device *parent =NULL ;int ret;
@@ -4836,6 +4843,12 @@ static int rbd_dev_probe_parent(struct rbd_device *rbd_dev)if (!rbd_dev->parent_spec)return 0 ; +if (++depth >RBD_MAX_PARENT_CHAIN_LEN ) { +pr_info ("parent chain is too long (%d)\n" , depth); + ret = -EINVAL ; + goto out_err; + } + parent =rbd_dev_create (rbd_dev->rbd_client, rbd_dev->parent_spec);if (!parent) { ret = -ENOMEM ;
@@ -4849,7 +4862,7 @@ static int rbd_dev_probe_parent(struct rbd_device *rbd_dev)__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, depth);if (ret <0 ) goto out_err;
@@ -4966,7 +4979,7 @@ static void rbd_dev_image_release(struct rbd_device *rbd_dev)* parent), initiate a watch on its header object before using that * object to get detailed information about the rbd image. */ -static int rbd_dev_image_probe (struct rbd_device *rbd_dev,bool mapping) +static int rbd_dev_image_probe (struct rbd_device *rbd_dev,int depth) {int ret;int tmp;
@@ -4987,7 +5000,7 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, bool mapping)if (ret) goto err_out_format; -if (mapping) { +if (!depth) { ret =rbd_dev_header_watch_sync (rbd_dev, true);if (ret) goto out_header_name;
@@ -5004,7 +5017,7 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, bool mapping)if (ret) goto err_out_probe; - ret =rbd_dev_probe_parent (rbd_dev); + ret =rbd_dev_probe_parent (rbd_dev, depth);if (ret) goto err_out_probe;
@@ -5015,7 +5028,7 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, bool mapping) err_out_probe:rbd_dev_unprobe (rbd_dev); err_out_watch: -if (mapping) { +if (!depth) { tmp =rbd_dev_header_watch_sync (rbd_dev, false);if (tmp) rbd_warn(rbd_dev, "unable to tear down "
@@ -5086,7 +5099,7 @@ static ssize_t rbd_add(struct bus_type *bus, rbdc =NULL ;/* rbd_dev now owns this */ spec =NULL ;/* rbd_dev now owns this */ - rc =rbd_dev_image_probe (rbd_dev, true); + rc =rbd_dev_image_probe (rbd_dev,0 );if (rc <0 ) goto err_out_rbd_dev;
Signature · 1 line
2.4.3
Ilya Dryomov
maintainerPATCH 1/1 rbd: prevent kernel stack blow up on rbd map
In reply to Ilya DryomovMapping an image with a long parent chain (e.g. image foo, whose parent is bar, whose parent is baz, etc) currently leads to a kernel stack overflow, due to the following recursion in the reply path:
rbd_osd_req_callback()
rbd_obj_request_complete()
rbd_img_obj_callback()
rbd_img_parent_read_callback()
rbd_obj_request_complete()
...Limit the parent chain to 16 images, which is ~5K worth of stack. When the above recursion is eliminated, this limit can be lifted.
--- drivers/block/rbd.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-)
drivers/block/rbd.c +21 -8
@@ -94,6 +94,8 @@ static int atomic_dec_return_safe(atomic_t *v)#define RBD_MINORS_PER_MAJOR 256#define RBD_SINGLE_MAJOR_PART_SHIFT 4 +#define RBD_MAX_PARENT_CHAIN_LEN 16 +#define RBD_SNAP_DEV_NAME_PREFIX "snap_"#define RBD_MAX_SNAP_NAME_LEN \ (NAME_MAX - (sizeof (RBD_SNAP_DEV_NAME_PREFIX) - 1))
@@ -411,7 +413,7 @@ static ssize_t rbd_add_single_major(struct bus_type *bus, const char *buf, size_t count);static ssize_t rbd_remove_single_major (struct bus_type *bus,const char *buf,size_t count); -static int rbd_dev_image_probe (struct rbd_device *rbd_dev,bool mapping); +static int rbd_dev_image_probe (struct rbd_device *rbd_dev,int depth);static void rbd_spec_put (struct rbd_spec *spec);static int rbd_dev_id_to_minor (int dev_id)
@@ -4819,7 +4821,12 @@ out_err:return ret; } -static int rbd_dev_probe_parent (struct rbd_device *rbd_dev) +/* +* @depth is rbd_dev_image_probe() -> rbd_dev_probe_parent() -> +* rbd_dev_image_probe() recursion depth, which means it's also the +* length of the already discovered part of the parent chain. +*/ +static int rbd_dev_probe_parent (struct rbd_device *rbd_dev,int depth) {struct rbd_device *parent =NULL ;int ret;
@@ -4827,6 +4834,12 @@ static int rbd_dev_probe_parent(struct rbd_device *rbd_dev)if (!rbd_dev->parent_spec)return 0 ; +if (++depth >RBD_MAX_PARENT_CHAIN_LEN ) { +pr_info ("parent chain is too long (%d)\n" , depth); + ret = -EINVAL ; + goto out_err; + } + parent =rbd_dev_create (rbd_dev->rbd_client, rbd_dev->parent_spec);if (!parent) { ret = -ENOMEM ;
@@ -4840,7 +4853,7 @@ static int rbd_dev_probe_parent(struct rbd_device *rbd_dev)__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, depth);if (ret <0 ) goto out_err;
@@ -4967,7 +4980,7 @@ static void rbd_dev_image_release(struct rbd_device *rbd_dev)* parent), initiate a watch on its header object before using that * object to get detailed information about the rbd image. */ -static int rbd_dev_image_probe (struct rbd_device *rbd_dev,bool mapping) +static int rbd_dev_image_probe (struct rbd_device *rbd_dev,int depth) {int ret;
@@ -4987,7 +5000,7 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, bool mapping)if (ret) goto err_out_format; -if (mapping) { +if (!depth) { ret =rbd_dev_header_watch_sync (rbd_dev);if (ret) goto out_header_name;
@@ -5004,7 +5017,7 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, bool mapping)if (ret) goto err_out_probe; - ret =rbd_dev_probe_parent (rbd_dev); + ret =rbd_dev_probe_parent (rbd_dev, depth);if (ret) goto err_out_probe;
@@ -5015,7 +5028,7 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, bool mapping) err_out_probe:rbd_dev_unprobe (rbd_dev); err_out_watch: -if (mapping) +if (!depth)rbd_dev_header_unwatch_sync (rbd_dev); out_header_name:kfree (rbd_dev->header_name);
@@ -5082,7 +5095,7 @@ static ssize_t do_rbd_add(struct bus_type *bus, rbdc =NULL ;/* rbd_dev now owns this */ spec =NULL ;/* rbd_dev now owns this */ - rc =rbd_dev_image_probe (rbd_dev, true); + rc =rbd_dev_image_probe (rbd_dev,0 );if (rc <0 ) goto err_out_rbd_dev;
Signature · 1 line
2.4.3
Ilya Dryomov
maintainerPATCH 1/1 rbd: prevent kernel stack blow up on rbd map
In reply to Ilya DryomovMapping an image with a long parent chain (e.g. image foo, whose parent is bar, whose parent is baz, etc) currently leads to a kernel stack overflow, due to the following recursion in the reply path:
rbd_osd_req_callback()
rbd_obj_request_complete()
rbd_img_obj_callback()
rbd_img_parent_read_callback()
rbd_obj_request_complete()
...Limit the parent chain to 16 images, which is ~5K worth of stack. When the above recursion is eliminated, this limit can be lifted.
--- drivers/block/rbd.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-)
drivers/block/rbd.c +23 -10
@@ -96,6 +96,8 @@ static int atomic_dec_return_safe(atomic_t *v)#define RBD_MINORS_PER_MAJOR 256#define RBD_SINGLE_MAJOR_PART_SHIFT 4 +#define RBD_MAX_PARENT_CHAIN_LEN 16 +#define RBD_SNAP_DEV_NAME_PREFIX "snap_"#define RBD_MAX_SNAP_NAME_LEN \ (NAME_MAX - (sizeof (RBD_SNAP_DEV_NAME_PREFIX) - 1))
@@ -425,7 +427,7 @@ static ssize_t rbd_add_single_major(struct bus_type *bus, const char *buf, size_t count);static ssize_t rbd_remove_single_major (struct bus_type *bus,const char *buf,size_t count); -static int rbd_dev_image_probe (struct rbd_device *rbd_dev,bool mapping); +static int rbd_dev_image_probe (struct rbd_device *rbd_dev,int depth);static void rbd_spec_put (struct rbd_spec *spec);static int rbd_dev_id_to_minor (int dev_id)
@@ -5142,7 +5144,12 @@ out_err:return ret; } -static int rbd_dev_probe_parent (struct rbd_device *rbd_dev) +/* +* @depth is rbd_dev_image_probe() -> rbd_dev_probe_parent() -> +* rbd_dev_image_probe() recursion depth, which means it's also the +* length of the already discovered part of the parent chain. +*/ +static int rbd_dev_probe_parent (struct rbd_device *rbd_dev,int depth) {struct rbd_device *parent =NULL ;int ret;
@@ -5150,6 +5157,12 @@ static int rbd_dev_probe_parent(struct rbd_device *rbd_dev)if (!rbd_dev->parent_spec)return 0 ; +if (++depth >RBD_MAX_PARENT_CHAIN_LEN ) { +pr_info ("parent chain is too long (%d)\n" , depth); + ret = -EINVAL ; + goto out_err; + } + parent =rbd_dev_create (rbd_dev->rbd_client, rbd_dev->parent_spec);if (!parent) { ret = -ENOMEM ;
@@ -5163,7 +5176,7 @@ static int rbd_dev_probe_parent(struct rbd_device *rbd_dev)__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, depth);if (ret <0 ) goto out_err;
@@ -5292,7 +5305,7 @@ static void rbd_dev_image_release(struct rbd_device *rbd_dev)* parent), initiate a watch on its header object before using that * object to get detailed information about the rbd image. */ -static int rbd_dev_image_probe (struct rbd_device *rbd_dev,bool mapping) +static int rbd_dev_image_probe (struct rbd_device *rbd_dev,int depth) {int ret;
@@ -5310,7 +5323,7 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, bool mapping)if (ret) goto err_out_format; -if (mapping) { +if (!depth) { ret =rbd_dev_header_watch_sync (rbd_dev);if (ret) {if (ret == -ENOENT )
@@ -5331,7 +5344,7 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, bool mapping)* Otherwise this is a parent image, identified by pool, image * and snap ids - need to fill in names for those ids. */ -if (mapping) +if (!depth) ret =rbd_spec_fill_snap_id (rbd_dev);else ret =rbd_spec_fill_names (rbd_dev);
@@ -5353,12 +5366,12 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, bool mapping)* Need to warn users if this image is the one being * mapped and has a parent. */ -if (mapping && rbd_dev->parent_spec) +if (!depth && rbd_dev->parent_spec)rbd_warn (rbd_dev,"WARNING: kernel layering is EXPERIMENTAL!" ); } - ret =rbd_dev_probe_parent (rbd_dev); + ret =rbd_dev_probe_parent (rbd_dev, depth);if (ret) goto err_out_probe;
@@ -5369,7 +5382,7 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, bool mapping) err_out_probe:rbd_dev_unprobe (rbd_dev); err_out_watch: -if (mapping) +if (!depth)rbd_dev_header_unwatch_sync (rbd_dev); out_header_name:kfree (rbd_dev->header_name);
@@ -5434,7 +5447,7 @@ static ssize_t do_rbd_add(struct bus_type *bus, rbdc =NULL ;/* rbd_dev now owns this */ spec =NULL ;/* rbd_dev now owns this */ - rc =rbd_dev_image_probe (rbd_dev, true); + rc =rbd_dev_image_probe (rbd_dev,0 );if (rc <0 ) goto err_out_rbd_dev;
Signature · 1 line
2.4.3
Quoted 6 lines · Ilya Dryomov
Hi Greg,
These are backports of mainline
1f2c6651f69c("rbd: don't leakparent_specinrbd_dev_probe_parent()") and6d69bb536bac("rbd: prevent kernel stack blow up on rbd map") for 3.10, 3.14 and 4.1. Please apply:
Quoted 8 lines
- 1st and 2nd patches for 3.10
- 1st and 3rd patches for 3.14
- 1st and 4th patches for 4.1
- for 4.2 cherry-pick from mainlineThanks,
Ilya
Thank you Ilya, I'm using these backports for the 3.16 kernel as well.
Cheers,
--
Lu�s
Greg KH
maintainerQuoted 10 lines · Ilya Dryomov
Hi Greg,
These are backports of mainline
1f2c6651f69c("rbd: don't leakparent_specinrbd_dev_probe_parent()") and6d69bb536bac("rbd: prevent kernel stack blow up on rbd map") for 3.10, 3.14 and 4.1. Please apply:- 1st and 2nd patches for 3.10
- 1st and 3rd patches for 3.14
- 1st and 4th patches for 4.1
- for 4.2 cherry-pick from mainline
Thanks for these.
greg k-h