diff options
author | Joe Thornber <ejt@redhat.com> | 2015-05-29 09:52:51 -0400 |
---|---|---|
committer | Mike Snitzer <snitzer@redhat.com> | 2015-05-29 13:41:16 -0400 |
commit | 1c220c69ce0dcc0f234a9f263ad9c0864f971852 (patch) | |
tree | 8ab6d754a212bd1fbfad8909686bc893cb889a82 | |
parent | 15b94a690470038aa08247eedbebbe7e2218d5ee (diff) |
dm: fix casting bug in dm_merge_bvec()
dm_merge_bvec() was originally added in f6fccb ("dm: introduce
merge_bvec_fn"). In that commit a value in sectors is converted to
bytes using << 9, and then assigned to an int. This code made
assumptions about the value of BIO_MAX_SECTORS.
A later commit 148e51 ("dm: improve documentation and code clarity in
dm_merge_bvec") was meant to have no functional change but it removed
the use of BIO_MAX_SECTORS in favor of using queue_max_sectors(). At
this point the cast from sector_t to int resulted in a zero value. The
fallout being dm_merge_bvec() would only allow a single page to be added
to a bio.
This interim fix is minimal for the benefit of stable@ because the more
comprehensive cleanup of passing a sector_t to all DM targets' merge
function will impact quite a few DM targets.
Signed-off-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Cc: stable@vger.kernel.org # 3.19+
-rw-r--r-- | drivers/md/dm.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/drivers/md/dm.c b/drivers/md/dm.c index e24069aaeb18..2caf492890d6 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c | |||
@@ -1723,8 +1723,7 @@ static int dm_merge_bvec(struct request_queue *q, | |||
1723 | struct mapped_device *md = q->queuedata; | 1723 | struct mapped_device *md = q->queuedata; |
1724 | struct dm_table *map = dm_get_live_table_fast(md); | 1724 | struct dm_table *map = dm_get_live_table_fast(md); |
1725 | struct dm_target *ti; | 1725 | struct dm_target *ti; |
1726 | sector_t max_sectors; | 1726 | sector_t max_sectors, max_size = 0; |
1727 | int max_size = 0; | ||
1728 | 1727 | ||
1729 | if (unlikely(!map)) | 1728 | if (unlikely(!map)) |
1730 | goto out; | 1729 | goto out; |
@@ -1739,8 +1738,16 @@ static int dm_merge_bvec(struct request_queue *q, | |||
1739 | max_sectors = min(max_io_len(bvm->bi_sector, ti), | 1738 | max_sectors = min(max_io_len(bvm->bi_sector, ti), |
1740 | (sector_t) queue_max_sectors(q)); | 1739 | (sector_t) queue_max_sectors(q)); |
1741 | max_size = (max_sectors << SECTOR_SHIFT) - bvm->bi_size; | 1740 | max_size = (max_sectors << SECTOR_SHIFT) - bvm->bi_size; |
1742 | if (unlikely(max_size < 0)) /* this shouldn't _ever_ happen */ | 1741 | |
1743 | max_size = 0; | 1742 | /* |
1743 | * FIXME: this stop-gap fix _must_ be cleaned up (by passing a sector_t | ||
1744 | * to the targets' merge function since it holds sectors not bytes). | ||
1745 | * Just doing this as an interim fix for stable@ because the more | ||
1746 | * comprehensive cleanup of switching to sector_t will impact every | ||
1747 | * DM target that implements a ->merge hook. | ||
1748 | */ | ||
1749 | if (max_size > INT_MAX) | ||
1750 | max_size = INT_MAX; | ||
1744 | 1751 | ||
1745 | /* | 1752 | /* |
1746 | * merge_bvec_fn() returns number of bytes | 1753 | * merge_bvec_fn() returns number of bytes |
@@ -1748,7 +1755,7 @@ static int dm_merge_bvec(struct request_queue *q, | |||
1748 | * max is precomputed maximal io size | 1755 | * max is precomputed maximal io size |
1749 | */ | 1756 | */ |
1750 | if (max_size && ti->type->merge) | 1757 | if (max_size && ti->type->merge) |
1751 | max_size = ti->type->merge(ti, bvm, biovec, max_size); | 1758 | max_size = ti->type->merge(ti, bvm, biovec, (int) max_size); |
1752 | /* | 1759 | /* |
1753 | * If the target doesn't support merge method and some of the devices | 1760 | * If the target doesn't support merge method and some of the devices |
1754 | * provided their merge_bvec method (we know this by looking for the | 1761 | * provided their merge_bvec method (we know this by looking for the |