Commit 51ba14fb368e ("dm-verity: do forward error correction on metadata
I/O errors") handles a failed hash block read by allocating the block with
dm_bufio_new() and decoding into it with verity_fec_decode().
dm_bufio_new() inserts the buffer into the v->bufio cache immediately, with
no B_READING state and no read_error, i.e. indistinguishable from a
successfully read block that merely has not been hash-verified yet. Its
contents are whatever the allocator returned (all zeroes with init_on_alloc),
and no I/O is ever submitted for it.
FEC then reads every other block of the RS codeword and, for blocks on the
data device, calls verity_hash_for_block() on them to decide whether they
are erasures. That walks the hash tree through the same v->bufio. If one of
those data blocks is covered by the hash block being recovered (or by a
descendant of it, when it is an upper level block), the nested
verity_verify_level() gets the placeholder from the cache, hashes the
uninitialized contents, sees a mismatch, cannot recurse into FEC again
(fio->level != 0) and calls verity_handle_err(). With restart_on_corruption
that reboots the machine on a single transient read error, although the
media is intact.
Whether this happens is purely a function of the geometry. With 4K blocks,
sha256 and roots=2, 251 of the 1786 level-0 hash blocks, all level-1 blocks
and the root block have a codeword data block underneath them, so an I/O
error on any of those reliably produces "metadata block N is corrupted".
It was observed on Android devices where a hash read failed with -EIO while
UFS was already offline during reboot.
Decode into a private buffer instead and only copy out the wanted digest on
success. The recovered block is not cached, so a later access will read and,
if needed, recover it again; that is only a cost on devices that are already
failing reads.
Fixes: 51ba14fb368e ("dm-verity: do forward error correction on metadata I/O
errors")
Signed-off-by: Hongyu Jin <[email protected]>
Signed-off-by: weijiang.zhou <[email protected]>
---
drivers/md/dm-verity-target.c | 28 +++++++++++++++++++---------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c
index 08a58a0b5e49..42ee24d823e3 100644
--- a/drivers/md/dm-verity-target.c
+++ b/drivers/md/dm-verity-target.c
@@ -266,22 +266,29 @@ static int verity_verify_level(struct dm_verity *v,
struct dm_verity_io *io,
}
if (IS_ERR(data)) {
+u8 *fec_buf;
+
if (skip_unverified)
return 1;
r = PTR_ERR(data);
-data = dm_bufio_new(v->bufio, hash_block, &buf);
-if (IS_ERR(data))
+/*
+ * Recover the hash block into a private buffer. It must not be
+ * made visible in v->bufio before it has been recovered: FEC
+ * verifies the other blocks of the RS codeword through
+ * verity_hash_for_block(), which may need this very hash block
+ * and would then hash an uninitialized buffer, reporting
+ * spurious corruption.
+ */
+fec_buf = kmalloc(1 << v->hash_dev_block_bits, GFP_NOIO);
+if (!fec_buf)
return r;
if (verity_fec_decode(v, io, DM_VERITY_BLOCK_TYPE_METADATA,
- want_digest, hash_block, data) == 0) {
-aux = dm_bufio_get_aux_data(buf);
-aux->hash_verified = 1;
-goto release_ok;
-} else {
-dm_bufio_release(buf);
-dm_bufio_forget(v->bufio, hash_block);
-return r;
+ want_digest, hash_block, fec_buf) == 0) {
+memcpy(want_digest, fec_buf + offset, v->digest_size);
+r = 0;
}
+kfree(fec_buf);
+return r;
}
aux = dm_bufio_get_aux_data(buf);
@@ -323,7 +330,6 @@ static int verity_verify_level(struct dm_verity *v, struct
dm_verity_io *io,
}
}
-release_ok:
data += offset;
memcpy(want_digest, data, v->digest_size);
r = 0;
--
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.
本邮件及其附件具有保密性质,受法律保护不得泄露,仅发送给本邮件所指特定收件人。严禁非经授权使用、宣传、发布或复制本邮件或其内容。若非该特定收件人,请勿阅读、复制、
使用或披露本邮件的任何内容。若误收本邮件,请从系统中永久性删除本邮件及所有附件,并以回复邮件的方式即刻告知发件人。无法保证互联网通信及时、安全、无误或防毒。发件人对任何错漏均不承担责任。