Skip to content

Commit a674d0c

Browse files
author
Mikulas Patocka
committed
dm-verity: don't crash if panic_on_corruption is not selected
If the user sets panic_on_error and doesn't set panic_on_corruption, dm-verity should not panic on data mismatch. But, currently it panics, because it treats data mismatch as I/O error. This commit fixes the logic so that if there is data mismatch and panic_on_corruption or restart_on_corruption is not selected, the system won't restart or panic. Signed-off-by: Mikulas Patocka <[email protected]> Reviewed-by: Sami Tolvanen <[email protected]> Fixes: f811b83 ("dm-verity: introduce the options restart_on_error and panic_on_error")
1 parent 5a4510c commit a674d0c

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

drivers/md/dm-verity-target.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,9 @@ static int verity_verify_level(struct dm_verity *v, struct dm_verity_io *io,
356356
else if (verity_handle_err(v,
357357
DM_VERITY_BLOCK_TYPE_METADATA,
358358
hash_block)) {
359-
struct bio *bio =
360-
dm_bio_from_per_bio_data(io,
361-
v->ti->per_io_data_size);
359+
struct bio *bio;
360+
io->had_mismatch = true;
361+
bio = dm_bio_from_per_bio_data(io, v->ti->per_io_data_size);
362362
dm_audit_log_bio(DM_MSG_PREFIX, "verify-metadata", bio,
363363
block, 0);
364364
r = -EIO;
@@ -482,6 +482,7 @@ static int verity_handle_data_hash_mismatch(struct dm_verity *v,
482482
return -EIO; /* Error correction failed; Just return error */
483483

484484
if (verity_handle_err(v, DM_VERITY_BLOCK_TYPE_DATA, blkno)) {
485+
io->had_mismatch = true;
485486
dm_audit_log_bio(DM_MSG_PREFIX, "verify-data", bio, blkno, 0);
486487
return -EIO;
487488
}
@@ -606,6 +607,7 @@ static void verity_finish_io(struct dm_verity_io *io, blk_status_t status)
606607

607608
if (unlikely(status != BLK_STS_OK) &&
608609
unlikely(!(bio->bi_opf & REQ_RAHEAD)) &&
610+
!io->had_mismatch &&
609611
!verity_is_system_shutting_down()) {
610612
if (v->error_mode == DM_VERITY_MODE_PANIC) {
611613
panic("dm-verity device has I/O error");
@@ -779,6 +781,7 @@ static int verity_map(struct dm_target *ti, struct bio *bio)
779781
io->orig_bi_end_io = bio->bi_end_io;
780782
io->block = bio->bi_iter.bi_sector >> (v->data_dev_block_bits - SECTOR_SHIFT);
781783
io->n_blocks = bio->bi_iter.bi_size >> v->data_dev_block_bits;
784+
io->had_mismatch = false;
782785

783786
bio->bi_end_io = verity_end_io;
784787
bio->bi_private = io;

drivers/md/dm-verity.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ struct dm_verity_io {
9292
sector_t block;
9393
unsigned int n_blocks;
9494
bool in_bh;
95+
bool had_mismatch;
9596

9697
struct work_struct work;
9798
struct work_struct bh_work;

0 commit comments

Comments
 (0)