Commit b86f4b79 authored by Mikulas Patocka's avatar Mikulas Patocka Committed by Mike Snitzer

dm-integrity: don't modify bio's immutable bio_vec in integrity_metadata()

__bio_for_each_segment assumes that the first struct bio_vec argument
doesn't change - it calls "bio_advance_iter_single((bio), &(iter),
(bvl).bv_len)" to advance the iterator. Unfortunately, the dm-integrity
code changes the bio_vec with "bv.bv_len -= pos". When this code path
is taken, the iterator would be out of sync and dm-integrity would
report errors. This happens if the machine is out of memory and
"kmalloc" fails.

Fix this bug by making a copy of "bv" and changing the copy instead.

Fixes: 7eada909 ("dm: add integrity target")
Cc: stable@vger.kernel.org	# v4.12+
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
parent db29d79b
...@@ -1755,11 +1755,12 @@ static void integrity_metadata(struct work_struct *w) ...@@ -1755,11 +1755,12 @@ static void integrity_metadata(struct work_struct *w)
sectors_to_process = dio->range.n_sectors; sectors_to_process = dio->range.n_sectors;
__bio_for_each_segment(bv, bio, iter, dio->bio_details.bi_iter) { __bio_for_each_segment(bv, bio, iter, dio->bio_details.bi_iter) {
struct bio_vec bv_copy = bv;
unsigned int pos; unsigned int pos;
char *mem, *checksums_ptr; char *mem, *checksums_ptr;
again: again:
mem = bvec_kmap_local(&bv); mem = bvec_kmap_local(&bv_copy);
pos = 0; pos = 0;
checksums_ptr = checksums; checksums_ptr = checksums;
do { do {
...@@ -1768,7 +1769,7 @@ static void integrity_metadata(struct work_struct *w) ...@@ -1768,7 +1769,7 @@ static void integrity_metadata(struct work_struct *w)
sectors_to_process -= ic->sectors_per_block; sectors_to_process -= ic->sectors_per_block;
pos += ic->sectors_per_block << SECTOR_SHIFT; pos += ic->sectors_per_block << SECTOR_SHIFT;
sector += ic->sectors_per_block; sector += ic->sectors_per_block;
} while (pos < bv.bv_len && sectors_to_process && checksums != checksums_onstack); } while (pos < bv_copy.bv_len && sectors_to_process && checksums != checksums_onstack);
kunmap_local(mem); kunmap_local(mem);
r = dm_integrity_rw_tag(ic, checksums, &dio->metadata_block, &dio->metadata_offset, r = dm_integrity_rw_tag(ic, checksums, &dio->metadata_block, &dio->metadata_offset,
...@@ -1793,9 +1794,9 @@ static void integrity_metadata(struct work_struct *w) ...@@ -1793,9 +1794,9 @@ static void integrity_metadata(struct work_struct *w)
if (!sectors_to_process) if (!sectors_to_process)
break; break;
if (unlikely(pos < bv.bv_len)) { if (unlikely(pos < bv_copy.bv_len)) {
bv.bv_offset += pos; bv_copy.bv_offset += pos;
bv.bv_len -= pos; bv_copy.bv_len -= pos;
goto again; goto again;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment