dm-verity: Fix biovecs hash calculation regression
PATCH 1/1 dm-verity: Fix biovecs hash calculation regression
The commit
003b5c5719f159f4f4bf97511c4702a0638313dd
block: Convert drivers to immutable biovecs
incorrectly converted biovec iteration in dm-verity to always calculate hash from full biovec, while the function need to calculate hash only from part of it (up to "todo" calculated value).
This patch fixes the issue by limiting hash input to only really requested data size.
The problem is easily reproducible using cryptsetup regression test for veritysetup (verity-compat-test).
(Patch should be applied also to 3.14 stable.)
--- drivers/md/dm-verity.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/md/dm-verity.c +9 -6
@@ -330,15 +330,17 @@ test_block_hash: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) {
@@ -346,8 +348,9 @@ test_block_hash: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);
Signature · 1 line
1.9.2
Quoted 12 lines · Milan Broz
The commit
003b5c5719f159f4f4bf97511c4702a0638313dd
block: Convert drivers to immutable biovecsincorrectly converted biovec iteration in dm-verity to always calculate hash from full biovec, while the function need to calculate hash only from part of it (up to "todo" calculated value).
This patch fixes the issue by limiting hash input to only really requested data size.
Quoted 6 lines
The problem is easily reproducible using cryptsetup regression test for veritysetup (verity-compat-test).
(Patch should be applied also to 3.14 stable.)
Signed-off-by Milan Broz <[email protected]>
Quoted 45 lines
--- drivers/md/dm-verity.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)drivers/md/dm-verity.c +9
-6@@ -330,15 +330,17 @@ test_block_hash: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) {@@ -346,8 +348,9 @@ test_block_hash: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);Signature · 1 line
1.9.2
Quoted 19 lines · Mikulas Patocka
Quoted 15 lines · Milan Broz
The commit
003b5c5719f159f4f4bf97511c4702a0638313dd
block: Convert drivers to immutable biovecsincorrectly converted biovec iteration in dm-verity to always calculate hash from full biovec, while the function need to calculate hash only from part of it (up to "todo" calculated value).
This patch fixes the issue by limiting hash input to only really requested data size.
The problem is easily reproducible using cryptsetup regression test for veritysetup (verity-compat-test).
Quoted 6 lines
Quoted 3 lines
(Patch should be applied also to 3.14 stable.)
Signed-off-by Milan Broz <[email protected]>Acked-by Mikulas Patocka <[email protected]>Cc [email protected] # 3.14
I'll pick this up to include in 3.15 fixes that I'll be sending to Linus.