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

Commit bd24f30

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 b3c10ac commit bd24f30

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
@@ -264,8 +264,10 @@ static int verity_handle_err(struct dm_verity *v, enum verity_block_type type,
264264
if (v->mode == DM_VERITY_MODE_LOGGING)
265265
return 0;
266266

267-
if (v->mode == DM_VERITY_MODE_RESTART)
268-
kernel_restart("dm-verity device corrupted");
267+
if (v->mode == DM_VERITY_MODE_RESTART) {
268+
pr_emerg("dm-verity device corrupted\n");
269+
emergency_restart();
270+
}
269271

270272
if (v->mode == DM_VERITY_MODE_PANIC)
271273
panic("dm-verity device corrupted");
@@ -689,6 +691,23 @@ static void verity_finish_io(struct dm_verity_io *io, blk_status_t status)
689691
if (!static_branch_unlikely(&use_tasklet_enabled) || !io->in_tasklet)
690692
verity_fec_finish_io(io);
691693

694+
if (unlikely(status != BLK_STS_OK) &&
695+
unlikely(!(bio->bi_opf & REQ_RAHEAD)) &&
696+
!verity_is_system_shutting_down()) {
697+
if (v->mode == DM_VERITY_MODE_RESTART ||
698+
v->mode == DM_VERITY_MODE_PANIC)
699+
DMERR_LIMIT("%s has error: %s", v->data_dev->name,
700+
blk_status_to_str(status));
701+
702+
if (v->mode == DM_VERITY_MODE_RESTART) {
703+
pr_emerg("dm-verity device corrupted\n");
704+
emergency_restart();
705+
}
706+
707+
if (v->mode == DM_VERITY_MODE_PANIC)
708+
panic("dm-verity device corrupted");
709+
}
710+
692711
bio_endio(bio);
693712
}
694713

0 commit comments

Comments
 (0)