From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Weijiang Zhou <weijiang.zhou@unisoc.com>,
Hongyu Jin <hongyu.jin@unisoc.com>,
Mikulas Patocka <mpatocka@redhat.com>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.1.y] dm-verity: don't restart or panic on errors during system shutdown
Date: Thu, 26 Nov 2026 00:01:31 -0500 [thread overview]
Message-ID: <20261126050014.2081983-1-sashal@kernel.org> (raw)
In-Reply-To: <2026112516-crystal-retriever-61b9@gregkh>
From: Weijiang Zhou <weijiang.zhou@unisoc.com>
[ Upstream commit 47930d1236d2988cdc580c10d3af21b6b02d7ece ]
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 <hongyu.jin@unisoc.com>
Signed-off-by: weijiang.zhou <weijiang.zhou@unisoc.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Fixes: 252bd1256396 ("dm verity: skip verity work if I/O error when system is shutting down")
Cc: stable@vger.kernel.org
[ sashal: adjusted the final hunk's context, since the surrounding code in this tree differs (verity_verify_io returns r instead of 0, and the removed helper is followed by a different function). ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
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 3e582c1b544fe..ce72eed21d6c5 100644
--- a/drivers/md/dm-verity-target.c
+++ b/drivers/md/dm-verity-target.c
@@ -215,6 +215,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.
*/
@@ -262,6 +271,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");
@@ -656,15 +674,6 @@ static int verity_verify_io(struct dm_verity_io *io)
return 0;
}
-/*
- * 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;
-}
-
/*
* End one "io" structure with a given error.
*/
--
2.53.0
prev parent reply other threads:[~2026-11-26 5:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 11:20 FAILED: patch "[PATCH] dm-verity: don't restart or panic on errors during system" failed to apply to 6.1-stable tree gregkh
2026-11-26 5:01 ` Sasha Levin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261126050014.2081983-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=hongyu.jin@unisoc.com \
--cc=mpatocka@redhat.com \
--cc=stable@vger.kernel.org \
--cc=weijiang.zhou@unisoc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox