Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rbd: handle parent_overlap on writes correctly

The following check in rbd_img_obj_request_submit()

rbd_dev->parent_overlap <= obj_request->img_offset

allows the fall through to the non-layered write case even if both
parent_overlap and obj_request->img_offset belong to the same RADOS
object. This leads to data corruption, because the area to the left of
parent_overlap ends up unconditionally zero-filled instead of being
populated with parent data. Suppose we want to write 1M to offset 6M
of image bar, which is a clone of foo@snap; object_size is 4M,
parent_overlap is 5M:

rbd_data.<id>.0000000000000001
---------------------|----------------------|------------
| should be copyup'ed | should be zeroed out | write ...
---------------------|----------------------|------------
4M 5M 6M
parent_overlap obj_request->img_offset

4..5M should be copyup'ed from foo, yet it is zero-filled, just like
5..6M is.

Given that the only striping mode kernel client currently supports is
chunking (i.e. stripe_unit == object_size, stripe_count == 1), round
parent_overlap up to the next object boundary for the purposes of the
overlap check.

Cc: stable@vger.kernel.org # 3.10+
Signed-off-by: Ilya Dryomov <ilya.dryomov@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>

+9 -1
+9 -1
drivers/block/rbd.c
··· 1431 1431 return test_bit(OBJ_REQ_EXISTS, &obj_request->flags) != 0; 1432 1432 } 1433 1433 1434 + static bool obj_request_overlaps_parent(struct rbd_obj_request *obj_request) 1435 + { 1436 + struct rbd_device *rbd_dev = obj_request->img_request->rbd_dev; 1437 + 1438 + return obj_request->img_offset < 1439 + round_up(rbd_dev->parent_overlap, rbd_obj_bytes(&rbd_dev->header)); 1440 + } 1441 + 1434 1442 static void rbd_obj_request_get(struct rbd_obj_request *obj_request) 1435 1443 { 1436 1444 dout("%s: obj %p (was %d)\n", __func__, obj_request, ··· 2756 2748 */ 2757 2749 if (!img_request_write_test(img_request) || 2758 2750 !img_request_layered_test(img_request) || 2759 - rbd_dev->parent_overlap <= obj_request->img_offset || 2751 + !obj_request_overlaps_parent(obj_request) || 2760 2752 ((known = obj_request_known_test(obj_request)) && 2761 2753 obj_request_exists_test(obj_request))) { 2762 2754