Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit c08128c

Browse files
Mikulas Patockagregkh
Mikulas Patocka
authored andcommitted
dm-verity: restart or panic on an I/O error
commit e6a3531 upstream. Maxim Suhanov reported that dm-verity doesn't crash if an I/O error happens. In theory, this could be used to subvert security, because an attacker can create sectors that return error with the Write Uncorrectable command. Some programs may misbehave if they have to deal with EIO. This commit fixes dm-verity, so that if "panic_on_corruption" or "restart_on_corruption" was specified and an I/O error happens, the machine will panic or restart. This commit also changes kernel_restart to emergency_restart - kernel_restart calls reboot notifiers and these reboot notifiers may wait for the bio that failed. emergency_restart doesn't call the notifiers. Reported-by: Maxim Suhanov <dfirblog@gmail.com> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a27c5ea commit c08128c

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

drivers/md/dm-verity-target.c

+21-2
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,10 @@ static int verity_handle_err(struct dm_verity *v, enum verity_block_type type,
272272
if (v->mode == DM_VERITY_MODE_LOGGING)
273273
return 0;
274274

275-
if (v->mode == DM_VERITY_MODE_RESTART)
276-
kernel_restart("dm-verity device corrupted");
275+
if (v->mode == DM_VERITY_MODE_RESTART) {
276+
pr_emerg("dm-verity device corrupted\n");
277+
emergency_restart();
278+
}
277279

278280
if (v->mode == DM_VERITY_MODE_PANIC)
279281
panic("dm-verity device corrupted");
@@ -596,6 +598,23 @@ static void verity_finish_io(struct dm_verity_io *io, blk_status_t status)
596598
if (!static_branch_unlikely(&use_bh_wq_enabled) || !io->in_bh)
597599
verity_fec_finish_io(io);
598600

601+
if (unlikely(status != BLK_STS_OK) &&
602+
unlikely(!(bio->bi_opf & REQ_RAHEAD)) &&
603+
!verity_is_system_shutting_down()) {
604+
if (v->mode == DM_VERITY_MODE_RESTART ||
605+
v->mode == DM_VERITY_MODE_PANIC)
606+
DMERR_LIMIT("%s has error: %s", v->data_dev->name,
607+
blk_status_to_str(status));
608+
609+
if (v->mode == DM_VERITY_MODE_RESTART) {
610+
pr_emerg("dm-verity device corrupted\n");
611+
emergency_restart();
612+
}
613+
614+
if (v->mode == DM_VERITY_MODE_PANIC)
615+
panic("dm-verity device corrupted");
616+
}
617+
599618
bio_endio(bio);
600619
}
601620

0 commit comments

Comments
 (0)