On Tue, Nov 10, 2026 at 1:08 PM Mikulas Patocka <[email protected]> wrote:
>
> Hi
>
>
> On Tue, 10 Nov 2026, 周伟江 (Weijiang Zhou) wrote:
>
> > 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.
>
> I don't see why this should be a problem.
>
> If the device returns random data, FEC is supposed to correct it.
>
> If the device returns an I/O error and we create a buffer with random
> data, this is similar to the case where the device returned random data -
> and FEC should also correct it. It doesn't matter whether the random data
> came from the device or from uninitialized kernel memory.
>
> So, it seems to me that this patch is just papering over the problem.
>
> > 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
>
> This is the real problem that should be fixed. Correcting a block
> shouldn't depend on the content of the block being corrected.

It doesn't depend on it. We only look for erasures because knowing
which blocks are corrupt allows us to correct twice as many errors,
but this is completely optional. Sounds like the correct solution is
not to call verity_handle_err() on verification errors while we're
only looking up erasures, since these are not fatal errors.

> > 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.

We also shouldn't try to correct I/O errors when the system is
shutting down. We already have verity_is_system_shutting_down() for
this purpose, perhaps we should use it in verity_fec_decode() too?

Sami

Reply via email to