Skip to content

Commit

Permalink
dm verity: fix biovecs hash calculation regression
Browse files Browse the repository at this point in the history
Commit 003b5c5 ("block: Convert drivers
to immutable biovecs") incorrectly converted biovec iteration in
dm-verity to always calculate the hash from a full biovec, but the
function only needs to calculate the hash from part of the biovec (up to
the calculated "todo" value).

Fix this issue by limiting hash input to only the requested data size.

This problem was identified using the cryptsetup regression test for
veritysetup (verity-compat-test).

Signed-off-by: Milan Broz <gmazyland@gmail.com>
Acked-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Cc: stable@vger.kernel.org # 3.14+
  • Loading branch information
Milan Broz authored and Mike Snitzer committed Apr 15, 2014
1 parent b10ebd3 commit 3a77452
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions drivers/md/dm-verity.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,24 +330,27 @@ static int verity_verify_io(struct dm_verity_io *io)
return r;
}
}

todo = 1 << v->data_dev_block_bits;
while (io->iter.bi_size) {
do {
u8 *page;
unsigned len;
struct bio_vec bv = bio_iter_iovec(bio, io->iter);

page = kmap_atomic(bv.bv_page);
r = crypto_shash_update(desc, page + bv.bv_offset,
bv.bv_len);
len = bv.bv_len;
if (likely(len >= todo))
len = todo;
r = crypto_shash_update(desc, page + bv.bv_offset, len);
kunmap_atomic(page);

if (r < 0) {
DMERR("crypto_shash_update failed: %d", r);
return r;
}

bio_advance_iter(bio, &io->iter, bv.bv_len);
}
bio_advance_iter(bio, &io->iter, len);
todo -= len;
} while (todo);

if (!v->version) {
r = crypto_shash_update(desc, v->salt, v->salt_size);
Expand Down

0 comments on commit 3a77452

Please sign in to comment.