Commit 252bd1256396 ("dm verity: skip verity work if I/O error when system
is shutting down") stopped I/O errors during shutdown from triggering a
restart, since devices may legitimately be gone by then. Errors that reach
verity_handle_err(), e.g. through a failed hash block read followed by a
failed FEC attempt, are not covered and still call kernel_restart() or
panic().

During a reboot that is both wrong (nothing is corrupt) and harmful: it
races with the reboot already in progress and replaces its reason with
"dm-verity device corrupted", which bootloaders such as Android's treat as
a verity failure and switch the device to EIO mode.

Apply the same shutdown check in verity_handle_err(). Corruption is still
logged, recorded in hash_failed and reported via uevent, and the I/O still
fails.

Signed-off-by: Hongyu Jin <[email protected]>
Signed-off-by: weijiang.zhou <[email protected]>
---
 drivers/md/dm-verity-target.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c
index 42ee24d823e3..756f1202490b 100644
--- a/drivers/md/dm-verity-target.c
+++ b/drivers/md/dm-verity-target.c
@@ -169,6 +169,15 @@ static void verity_hash_at_level(struct dm_verity *v, 
sector_t block, int level,
 *offset = idx << (v->hash_dev_block_bits - v->hash_per_block_bits);
 }

+/*
+ * Skip verity work in response to I/O error when system is shutting down.
+ */
+static inline bool verity_is_system_shutting_down(void)
+{
+return system_state == SYSTEM_HALT || system_state == SYSTEM_POWER_OFF
+|| system_state == SYSTEM_RESTART;
+}
+
 /*
  * Handle verification errors.
  */
@@ -216,6 +225,15 @@ static int verity_handle_err(struct dm_verity *v, enum 
verity_block_type type,
 if (v->mode == DM_VERITY_MODE_LOGGING)
 return 0;

+/*
+ * Devices may already be quiesced (e.g. UFS set offline by its
+ * shutdown hook), so a failure here does not imply corruption.  Fail
+ * the I/O but do not restart or panic, which would also override the
+ * reboot reason of the shutdown already in progress.
+ */
+if (verity_is_system_shutting_down())
+return 1;
+
 if (v->mode == DM_VERITY_MODE_RESTART)
 kernel_restart("dm-verity device corrupted");

@@ -598,15 +616,6 @@ static int verity_verify_io(struct dm_verity_io *io)
 return r;
 }

-/*
- * Skip verity work in response to I/O error when system is shutting down.
- */
-static inline bool verity_is_system_shutting_down(void)
-{
-return system_state == SYSTEM_HALT || system_state == SYSTEM_POWER_OFF
-|| system_state == SYSTEM_RESTART;
-}
-
 static void restart_io_error(struct work_struct *w)
 {
 kernel_restart("dm-verity device has I/O error");
--
2.43.0
________________________________
 This email (including its attachments) is intended only for the person or 
entity to which it is addressed and may contain information that is privileged, 
confidential or otherwise protected from disclosure. Unauthorized use, 
dissemination, distribution or copying of this email or the information herein 
or taking any action in reliance on the contents of this email or the 
information herein, by anyone other than the intended recipient, or an employee 
or agent responsible for delivering the message to the intended recipient, is 
strictly prohibited. If you are not the intended recipient, please do not read, 
copy, use or disclose any part of this e-mail to others. Please notify the 
sender immediately and permanently delete this e-mail and any attachments if 
you received it in error. Internet communications cannot be guaranteed to be 
timely, secure, error-free or virus-free. The sender does not accept liability 
for any errors or omissions.
本邮件及其附件具有保密性质,受法律保护不得泄露,仅发送给本邮件所指特定收件人。严禁非经授权使用、宣传、发布或复制本邮件或其内容。若非该特定收件人,请勿阅读、复制、
 
使用或披露本邮件的任何内容。若误收本邮件,请从系统中永久性删除本邮件及所有附件,并以回复邮件的方式即刻告知发件人。无法保证互联网通信及时、安全、无误或防毒。发件人对任何错漏均不承担责任。

Reply via email to