* [RFC PATCH 0/2] dm-verity: don't let FEC decode into a dm_bufio page that is already in the cache
@ 2026-11-10 13:06 周伟江 (Weijiang Zhou)
2026-11-10 13:06 ` [RFC PATCH 1/2] dm-verity: don't decode FEC " 周伟江 (Weijiang Zhou)
2026-11-10 13:06 ` [RFC PATCH 2/2] dm-verity: don't restart or panic on errors during system shutdown 周伟江 (Weijiang Zhou)
0 siblings, 2 replies; 16+ messages in thread
From: 周伟江 (Weijiang Zhou) @ 2026-11-10 13:06 UTC (permalink / raw)
To: dm-devel@lists.linux.dev
Cc: Alasdair Kergon, Mike Snitzer, Mikulas Patocka,
Benjamin Marzinski, Sami Tolvanen,
金红宇 (Hongyu Jin),
吴祥禄 (Xianglu Wu),
吴周镜 (Justin Wu)
Hi,
We would like to ask for your help with something we ran into on dm-verity.
On 6.18 we are seeing a hash block being reported as corrupted while FEC is
in the middle of recovering it, and we suspect the reason is that the block
becomes visible in the dm_bufio cache before FEC has written it. It looks to
us like a regression from 51ba14fb368e (6.15), but we would very much like a
second opinion before going any further.
Two patches follow, as an RFC: they have not been built or run on a device
yet, and we would rather agree on the direction with you first.
1. Root cause
As far as we can tell, verity_verify_level() handles a failed hash block
read by taking a fresh buffer with dm_bufio_new() and decoding into it with
verity_fec_decode():
data = dm_bufio_new(v->bufio, hash_block, &buf); /* <-- */
Our understanding is that dm_bufio_new() inserts that buffer into v->bufio
immediately, with no B_READING and no read_error, and never submits I/O for
it. While FEC runs, the cache would then hold a page that cannot be told
apart from a block which was read successfully and simply has not been hash-
checked yet, while its contents are whatever the allocator returned.
FEC then walks the RS codeword and, for the message blocks that live on the
data device, calls verity_hash_for_block() to decide which of them are
erasures - through the same v->bufio. So if one of those data blocks happens
to be covered by the hash block being recovered, the nested
verity_verify_level() would take that placeholder out of the cache, hash
zeros, get a mismatch and, since nested FEC is refused (fio->level != 0 ->
-EIO), end up in verity_handle_err(), which reports corruption.
Both the publication and the read-back happen in the same thread, so it does
not look like a race to us. Whether it triggers seems to depend only on the
geometry.
2. Symptom
Unisoc ums9635, Android 17, kernel 6.18.21, dm-verity over a virtual A/B
system partition: 4K blocks, sha256, fec_roots=2, created with
restart_on_corruption. Rebooting a slot whose snapshot had not been merged
yet, we got:
device-mapper: verity: 254:3: metadata block 229730 is corrupted
reboot: Restarting system with command 'dm-verity device corrupted'
The hash read did fail with -EIO, because the UFS was already offline. The
media itself is fine: we rebuilt that slot from the COW and verified both
slots' hash trees offline, zero bad blocks, and block 229730 contains
exactly the digest the tree expects.
If our reading is right, any failed hash read can trigger this, not just one
during shutdown. With 228497 data blocks, 251 of the 1786 level-0 hash
blocks, all 14 level-1 blocks and the root block have a codeword data block
underneath them, so an I/O error on any of those would be reported as
corruption. android16-6.12 has no 51ba14fb368e, and there it simply returns
-EIO.
3. Code evidence
/* drivers/md/dm-verity-target.c, verity_verify_level() */
if (IS_ERR(data)) {
if (skip_unverified)
return 1;
r = PTR_ERR(data);
data = dm_bufio_new(v->bufio, hash_block, &buf); /* <-- */
/* drivers/md/dm-verity-fec.c, fec_read_bufs() */
/* locate erasures if the block is on the data device */
if (bufio == v->fec->data_bufio &&
verity_hash_for_block(v, io, block, want_digest, &is_zero) == 0) {
What we can add from the minidump, all of it in thread T329 (kverityd):
- block 229730 was read from the device twice; the nested read issued no I/O
and was served from the cache
- T329 was preempted 171 times between the failed read and the report,
matching the 171 successful reads of blocks i = 0..170 before the nested
one
- kprobe: real digest 8b1f331f... equals sha256(salt || 4096 * 0x00), wanted
digest bac80063... equals offset 0x840 of L1 block 228507 in the image we
rebuilt offline
- dump, report and restart all carry TID 329
In our case it happens at i = 171: message block 171 * 911 + 158 = 155939,
whose leaf hash is 228512 + (155939 >> 7) = 229730 (region_blocks 911 from
fec_blocks 230298 and roots 2, index_in_region 158).
The guards we looked at do not seem to cover this path: 252bd1256396 in
verity_end_io applies to the outer bio, which succeeded; verity_finish_io
checks bio completion, while verity_handle_err() has no system_state check;
and dm_bufio_release only drops buffers with read_error set, which an
NF_FRESH buffer does not have. If we are missing one, we would be glad to be
corrected.
4. Reproducer, no device and no shutdown needed
1. put a dm-dust layer below the verity hash area and mark one level-1 block
bad
2. drop the page cache and let the bufio cache go
3. read a data block that has that level-1 block as an ancestor
In our hands an unmodified 6.18 reports "metadata block N is corrupted"
every time, single threaded. We would be happy to turn this into a proper
reproducer if it is useful.
5. Patch 1
What we have tried so far is to decode into a private buffer, so that
nothing enters v->bufio before it holds recovered data:
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, fec_buf) == 0) {
memcpy(want_digest, fec_buf + offset, v->digest_size);
r = 0;
}
kfree(fec_buf);
return r;
We believe this closes the window rather than narrowing it. A recovered hash
block is no longer cached, so a later access reads it again and, if the
device is still failing, recovers it again - which costs something only on
media that already returns errors, and keeps the change inside the function
that got us here. We also wondered about the other end, having
dm_bufio_new() refuse to publish a buffer before it is filled: that would
hold for every caller rather than just verity, but NF_FRESH exists precisely
so a caller can fill the buffer itself and other targets rely on it, so it
looked like a larger change than this needs. We are quite happy to redo it
there if you prefer.
Patch 2 is unrelated to cache visibility and came out of the same dump:
verity_handle_err() does not consult system_state, so during a shutdown it
still restarts or panics for an error that cannot mean corruption, and
overwrites the reason of the reboot already in progress. It reuses
verity_is_system_shutting_down() and fails the I/O instead. Please look at
the two separately.
6. Questions
1. Have you seen this before, or is a fix already queued somewhere?
verity_verify_level() and fec_read_bufs() look unchanged in master
(05441d697f7f), and the v2 review of 51ba14fb368e does not mention cache
visibility, but you would know better than we do.
2. Would you be willing to check whether our reading of the dm_bufio_new() +
FEC interaction is right, and whether the shape of patch 1 makes sense?
If we have it wrong, we would much rather hear it now than later.
The dump comes from a product device so it is not public, but we can extract
anything you would like to see: the raw log_buf, the sched_trace window
around T329, the kprobe output. And of course we are glad to test anything
you suggest on the device.
Thank you for your time, and for the work on dm-verity.
BRs
weijiang.zhou
Unisoc ota team
________________________________
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.
本邮件及其附件具有保密性质,受法律保护不得泄露,仅发送给本邮件所指特定收件人。严禁非经授权使用、宣传、发布或复制本邮件或其内容。若非该特定收件人,请勿阅读、复制、 使用或披露本邮件的任何内容。若误收本邮件,请从系统中永久性删除本邮件及所有附件,并以回复邮件的方式即刻告知发件人。无法保证互联网通信及时、安全、无误或防毒。发件人对任何错漏均不承担责任。
^ permalink raw reply [flat|nested] 16+ messages in thread* [RFC PATCH 1/2] dm-verity: don't decode FEC into a dm_bufio page that is already in the cache 2026-11-10 13:06 [RFC PATCH 0/2] dm-verity: don't let FEC decode into a dm_bufio page that is already in the cache 周伟江 (Weijiang Zhou) @ 2026-11-10 13:06 ` 周伟江 (Weijiang Zhou) 2026-11-10 21:08 ` Mikulas Patocka 2026-11-10 13:06 ` [RFC PATCH 2/2] dm-verity: don't restart or panic on errors during system shutdown 周伟江 (Weijiang Zhou) 1 sibling, 1 reply; 16+ messages in thread From: 周伟江 (Weijiang Zhou) @ 2026-11-10 13:06 UTC (permalink / raw) To: dm-devel@lists.linux.dev Cc: Alasdair Kergon, Mike Snitzer, Mikulas Patocka, Benjamin Marzinski, Sami Tolvanen, 金红宇 (Hongyu Jin), 吴祥禄 (Xianglu Wu), 吴周镜 (Justin Wu) 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 <hongyu.jin@unisoc.com> Signed-off-by: weijiang.zhou <weijiang.zhou@unisoc.com> --- 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. 本邮件及其附件具有保密性质,受法律保护不得泄露,仅发送给本邮件所指特定收件人。严禁非经授权使用、宣传、发布或复制本邮件或其内容。若非该特定收件人,请勿阅读、复制、 使用或披露本邮件的任何内容。若误收本邮件,请从系统中永久性删除本邮件及所有附件,并以回复邮件的方式即刻告知发件人。无法保证互联网通信及时、安全、无误或防毒。发件人对任何错漏均不承担责任。 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [RFC PATCH 1/2] dm-verity: don't decode FEC into a dm_bufio page that is already in the cache 2026-11-10 13:06 ` [RFC PATCH 1/2] dm-verity: don't decode FEC " 周伟江 (Weijiang Zhou) @ 2026-11-10 21:08 ` Mikulas Patocka 2026-11-11 3:14 ` 周伟江 (Weijiang Zhou) ` (2 more replies) 0 siblings, 3 replies; 16+ messages in thread From: Mikulas Patocka @ 2026-11-10 21:08 UTC (permalink / raw) To: 周伟江 (Weijiang Zhou) Cc: dm-devel@lists.linux.dev, Alasdair Kergon, Mike Snitzer, Benjamin Marzinski, Sami Tolvanen, 金红宇 (Hongyu Jin), 吴祥禄 (Xianglu Wu), 吴周镜 (Justin Wu) [-- Attachment #1: Type: text/plain, Size: 5964 bytes --] 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. > 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 <hongyu.jin@unisoc.com> > Signed-off-by: weijiang.zhou <weijiang.zhou@unisoc.com> > --- > 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 Your mailing software deleted tabs from the patch. Please, fix it. Mikulas > ________________________________ > 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. > 本邮件及其附件具有保密性质,受法律保护不得泄露,仅发送给本邮件所指特定收件人。严禁非经授权使用、宣传、发布或复制本邮件或其内容。若非该特定收件人,请勿阅读、复制、 使用或披露本邮件的任何内容。若误收本邮件,请从系统中永久性删除本邮件及所有附件,并以回复邮件的方式即刻告知发件人。无法保证互联网通信及时、安全、无误或防毒。发件人对任何错漏均不承担责任。 > ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [RFC PATCH 1/2] dm-verity: don't decode FEC into a dm_bufio page that is already in the cache 2026-11-10 21:08 ` Mikulas Patocka @ 2026-11-11 3:14 ` 周伟江 (Weijiang Zhou) 2026-11-11 23:33 ` Mikulas Patocka 2026-11-12 0:38 ` Sami Tolvanen 2026-11-13 5:36 ` Eric Biggers 2 siblings, 1 reply; 16+ messages in thread From: 周伟江 (Weijiang Zhou) @ 2026-11-11 3:14 UTC (permalink / raw) To: Mikulas Patocka Cc: dm-devel@lists.linux.dev, Alasdair Kergon, Mike Snitzer, Benjamin Marzinski, Sami Tolvanen, 金红宇 (Hongyu Jin), 吴祥禄 (Xianglu Wu), 吴周镜 (Justin Wu), dhavale@google.com, ebiggers@google.com Hi Mikulas, thank you for the careful review, and for pointing straight at what needs to be fixed. We agree with you: the 1/2 sent earlier only hides the symptom, please ignore it. To make sure we read the defect the same way: in fec_read_bufs() a block whose read fails is recorded as an erasure outright; a block that reads back fine and lives on the data device is judged by fec_is_erasure(), which compares it against the digest verity_hash_for_block() produced for it. Getting that digest can walk the hash tree and read, level by level, the hash block covering that data block. When the block being recovered is itself a metadata block, a data block of the same codeword can have its hash path run through it - at level 0 one of the data blocks it covers, above level 0 one of the hash blocks below it. So the walk asks for exactly the block we are rebuilding: the one dm_bufio_new() put in the cache holding allocator leftovers, with no read ever issued for it. The digest cannot match, recursion into FEC is blocked by fio->level, and the walk ends in verity_handle_err() - the "metadata block N is corrupted" from our devices, which under restart_on_corruption means a reboot on a single transient read error. This is only reachable on the second try, the one that asks for erasures: the first try recovers the block without searching for them. Rather than defending a patch of our own, what we would really appreciate is your help with the complete fix. This is a path where a partial change worries us: the erasure search, the recursion guard in verity_fec_decode() and the hash_verified state are all involved, and from the outside we cannot judge which of them a correct fix has to touch. Our concern is that we close the case we can see and open another risk somewhere we cannot. Would you describe the fix you would consider correct - where the change belongs, and what else it has to cover? We will implement it exactly as you specify, verify it on the configuration that reproduces the problem, and send it to you for review before it goes any further. Thanks again for your time, Weijiang ________________________________ 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. 本邮件及其附件具有保密性质,受法律保护不得泄露,仅发送给本邮件所指特定收件人。严禁非经授权使用、宣传、发布或复制本邮件或其内容。若非该特定收件人,请勿阅读、复制、 使用或披露本邮件的任何内容。若误收本邮件,请从系统中永久性删除本邮件及所有附件,并以回复邮件的方式即刻告知发件人。无法保证互联网通信及时、安全、无误或防毒。发件人对任何错漏均不承担责任。 ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [RFC PATCH 1/2] dm-verity: don't decode FEC into a dm_bufio page that is already in the cache 2026-11-11 3:14 ` 周伟江 (Weijiang Zhou) @ 2026-11-11 23:33 ` Mikulas Patocka 0 siblings, 0 replies; 16+ messages in thread From: Mikulas Patocka @ 2026-11-11 23:33 UTC (permalink / raw) To: 周伟江 (Weijiang Zhou) Cc: dm-devel@lists.linux.dev, Alasdair Kergon, Mike Snitzer, Benjamin Marzinski, Sami Tolvanen, 金红宇 (Hongyu Jin), 吴祥禄 (Xianglu Wu), 吴周镜 (Justin Wu), dhavale@google.com, ebiggers@google.com [-- Attachment #1: Type: text/plain, Size: 4100 bytes --] Hi On Wed, 11 Nov 2026, 周伟江 (Weijiang Zhou) wrote: > Hi Mikulas, > > thank you for the careful review, and for pointing straight at what > needs to be fixed. We agree with you: the 1/2 sent earlier only hides > the symptom, please ignore it. > > To make sure we read the defect the same way: in fec_read_bufs() a block > whose read fails is recorded as an erasure outright; a block that reads > back fine and lives on the data device is judged by fec_is_erasure(), > which compares it against the digest verity_hash_for_block() produced > for it. Getting that digest can walk the hash tree and read, level by > level, the hash block covering that data block. When the block being > recovered is itself a metadata block, a data block of the same codeword > can have its hash path run through it - at level 0 one of the data > blocks it covers, above level 0 one of the hash blocks below it. So > the walk asks for exactly the block we are rebuilding: the one > dm_bufio_new() put in the cache holding allocator leftovers, with no > read ever issued for it. The digest cannot match, recursion into FEC > is blocked by fio->level, and the walk ends in verity_handle_err() - > the "metadata block N is corrupted" from our devices, which under > restart_on_corruption means a reboot on a single transient read error. > This is only reachable on the second try, the one that asks for > erasures: the first try recovers the block without searching for them. > > Rather than defending a patch of our own, what we would really > appreciate is your help with the complete fix. This is a path where a I think that the correct fix would be to ensure that the erasure blocks for a given tree level are stored at the same level as the blocks that they protect. Then, you will never hit the situation where the correction recurses into the same block that it attempts to correct. You would need to modify the veritysetup tool for that and maybe it would also need to introduce a new on-disk format. The forward error correction was written by Sami Tolvanen, so maybe he can help with that. Mikulas > partial change worries us: the erasure search, the recursion guard in > verity_fec_decode() and the hash_verified state are all involved, and > from the outside we cannot judge which of them a correct fix has to > touch. Our concern is that we close the case we can see and open > another risk somewhere we cannot. > > Would you describe the fix you would consider correct - where the > change belongs, and what else it has to cover? We will implement it > exactly as you specify, verify it on the configuration that reproduces > the problem, and send it to you for review before it goes any further. > > Thanks again for your time, > Weijiang > ________________________________ > 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. > 本邮件及其附件具有保密性质,受法律保护不得泄露,仅发送给本邮件所指特定收件人。严禁非经授权使用、宣传、发布或复制本邮件或其内容。若非该特定收件人,请勿阅读、复制、 使用或披露本邮件的任何内容。若误收本邮件,请从系统中永久性删除本邮件及所有附件,并以回复邮件的方式即刻告知发件人。无法保证互联网通信及时、安全、无误或防毒。发件人对任何错漏均不承担责任。 > ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [RFC PATCH 1/2] dm-verity: don't decode FEC into a dm_bufio page that is already in the cache 2026-11-10 21:08 ` Mikulas Patocka 2026-11-11 3:14 ` 周伟江 (Weijiang Zhou) @ 2026-11-12 0:38 ` Sami Tolvanen 2026-11-13 5:36 ` Eric Biggers 2 siblings, 0 replies; 16+ messages in thread From: Sami Tolvanen @ 2026-11-12 0:38 UTC (permalink / raw) To: Mikulas Patocka Cc: 周伟江 (Weijiang Zhou), dm-devel@lists.linux.dev, Alasdair Kergon, Mike Snitzer, Benjamin Marzinski, 金红宇 (Hongyu Jin), 吴祥禄 (Xianglu Wu), 吴周镜 (Justin Wu) On Tue, Nov 10, 2026 at 1:08 PM Mikulas Patocka <mpatocka@redhat.com> 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 ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [RFC PATCH 1/2] dm-verity: don't decode FEC into a dm_bufio page that is already in the cache 2026-11-10 21:08 ` Mikulas Patocka 2026-11-11 3:14 ` 周伟江 (Weijiang Zhou) 2026-11-12 0:38 ` Sami Tolvanen @ 2026-11-13 5:36 ` Eric Biggers 2026-11-19 13:22 ` 周伟江 (Weijiang Zhou) 2 siblings, 1 reply; 16+ messages in thread From: Eric Biggers @ 2026-11-13 5:36 UTC (permalink / raw) To: Mikulas Patocka Cc: 周伟江 (Weijiang Zhou), dm-devel@lists.linux.dev, Alasdair Kergon, Mike Snitzer, Benjamin Marzinski, Sami Tolvanen, 金红宇 (Hongyu Jin), 吴祥禄 (Xianglu Wu), 吴周镜 (Justin Wu) On Tue, Nov 10, 2026 at 10:08:02PM +0100, Mikulas Patocka wrote: > 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. dm-verity does use FEC to try to recover from I/O errors, but this doesn't mean that I/O errors and corruption are interchangeable and handled in the same way. See the difference at the end of verity_handle_data_hash_mismatch(), for example. It calls verity_handle_err() only on actual corruption, not an I/O error. That triggers the corruption policy controlled by 'v->mode', which is different from the I/O error policy controlled by 'v->error_mode'. > > 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. There does seem to be a bug where when FEC is trying to read data block hashes to correct a block, it can detect corruption in the hash tree and be unable to correct it due to FEC being non-recursive. That triggers the corruption policy, when really it shouldn't and FEC should just consider erasure information unavailable. That is fixable. But it is not the root cause problem here. The root cause problem is that the call to dm_bufio_new() injects uninitialized data into the hash block cache as if it came from a successful read. That turns an I/O error into corruption, making the corruption policy take effect merely due to an I/O error. This is not limited to FEC reading the data block erasures, either; any concurrent reader can trip over this corruption. It seems that dm_bufio_new() was designed for writers that overwrite the full block without reading any of it while also excluding concurrent readers, e.g. using locks. That just does not work here, unfortunately. Using a kmalloc() buffer (this patch) kind of works but is a hack because it doesn't actually populate the cache at all. I think the correct solution would be to have the FEC output initially just go into fio->output, then populate the cache atomically with the data. Seems that dm-bufio.c will need a new function for that. - Eric ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [RFC PATCH 1/2] dm-verity: don't decode FEC into a dm_bufio page that is already in the cache 2026-11-13 5:36 ` Eric Biggers @ 2026-11-19 13:22 ` 周伟江 (Weijiang Zhou) 2026-12-02 13:05 ` 周伟江 (Weijiang Zhou) 0 siblings, 1 reply; 16+ messages in thread From: 周伟江 (Weijiang Zhou) @ 2026-11-19 13:22 UTC (permalink / raw) To: Eric Biggers, Mikulas Patocka Cc: dm-devel@lists.linux.dev, Alasdair Kergon, Mike Snitzer, Benjamin Marzinski, Sami Tolvanen, 金红宇 (Hongyu Jin), 吴祥禄 (Xianglu Wu), 吴周镜 (Justin Wu) [-- Attachment #1: Type: text/plain, Size: 4545 bytes --] Hi Eric and Sami, Thank you both for your careful review and guidance. Eric, thank you for explaining why an I/O error must not be escalated to corruption, and for recommending that FEC decode into fio->output first and then populate the cache atomically. Thank you also for accepting the shutdown workaround into mainline and cherry-picking it to the Android Common Kernel branches. Sami, thank you for pointing out that erasure lookup is optional and that a verification failure while looking up erasures should not be treated as a fatal corruption error. Your suggestion helped us separate the erasure lookup error handling from the real corruption path. Based on your feedback, we have prepared the attached four-patch series against our 6.18 branch: 1. Backport the shutdown workaround that is already in mainline. This is included only to make our branch series complete; it is not intended as a duplicate upstream change. 2. Add NF_FILLED and dm_bufio_new_filled() to dm-bufio. The supplied data is copied into the buffer before cache_insert() makes it visible to other readers. Existing dm-bufio APIs keep their previous behavior. 3. Prevent FEC from publishing uninitialized hash blocks. FEC now decodes into the per-I/O private fio->output buffer. After successful decoding and hash verification, dm-verity publishes the corrected data with dm_bufio_new_filled(). Because dm_bufio_new_filled() can return an existing cached buffer and ignore the supplied data, we compare the returned contents with fio->output. We set hash_verified only if they match. If publication fails, or the existing buffer contains different data, the current verification falls back to the verified private output and releases the buffer reference where necessary. 4. Avoid corruption policy during FEC erasure lookup. A hash-tree failure while looking up erasures now returns -EIO as "erasure information unavailable" instead of invoking the corruption policy. The normal verification path still handles real corruption as before. Could you please review this series, especially patches 2-4, and check whether it implements the intended root-cause fix correctly? In particular, we would appreciate your feedback on: - whether NF_FILLED is an appropriate minimal dm-bufio interface; - whether the cache-hit handling, private-output fallback, reference counting, and hash_verified updates are correct; - whether any cache-visibility or concurrency window remains; - whether the erasure lookup error-policy isolation is sufficiently narrow; and - whether there is a simpler or more appropriate solution. We are concerned that we may have overlooked a corner case in concurrency, cache lifetime, FEC recovery, or error handling and could inadvertently introduce a regression. If you see a better approach, we would be very happy to rework the patches according to your suggestions. We are currently preparing a build for stress testing, and the final four-patch series has not yet undergone actual validation. Thank you again for your time and guidance. Best regards, Weijiang Zhou ________________________________ 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. 本邮件及其附件具有保密性质,受法律保护不得泄露,仅发送给本邮件所指特定收件人。严禁非经授权使用、宣传、发布或复制本邮件或其内容。若非该特定收件人,请勿阅读、复制、 使用或披露本邮件的任何内容。若误收本邮件,请从系统中永久性删除本邮件及所有附件,并以回复邮件的方式即刻告知发件人。无法保证互联网通信及时、安全、无误或防毒。发件人对任何错漏均不承担责任。 [-- Attachment #2: 0001-Bug-3623141-UPSTREAM-dm-verity-don-t-restart-or-pani.patch --] [-- Type: application/octet-stream, Size: 3382 bytes --] From 2217f02fd45c289cbacf35426c7dd3bc8089e709 Mon Sep 17 00:00:00 2001 From: Weijiang Zhou <weijiang.zhou@unisoc.com> Date: Wed, 11 Nov 2026 20:24:42 +0100 Subject: [PATCH 1/4] Bug #3623141: UPSTREAM: dm-verity: don't restart or panic on errors during system shutdown 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 Bug: 584157730 (cherry picked from commit 47930d1236d2988cdc580c10d3af21b6b02d7ece) Change-Id: I8ba6573910849fd067cd61b123c42e9f6e9be3a3 Signed-off-by: Eric Biggers <ebiggers@google.com> --- 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 08a58a0b5e49a..cdad28511877e 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"); @@ -592,15 +610,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.34.1 [-- Attachment #3: 0002-Bug-3623141-dm-bufio-support-atomic-publication-of-p.patch --] [-- Type: application/octet-stream, Size: 6791 bytes --] From 02f63ee0a39ceace90ab515c5c297a00a5faff02 Mon Sep 17 00:00:00 2001 From: "weijiang.zhou" <weijiang.zhou@unisoc.com> Date: Wed, 18 Nov 2026 16:24:20 +0800 Subject: [PATCH 2/4] Bug #3623141: dm-bufio: support atomic publication of pre-filled buffers [root cause ]: dm-verity FEC must not publish a hash block until correction and hash verification complete. dm_bufio_new() currently exposes an unfilled buffer to concurrent readers before initialization. [changes ]: 1. Add NF_FILLED and dm_bufio_new_filled() to copy the caller's data before cache_insert(). 2. Preserve the existing-buffer return semantics and export the new API for dm-verity. [board]: all [test case]: git apply --check; git diff --check; checkpatch; static review [ai generated code ratio]: 1 commit_template_version:v2 Change-Id: I47f89c2a847d6afed9025c45442127a57339fc07 Signed-off-by: weijiang.zhou <weijiang.zhou@unisoc.com> --- drivers/md/dm-bufio.c | 48 ++++++++++++++++++++++++++++++++-------- include/linux/dm-bufio.h | 14 ++++++++++-- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c index ae169f3091e32..9c960b2e5ccb1 100644 --- a/drivers/md/dm-bufio.c +++ b/drivers/md/dm-bufio.c @@ -1590,7 +1590,8 @@ enum new_flag { NF_FRESH = 0, NF_READ = 1, NF_GET = 2, - NF_PREFETCH = 3 + NF_PREFETCH = 3, + NF_FILLED = 4 }; /* @@ -1774,7 +1775,8 @@ static void cache_put_and_wake(struct dm_bufio_client *c, static struct dm_buffer *__bufio_new(struct dm_bufio_client *c, struct buffer_tree *tree, sector_t block, enum new_flag nf, int *need_submit, - struct list_head *write_list) + struct list_head *write_list, + const void *fill_data) { struct dm_buffer *b, *new_b = NULL; @@ -1808,13 +1810,20 @@ static struct dm_buffer *__bufio_new(struct dm_bufio_client *c, b->write_error = 0; b->list_mode = LIST_CLEAN; - if (nf == NF_FRESH) + if (nf == NF_FRESH || nf == NF_FILLED) b->state = 0; else { b->state = 1 << B_READING; *need_submit = 1; } + /* + * NF_FILLED: populate the buffer before it becomes visible in the + * cache, so that no reader can ever observe uninitialized contents. + */ + if (nf == NF_FILLED) + memcpy(b->data, fill_data, c->block_size); + /* * We mustn't insert into the cache until the B_READING state * is set. Otherwise another thread could get it and use @@ -1870,7 +1879,7 @@ static void read_endio(struct dm_buffer *b, blk_status_t status) */ static void *new_read(struct dm_bufio_client *c, sector_t block, enum new_flag nf, struct dm_buffer **bp, - unsigned short ioprio) + unsigned short ioprio, const void *fill_data) { struct buffer_tree *tree; int need_submit = 0; @@ -1910,7 +1919,8 @@ static void *new_read(struct dm_bufio_client *c, sector_t block, return NULL; dm_bufio_lock(c); - b = __bufio_new(c, tree, block, nf, &need_submit, &write_list); + b = __bufio_new(c, tree, block, nf, &need_submit, &write_list, + fill_data); dm_bufio_unlock(c); } @@ -1946,7 +1956,7 @@ static void *new_read(struct dm_bufio_client *c, sector_t block, void *dm_bufio_get(struct dm_bufio_client *c, sector_t block, struct dm_buffer **bp) { - return new_read(c, block, NF_GET, bp, IOPRIO_DEFAULT); + return new_read(c, block, NF_GET, bp, IOPRIO_DEFAULT, NULL); } EXPORT_SYMBOL_GPL(dm_bufio_get); @@ -1956,7 +1966,7 @@ static void *__dm_bufio_read(struct dm_bufio_client *c, sector_t block, if (WARN_ON_ONCE(dm_bufio_in_request())) return ERR_PTR(-EINVAL); - return new_read(c, block, NF_READ, bp, ioprio); + return new_read(c, block, NF_READ, bp, ioprio, NULL); } void *dm_bufio_read(struct dm_bufio_client *c, sector_t block, @@ -1979,10 +1989,30 @@ void *dm_bufio_new(struct dm_bufio_client *c, sector_t block, if (WARN_ON_ONCE(dm_bufio_in_request())) return ERR_PTR(-EINVAL); - return new_read(c, block, NF_FRESH, bp, IOPRIO_DEFAULT); + return new_read(c, block, NF_FRESH, bp, IOPRIO_DEFAULT, NULL); } EXPORT_SYMBOL_GPL(dm_bufio_new); +/* + * Publish a fully prepared block into the cache. Unlike dm_bufio_new(), + * the buffer is populated with @data before it becomes visible to other + * readers, so no one can observe uninitialized contents. If the block is + * already cached, the existing buffer is returned and @data is not used. + * + * The returned buffer is held and must be released with dm_bufio_release(). + * The caller may inspect or modify the data, but must not mark it dirty + * unless it intends to write the block back to the device. + */ +void *dm_bufio_new_filled(struct dm_bufio_client *c, sector_t block, + const void *data, struct dm_buffer **bp) +{ + if (WARN_ON_ONCE(dm_bufio_in_request())) + return ERR_PTR(-EINVAL); + + return new_read(c, block, NF_FILLED, bp, IOPRIO_DEFAULT, data); +} +EXPORT_SYMBOL_GPL(dm_bufio_new_filled); + static void __dm_bufio_prefetch(struct dm_bufio_client *c, sector_t block, unsigned int n_blocks, unsigned short ioprio) @@ -2011,7 +2041,7 @@ static void __dm_bufio_prefetch(struct dm_bufio_client *c, dm_bufio_lock(c); b = __bufio_new(c, tree, block, NF_PREFETCH, &need_submit, - &write_list); + &write_list, NULL); if (unlikely(!list_empty(&write_list))) { dm_bufio_unlock(c); blk_finish_plug(&plug); diff --git a/include/linux/dm-bufio.h b/include/linux/dm-bufio.h index d1503b815a789..4dacef1c43e44 100644 --- a/include/linux/dm-bufio.h +++ b/include/linux/dm-bufio.h @@ -81,6 +81,16 @@ void *dm_bufio_get(struct dm_bufio_client *c, sector_t block, void *dm_bufio_new(struct dm_bufio_client *c, sector_t block, struct dm_buffer **bp); +/* + * Like dm_bufio_new, but the buffer is populated with @data before it + * becomes visible in the cache, so no reader can observe uninitialized + * contents. If the block is already cached, the existing buffer is + * returned and @data is not used. The caller must not mark the buffer + * dirty unless it intends to write the block back to the device. + */ +void *dm_bufio_new_filled(struct dm_bufio_client *c, sector_t block, + const void *data, struct dm_buffer **bp); + /* * Prefetch the specified blocks to the cache. * The function starts to read the blocks and returns without waiting for @@ -94,8 +104,8 @@ void dm_bufio_prefetch_with_ioprio(struct dm_bufio_client *c, unsigned short ioprio); /* - * Release a reference obtained with dm_bufio_{read,get,new}. The data - * pointer and dm_buffer pointer is no longer valid after this call. + * Release a reference obtained with dm_bufio_{read,get,new,new_filled}. The + * data pointer and dm_buffer pointer is no longer valid after this call. */ void dm_bufio_release(struct dm_buffer *b); -- 2.34.1 [-- Attachment #4: 0003-Bug-3623141-dm-verity-prevent-FEC-from-publishing-un.patch --] [-- Type: application/octet-stream, Size: 7374 bytes --] From 10ee0fb15c06d46ed87e494c36bf9f463703a8c1 Mon Sep 17 00:00:00 2001 From: "weijiang.zhou" <weijiang.zhou@unisoc.com> Date: Wed, 18 Nov 2026 16:26:36 +0800 Subject: [PATCH 3/4] Bug #3623141: dm-verity: prevent FEC from publishing uninitialized hash blocks [root cause ]: After a hash block read failure, dm_bufio_new() publishes an uninitialized buffer before FEC corrects it in place. Nested erasure lookups or concurrent readers can mistake it for valid metadata, turning an I/O error into corruption. [changes ]: 1. Decode FEC into the per-I/O private output buffer and retain the final expected-hash verification. 2. Publish the corrected block atomically with dm_bufio_new_filled(). Mark an existing cached buffer as hash-verified only if it matches the output. 3. Fall back to the private output if publication fails or the existing buffer differs, and release each buffer reference exactly once. [board]: all [test case]: git apply --check; git diff --check; checkpatch; static review [ai generated code ratio]: 1 commit_template_version:v2 Change-Id: I84a4682249eb41cf3a95dac2c757f886e62a3d99 Signed-off-by: weijiang.zhou <weijiang.zhou@unisoc.com> --- drivers/md/dm-verity-fec.c | 19 ++++++++- drivers/md/dm-verity-fec.h | 7 +++ drivers/md/dm-verity-target.c | 80 +++++++++++++++++++++++++++++------ 3 files changed, 90 insertions(+), 16 deletions(-) diff --git a/drivers/md/dm-verity-fec.c b/drivers/md/dm-verity-fec.c index c3caf33ae6949..aa48c7780a49f 100644 --- a/drivers/md/dm-verity-fec.c +++ b/drivers/md/dm-verity-fec.c @@ -369,7 +369,11 @@ static int fec_decode(struct dm_verity *v, struct dm_verity_io *io, return 0; } -/* Correct errors in a block. Copies corrected block to dest. */ +/* + * Correct errors in a block. If @dest is non-NULL, copy the corrected block + * to it. Otherwise the corrected block is left in fio->output and can be + * retrieved with verity_fec_output() until the next FEC operation on this io. + */ int verity_fec_decode(struct dm_verity *v, struct dm_verity_io *io, enum verity_block_type type, const u8 *want_digest, sector_t block, u8 *dest) @@ -404,7 +408,8 @@ int verity_fec_decode(struct dm_verity *v, struct dm_verity_io *io, goto done; } - memcpy(dest, fio->output, v->fec->block_size); + if (dest) + memcpy(dest, fio->output, v->fec->block_size); atomic64_inc(&v->fec->corrected); done: @@ -412,6 +417,16 @@ int verity_fec_decode(struct dm_verity *v, struct dm_verity_io *io, return r; } +/* + * Return the private output buffer holding the last block recovered by + * verity_fec_decode() with a NULL destination. Only valid until the next + * FEC operation on this io. + */ +u8 *verity_fec_output(struct dm_verity_io *io) +{ + return io->fec_io ? io->fec_io->output : NULL; +} + /* * Clean up per-bio data. */ diff --git a/drivers/md/dm-verity-fec.h b/drivers/md/dm-verity-fec.h index 50b5e187d5cc1..b2bf01dc5e6cd 100644 --- a/drivers/md/dm-verity-fec.h +++ b/drivers/md/dm-verity-fec.h @@ -76,6 +76,8 @@ extern int verity_fec_decode(struct dm_verity *v, struct dm_verity_io *io, enum verity_block_type type, const u8 *want_digest, sector_t block, u8 *dest); +extern u8 *verity_fec_output(struct dm_verity_io *io); + extern unsigned int verity_fec_status_table(struct dm_verity *v, unsigned int sz, char *result, unsigned int maxlen); @@ -119,6 +121,11 @@ static inline int verity_fec_decode(struct dm_verity *v, return -EOPNOTSUPP; } +static inline u8 *verity_fec_output(struct dm_verity_io *io) +{ + return NULL; +} + static inline unsigned int verity_fec_status_table(struct dm_verity *v, unsigned int sz, char *result, unsigned int maxlen) diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c index cdad28511877e..12b1f76a8c389 100644 --- a/drivers/md/dm-verity-target.c +++ b/drivers/md/dm-verity-target.c @@ -287,19 +287,42 @@ static int verity_verify_level(struct dm_verity *v, struct dm_verity_io *io, if (skip_unverified) return 1; r = PTR_ERR(data); - data = dm_bufio_new(v->bufio, hash_block, &buf); - if (IS_ERR(data)) - return r; + /* + * Recover the block with FEC into the io's private output + * buffer first, then publish the fully corrected block into + * the cache atomically. Decoding into a dm_bufio_new() + * buffer instead would insert uninitialized data into the + * cache as if it had been read successfully, so any + * concurrent reader (including FEC's own erasure lookups) + * could hash that garbage and treat the I/O error as + * corruption. + */ if (verity_fec_decode(v, io, DM_VERITY_BLOCK_TYPE_METADATA, - want_digest, hash_block, data) == 0) { + want_digest, hash_block, NULL) < 0) + return r; + /* + * Drop any leftover buffer from the failed read (it is + * normally already removed by dm_bufio_release(), but may + * linger if another thread still holds it), so that the + * corrected block is actually published. + */ + u8 *output = verity_fec_output(io); + + dm_bufio_forget(v->bufio, hash_block); + data = dm_bufio_new_filled(v->bufio, hash_block, + output, &buf); + if (IS_ERR(data)) { + data = output; + } else if (memcmp(data, output, + 1 << v->hash_dev_block_bits)) { + dm_bufio_release(buf); + buf = NULL; + data = output; + } else { 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; } + goto release_ok; } aux = dm_bufio_get_aux_data(buf); @@ -325,10 +348,38 @@ static int verity_verify_level(struct dm_verity *v, struct dm_verity_io *io, */ r = -EAGAIN; goto release_ret_r; - } else if (verity_fec_decode(v, io, DM_VERITY_BLOCK_TYPE_METADATA, - want_digest, hash_block, data) == 0) - aux->hash_verified = 1; - else if (verity_handle_err(v, + } else if (verity_fec_decode(v, io, + DM_VERITY_BLOCK_TYPE_METADATA, + want_digest, hash_block, NULL) == 0) { + u8 *output = verity_fec_output(io); + + /* + * The cached buffer failed verification. Drop it and + * publish the corrected block atomically; never + * overwrite the cached buffer in place, since + * concurrent readers may be hashing it. If the bad + * buffer lingers in the cache because another thread + * still holds it, dm_bufio_new_filled() returns it + * unchanged; in that case use the private corrected + * block for this verification only. + */ + dm_bufio_release(buf); + dm_bufio_forget(v->bufio, hash_block); + data = dm_bufio_new_filled(v->bufio, hash_block, + output, &buf); + if (IS_ERR(data)) { + data = output; + } else if (memcmp(data, output, + 1 << v->hash_dev_block_bits)) { + dm_bufio_release(buf); + buf = NULL; + data = output; + } else { + aux = dm_bufio_get_aux_data(buf); + aux->hash_verified = 1; + } + goto release_ok; + } else if (verity_handle_err(v, DM_VERITY_BLOCK_TYPE_METADATA, hash_block)) { struct bio *bio; @@ -347,7 +398,8 @@ static int verity_verify_level(struct dm_verity *v, struct dm_verity_io *io, r = 0; release_ret_r: - dm_bufio_release(buf); + if (buf) + dm_bufio_release(buf); return r; } -- 2.34.1 [-- Attachment #5: 0004-Bug-3623141-dm-verity-avoid-corruption-policy-during.patch --] [-- Type: application/octet-stream, Size: 4915 bytes --] From bc3ea128b0abcc97809cd54b9b08f69bd76efd04 Mon Sep 17 00:00:00 2001 From: "weijiang.zhou" <weijiang.zhou@unisoc.com> Date: Wed, 18 Nov 2026 16:27:48 +0800 Subject: [PATCH 4/4] Bug #3623141: dm-verity: avoid corruption policy during FEC erasure lookup [root cause ]: FEC speculatively walks the hash tree to locate erasures. A lookup failure only means erasure information is unavailable; it must not be promoted to corruption of the current bio or trigger a restart or panic. [changes ]: 1. Add a per-I/O erasure lookup flag to dm_verity_io and initialize it in verity_map(). 2. Set the flag only around the synchronous hash tree walk in fec_read_bufs() and clear it immediately afterward. 3. Return -EIO without calling verity_handle_err() when speculative verification fails. Preserve the normal data corruption policy. [board]: all [test case]: git apply --check; git diff --check; checkpatch; static review [ai generated code ratio]: 1 commit_template_version:v2 Change-Id: Icff6af341ac3e319d4ffba78855ea52581717b2a Signed-off-by: weijiang.zhou <weijiang.zhou@unisoc.com> --- drivers/md/dm-verity-fec.c | 36 ++++++++++++++++++++++------------- drivers/md/dm-verity-target.c | 11 +++++++++++ drivers/md/dm-verity.h | 7 +++++++ 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/drivers/md/dm-verity-fec.c b/drivers/md/dm-verity-fec.c index aa48c7780a49f..f7e75e28b9811 100644 --- a/drivers/md/dm-verity-fec.c +++ b/drivers/md/dm-verity-fec.c @@ -175,7 +175,7 @@ static int fec_read_bufs(struct dm_verity *v, struct dm_verity_io *io, unsigned int out_pos, int *neras) { bool is_zero; - int i, j; + int i, j, r; struct dm_buffer *buf; struct dm_bufio_client *bufio; struct dm_verity_fec_io *fio = io->fec_io; @@ -227,20 +227,30 @@ static int fec_read_bufs(struct dm_verity *v, struct dm_verity_io *io, } /* locate erasures if the block is on the data device */ - if (bufio == v->fec->data_bufio && - verity_hash_for_block(v, io, block, want_digest, - &is_zero) == 0) { - /* skip known zero blocks entirely */ - if (is_zero) - goto done; - + if (bufio == v->fec->data_bufio) { /* - * skip if we have already found the theoretical - * maximum number (i.e. fec->roots) of erasures + * This hash tree walk is speculative: a failure only + * means erasure information is unavailable. Suppress + * the corruption policy while it runs, so that an + * I/O error here cannot restart or panic the system. */ - if (neras && *neras <= v->fec->roots && - fec_is_erasure(v, io, want_digest, bbuf)) - fio->erasures[(*neras)++] = i; + io->fec_erasure_lookup = true; + r = verity_hash_for_block(v, io, block, want_digest, + &is_zero); + io->fec_erasure_lookup = false; + if (r == 0) { + /* skip known zero blocks entirely */ + if (is_zero) + goto done; + + /* + * skip if we have already found the theoretical + * maximum number (i.e. fec->roots) of erasures + */ + if (neras && *neras <= v->fec->roots && + fec_is_erasure(v, io, want_digest, bbuf)) + fio->erasures[(*neras)++] = i; + } } /* diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c index 12b1f76a8c389..53eae9f419087 100644 --- a/drivers/md/dm-verity-target.c +++ b/drivers/md/dm-verity-target.c @@ -379,6 +379,16 @@ static int verity_verify_level(struct dm_verity *v, struct dm_verity_io *io, aux->hash_verified = 1; } goto release_ok; + } else if (io->fec_erasure_lookup) { + /* + * FEC is walking the hash tree speculatively to + * locate erasures. A failure here only means + * erasure information is unavailable; it is not + * corruption of this bio's data, so do not call + * verity_handle_err() or record a mismatch. + */ + r = -EIO; + goto release_ret_r; } else if (verity_handle_err(v, DM_VERITY_BLOCK_TYPE_METADATA, hash_block)) { @@ -871,6 +881,7 @@ static int verity_map(struct dm_target *ti, struct bio *bio) io->block = bio->bi_iter.bi_sector >> (v->data_dev_block_bits - SECTOR_SHIFT); io->n_blocks = bio->bi_iter.bi_size >> v->data_dev_block_bits; io->had_mismatch = false; + io->fec_erasure_lookup = false; bio->bi_end_io = verity_end_io; bio->bi_private = io; diff --git a/drivers/md/dm-verity.h b/drivers/md/dm-verity.h index 2922263501f68..9143920d2d551 100644 --- a/drivers/md/dm-verity.h +++ b/drivers/md/dm-verity.h @@ -103,6 +103,13 @@ struct dm_verity_io { unsigned int n_blocks; bool in_bh; bool had_mismatch; + /* + * Set while FEC looks up data block hashes to locate erasures. + * Verification failures during such lookups only mean that erasure + * information is unavailable; they must not trigger the corruption + * policy. + */ + bool fec_erasure_lookup; #ifdef CONFIG_DM_VERITY_FEC struct dm_verity_fec_io *fec_io; -- 2.34.1 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [RFC PATCH 1/2] dm-verity: don't decode FEC into a dm_bufio page that is already in the cache 2026-11-19 13:22 ` 周伟江 (Weijiang Zhou) @ 2026-12-02 13:05 ` 周伟江 (Weijiang Zhou) 2026-12-02 19:04 ` Eric Biggers 0 siblings, 1 reply; 16+ messages in thread From: 周伟江 (Weijiang Zhou) @ 2026-12-02 13:05 UTC (permalink / raw) To: Eric Biggers, Sami Tolvanen, Mikulas Patocka Cc: dm-devel@lists.linux.dev, Alasdair Kergon, Mike Snitzer, Benjamin Marzinski, 金红宇 (Hongyu Jin), 吴祥禄 (Xianglu Wu), 吴周镜 (Justin Wu) Hi Eric, Sami and Mikulas, Sorry to ping this thread again - we know this is a busy time of year, and we are grateful for the help you have already given us. We are gently following up on the four-patch series we sent on Nov 19 (as attachments in this thread), which implements the approach you recommended: FEC decodes into the per-I/O fio->output buffer first and populates the cache atomically through a new dm-bufio interface (0002/0003), and the corruption policy is no longer invoked while the erasure lookup walks the hash tree (0004). First, could you let us know whether that email and its attachments reached you? Our corporate mail gateway has mangled our outbound mail before (the lost TABs and the appended footers you saw), so if the message or the patches arrived damaged or were filtered out, we will gladly resend them inline. Second, whenever you can find a moment, we would appreciate your comments on patches 0002-0004. We are not committed to our own version: if you see a better approach, or if you would rather take the series over, rework it, or replace it with something of your own, we would much prefer the fix to come from you. On our side the stress testing of the series is still in progress; we will share the results as soon as it completes. Finally, two questions about the Android GKI side: 1. Eric, you mentioned that the shutdown workaround (upstream commit 47930d1236d2, now also queued for the 6.12/6.18/7.3 stable trees) had been cherry-picked to the Android Common Kernel branches. Will it be part of the December quarterly release (QPR)? If not, when is the next GKI build that contains it expected? Our Android 17 projects pace their OTA plans against the GKI cadence, so even a rough estimate would help us a lot. 2. About the FEC root-cause fix (our 0002-0004, or your own version of it): our devices boot Google's GKI images, so we cannot carry the series in our own kernel - for now it only runs on an internal test branch for stress testing, and the fix has to reach our devices through the ACK/GKI. On the geometries we described, a single failed hash read reports corruption even outside shutdown, so the timing matters to us. Is there any chance the fix could still make it into the December QPR, or would it be a later one? And is there anything we can do from our side to help it along? As always, we have devices that reproduce the issue and are glad to verify any approach you prefer. Thank you again for your time and guidance. Best regards, Weijiang Zhou ________________________________ 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. 本邮件及其附件具有保密性质,受法律保护不得泄露,仅发送给本邮件所指特定收件人。严禁非经授权使用、宣传、发布或复制本邮件或其内容。若非该特定收件人,请勿阅读、复制、 使用或披露本邮件的任何内容。若误收本邮件,请从系统中永久性删除本邮件及所有附件,并以回复邮件的方式即刻告知发件人。无法保证互联网通信及时、安全、无误或防毒。发件人对任何错漏均不承担责任。 ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [RFC PATCH 1/2] dm-verity: don't decode FEC into a dm_bufio page that is already in the cache 2026-12-02 13:05 ` 周伟江 (Weijiang Zhou) @ 2026-12-02 19:04 ` Eric Biggers 0 siblings, 0 replies; 16+ messages in thread From: Eric Biggers @ 2026-12-02 19:04 UTC (permalink / raw) To: 周伟江 (Weijiang Zhou) Cc: Sami Tolvanen, Mikulas Patocka, dm-devel@lists.linux.dev, Alasdair Kergon, Mike Snitzer, Benjamin Marzinski, 金红宇 (Hongyu Jin), 吴祥禄 (Xianglu Wu), 吴周镜 (Justin Wu) Hi Weijiang, On Wed, Dec 02, 2026 at 01:05:19PM +0000, 周伟江 (Weijiang Zhou) wrote: > Hi Eric, Sami and Mikulas, > > Sorry to ping this thread again - we know this is a busy time of > year, and we are grateful for the help you have already given us. > > We are gently following up on the four-patch series we sent on Nov 19 > (as attachments in this thread), which implements the approach you > recommended: FEC decodes into the per-I/O fio->output buffer first > and populates the cache atomically through a new dm-bufio interface > (0002/0003), and the corruption policy is no longer invoked while the > erasure lookup walks the hash tree (0004). > > First, could you let us know whether that email and its attachments > reached you? Our corporate mail gateway has mangled our outbound mail > before (the lost TABs and the appended footers you saw), so if the > message or the patches arrived damaged or were filtered out, we will > gladly resend them inline. > > Second, whenever you can find a moment, we would appreciate your > comments on patches 0002-0004. We are not committed to our own > version: if you see a better approach, or if you would rather take the > series over, rework it, or replace it with something of your own, we > would much prefer the fix to come from you. On our side the stress > testing of the series is still in progress; we will share the results > as soon as it completes. I did get the patches, and it's on my long list of things to review. I've just been busy with other things, sorry. Note that attachments are not the normal way to send Linux kernel patches. Also, all your emails also have a notice at the bottom telling people to delete your emails. It would be helpful if you would resend them in the normal format as per Documentation/process/submitting-patches.rst, and also without asking for them to be deleted. Then people would be more likely to look at them. > 1. Eric, you mentioned that the shutdown workaround (upstream commit > 47930d1236d2, now also queued for the 6.12/6.18/7.3 stable trees) > had been cherry-picked to the Android Common Kernel branches. > Will it be part of the December quarterly release (QPR)? If not, > when is the next GKI build that contains it expected? Our Android > 17 projects pace their OTA plans against the GKI cadence, so even > a rough estimate would help us a lot. > > 2. About the FEC root-cause fix (our 0002-0004, or your own version > of it): our devices boot Google's GKI images, so we cannot carry > the series in our own kernel - for now it only runs on an internal > test branch for stress testing, and the fix has to reach our > devices through the ACK/GKI. On the geometries we described, a > single failed hash read reports corruption even outside shutdown, > so the timing matters to us. Is there any chance the fix could > still make it into the December QPR, or would it be a later one? > And is there anything we can do from our side to help it along? > > As always, we have devices that reproduce the issue and are glad to > verify any approach you prefer. > > Thank you again for your time and guidance. The commit is in the android16-6.12-2026-12 and android17-6.18-2026-12 release branches already. If you need it in other branches too, you could submit a GKI respin request using the process documented at source.android.com. In any case, if you have any further questions about Android / GKI specific stuff please use the partner issue tracker, as it isn't relevant to the upstream mailing lists. Thanks! - Eric ^ permalink raw reply [flat|nested] 16+ messages in thread
* [RFC PATCH 2/2] dm-verity: don't restart or panic on errors during system shutdown 2026-11-10 13:06 [RFC PATCH 0/2] dm-verity: don't let FEC decode into a dm_bufio page that is already in the cache 周伟江 (Weijiang Zhou) 2026-11-10 13:06 ` [RFC PATCH 1/2] dm-verity: don't decode FEC " 周伟江 (Weijiang Zhou) @ 2026-11-10 13:06 ` 周伟江 (Weijiang Zhou) 2026-11-10 21:13 ` Mikulas Patocka 2026-11-13 5:55 ` Eric Biggers 1 sibling, 2 replies; 16+ messages in thread From: 周伟江 (Weijiang Zhou) @ 2026-11-10 13:06 UTC (permalink / raw) To: dm-devel@lists.linux.dev Cc: Alasdair Kergon, Mike Snitzer, Mikulas Patocka, Benjamin Marzinski, Sami Tolvanen, 金红宇 (Hongyu Jin), 吴祥禄 (Xianglu Wu), 吴周镜 (Justin Wu) 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> --- 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. 本邮件及其附件具有保密性质,受法律保护不得泄露,仅发送给本邮件所指特定收件人。严禁非经授权使用、宣传、发布或复制本邮件或其内容。若非该特定收件人,请勿阅读、复制、 使用或披露本邮件的任何内容。若误收本邮件,请从系统中永久性删除本邮件及所有附件,并以回复邮件的方式即刻告知发件人。无法保证互联网通信及时、安全、无误或防毒。发件人对任何错漏均不承担责任。 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [RFC PATCH 2/2] dm-verity: don't restart or panic on errors during system shutdown 2026-11-10 13:06 ` [RFC PATCH 2/2] dm-verity: don't restart or panic on errors during system shutdown 周伟江 (Weijiang Zhou) @ 2026-11-10 21:13 ` Mikulas Patocka 2026-11-11 3:14 ` 周伟江 (Weijiang Zhou) 2026-11-13 5:55 ` Eric Biggers 1 sibling, 1 reply; 16+ messages in thread From: Mikulas Patocka @ 2026-11-10 21:13 UTC (permalink / raw) To: 周伟江 (Weijiang Zhou) Cc: dm-devel@lists.linux.dev, Alasdair Kergon, Mike Snitzer, Benjamin Marzinski, Sami Tolvanen, 金红宇 (Hongyu Jin), 吴祥禄 (Xianglu Wu), 吴周镜 (Justin Wu) [-- Attachment #1: Type: text/plain, Size: 4348 bytes --] On Tue, 10 Nov 2026, 周伟江 (Weijiang Zhou) wrote: > 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. This patch is acceptable - but, please, resend the patch with proper TABs. Mikulas > Signed-off-by: Hongyu Jin <hongyu.jin@unisoc.com> > Signed-off-by: weijiang.zhou <weijiang.zhou@unisoc.com> > --- > 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. > 本邮件及其附件具有保密性质,受法律保护不得泄露,仅发送给本邮件所指特定收件人。严禁非经授权使用、宣传、发布或复制本邮件或其内容。若非该特定收件人,请勿阅读、复制、 使用或披露本邮件的任何内容。若误收本邮件,请从系统中永久性删除本邮件及所有附件,并以回复邮件的方式即刻告知发件人。无法保证互联网通信及时、安全、无误或防毒。发件人对任何错漏均不承担责任。 > ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [RFC PATCH 2/2] dm-verity: don't restart or panic on errors during system shutdown 2026-11-10 21:13 ` Mikulas Patocka @ 2026-11-11 3:14 ` 周伟江 (Weijiang Zhou) 2026-11-11 22:48 ` Mikulas Patocka 0 siblings, 1 reply; 16+ messages in thread From: 周伟江 (Weijiang Zhou) @ 2026-11-11 3:14 UTC (permalink / raw) To: Mikulas Patocka Cc: dm-devel@lists.linux.dev, Alasdair Kergon, Mike Snitzer, Benjamin Marzinski, Sami Tolvanen, 金红宇 (Hongyu Jin), 吴祥禄 (Xianglu Wu), 吴周镜 (Justin Wu), dhavale@google.com, ebiggers@google.com Hi Mikulas, thanks for the review, and sorry about the TABs. They were not lost while composing: the message left my client intact, and the rich-text path of our corporate mail setup re-encoded the text part on the way out, dropped every TAB and reflowed the long lines. I have moved to a submission path that hands the MIME to the server byte for byte, and checked the round trip through a mailbox first. The patch below is the same patch, unchanged - no code was touched since your review, only the whitespace is back. Thanks, Weijiang 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> --- 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. 本邮件及其附件具有保密性质,受法律保护不得泄露,仅发送给本邮件所指特定收件人。严禁非经授权使用、宣传、发布或复制本邮件或其内容。若非该特定收件人,请勿阅读、复制、 使用或披露本邮件的任何内容。若误收本邮件,请从系统中永久性删除本邮件及所有附件,并以回复邮件的方式即刻告知发件人。无法保证互联网通信及时、安全、无误或防毒。发件人对任何错漏均不承担责任。 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [RFC PATCH 2/2] dm-verity: don't restart or panic on errors during system shutdown 2026-11-11 3:14 ` 周伟江 (Weijiang Zhou) @ 2026-11-11 22:48 ` Mikulas Patocka 0 siblings, 0 replies; 16+ messages in thread From: Mikulas Patocka @ 2026-11-11 22:48 UTC (permalink / raw) To: 周伟江 (Weijiang Zhou) Cc: dm-devel@lists.linux.dev, Alasdair Kergon, Mike Snitzer, Benjamin Marzinski, Sami Tolvanen, 金红宇 (Hongyu Jin), 吴祥禄 (Xianglu Wu), 吴周镜 (Justin Wu), dhavale@google.com, ebiggers@google.com [-- Attachment #1: Type: text/plain, Size: 4937 bytes --] On Wed, 11 Nov 2026, 周伟江 (Weijiang Zhou) wrote: > Hi Mikulas, > > thanks for the review, and sorry about the TABs. They were not lost while > composing: the message left my client intact, and the rich-text path of our > corporate mail setup re-encoded the text part on the way out, dropped every > TAB and reflowed the long lines. > > I have moved to a submission path that hands the MIME to the server byte for > byte, and checked the round trip through a mailbox first. The patch below is > the same patch, unchanged - no code was touched since your review, only the > whitespace is back. > > Thanks, > Weijiang Hi This email has deleted TABs too. I applied the patch manually, no need to resend it. Mikulas > 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> > --- > 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. > 本邮件及其附件具有保密性质,受法律保护不得泄露,仅发送给本邮件所指特定收件人。严禁非经授权使用、宣传、发布或复制本邮件或其内容。若非该特定收件人,请勿阅读、复制、 使用或披露本邮件的任何内容。若误收本邮件,请从系统中永久性删除本邮件及所有附件,并以回复邮件的方式即刻告知发件人。无法保证互联网通信及时、安全、无误或防毒。发件人对任何错漏均不承担责任。 > ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [RFC PATCH 2/2] dm-verity: don't restart or panic on errors during system shutdown 2026-11-10 13:06 ` [RFC PATCH 2/2] dm-verity: don't restart or panic on errors during system shutdown 周伟江 (Weijiang Zhou) 2026-11-10 21:13 ` Mikulas Patocka @ 2026-11-13 5:55 ` Eric Biggers 2026-11-13 7:40 ` 回复: " 周伟江 (Weijiang Zhou) 1 sibling, 1 reply; 16+ messages in thread From: Eric Biggers @ 2026-11-13 5:55 UTC (permalink / raw) To: 周伟江 (Weijiang Zhou) Cc: dm-devel@lists.linux.dev, Alasdair Kergon, Mike Snitzer, Mikulas Patocka, Benjamin Marzinski, Sami Tolvanen, 金红宇 (Hongyu Jin), 吴祥禄 (Xianglu Wu), 吴周镜 (Justin Wu) On Tue, Nov 10, 2026 at 01:06:21PM +0000, 周伟江 (Weijiang Zhou) wrote: > 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. verity_handle_err() is supposed to be called only on corruption. Just as established by patch 1, there is a bug where an I/O error is unnecessarily escalated to corruption. This patch might still be worthwhile, to be robust against hypothetical storage devices that return successful reads with incorrect data while the system is shutting down. Just the commit message and comments don't really match up with that. >+/* >+ * 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; >+} The above comment is misleading. This patch makes this function be called by verity_handle_err() which is for handling corruption. It also occurs *during* the verity work. > +/* > + * 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; Shouldn't this go earlier in the function? By the time we get here, verity_handle_err() has already recorded the corruption in struct dm_verity (where DM_TABLE_STATUS can read it) and sent a uevent to userspace notifying them of the corruption. That isn't very consistent with the idea that if verity_is_system_shutting_down() then corruption is not reliable and should not be reported. Side note: as Mikulas mentioned, your patches were also corrupted and do not apply. You also should not include email footers telling people to delete your emails, as they may do what you ask. - Eric ^ permalink raw reply [flat|nested] 16+ messages in thread
* 回复: [RFC PATCH 2/2] dm-verity: don't restart or panic on errors during system shutdown 2026-11-13 5:55 ` Eric Biggers @ 2026-11-13 7:40 ` 周伟江 (Weijiang Zhou) 0 siblings, 0 replies; 16+ messages in thread From: 周伟江 (Weijiang Zhou) @ 2026-11-13 7:40 UTC (permalink / raw) To: Eric Biggers, Sami Tolvanen' Cc: dm-devel@lists.linux.dev, Alasdair Kergon, Mike Snitzer, Mikulas Patocka, Benjamin Marzinski, 金红宇 (Hongyu Jin), 吴祥禄 (Xianglu Wu), 吴周镜 (Justin Wu), dhavale@google.com Hi Eric & Sami, Thanks for the reply and for the correction. Our patch was only meant to report what we see on the devices: during a reboot the storage is already gone, a hash block read returns -EIO, and the device ends up restarting with "dm-verity device corrupted". It was indeed a stopgap and did not cover every case. We are worried that further changes from us would introduce new problems, and that is why we came here to ask for help. On 2/2 we agree with you: the comment and the commit message do not match what the code does, which is misleading. Mikulas has applied it by hand, so we will not touch it. If you want a version that applies cleanly, we can send it as an attachment. About the mail format: the footer at the bottom, and the missing whitespace in the patches, both come from our company mail server. It rewrites outbound text and appends that footer, and we cannot turn it off. Patch content will go as an attachment from now on. Thanks to you, Sami and Mikulas for the time on this. The root cause looks clear enough now, so we are not going to push these two patches further. They do not solve the underlying problem. We would rather have a complete fix from you or Sami. We have Android devices that reproduce this and can verify whatever you come up with. Sami, it looks like you and Eric see the fix differently. Could the two of you settle on a final approach together? We would rather follow one direction you both agree on than choose between them ourselves. Thanks, Weijiang Zhou -----邮件原件----- 发件人: Eric Biggers <ebiggers@kernel.org> 发送时间: 2026年11月13日 13:55 收件人: 周伟江 (Weijiang Zhou) <weijiang.zhou@unisoc.com> 抄送: dm-devel@lists.linux.dev; Alasdair Kergon <agk@redhat.com>; Mike Snitzer <snitzer@kernel.org>; Mikulas Patocka <mpatocka@redhat.com>; Benjamin Marzinski <bmarzins@redhat.com>; Sami Tolvanen <samitolvanen@google.com>; 金红宇 (Hongyu Jin) <hongyu.jin@unisoc.com>; 吴祥禄 (Xianglu Wu) <Xianglu.Wu@unisoc.com>; 吴周镜 (Justin Wu) <Justin.Wu@unisoc.com> 主题: Re: [RFC PATCH 2/2] dm-verity: don't restart or panic on errors during system shutdown 注意: 这封邮件来自于外部。除非你确定邮件内容安全,否则不要点击任何链接和附件。 CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe. On Tue, Nov 10, 2026 at 01:06:21PM +0000, 周伟江 (Weijiang Zhou) wrote: > 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. verity_handle_err() is supposed to be called only on corruption. Just as established by patch 1, there is a bug where an I/O error is unnecessarily escalated to corruption. This patch might still be worthwhile, to be robust against hypothetical storage devices that return successful reads with incorrect data while the system is shutting down. Just the commit message and comments don't really match up with that. >+/* >+ * 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; >+} The above comment is misleading. This patch makes this function be called by verity_handle_err() which is for handling corruption. It also occurs *during* the verity work. > +/* > + * 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; Shouldn't this go earlier in the function? By the time we get here, verity_handle_err() has already recorded the corruption in struct dm_verity (where DM_TABLE_STATUS can read it) and sent a uevent to userspace notifying them of the corruption. That isn't very consistent with the idea that if verity_is_system_shutting_down() then corruption is not reliable and should not be reported. Side note: as Mikulas mentioned, your patches were also corrupted and do not apply. You also should not include email footers telling people to delete your emails, as they may do what you ask. - Eric ________________________________ 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. 本邮件及其附件具有保密性质,受法律保护不得泄露,仅发送给本邮件所指特定收件人。严禁非经授权使用、宣传、发布或复制本邮件或其内容。若非该特定收件人,请勿阅读、复制、 使用或披露本邮件的任何内容。若误收本邮件,请从系统中永久性删除本邮件及所有附件,并以回复邮件的方式即刻告知发件人。无法保证互联网通信及时、安全、无误或防毒。发件人对任何错漏均不承担责任。 ^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2026-12-02 19:04 UTC | newest] Thread overview: 16+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-10 13:06 [RFC PATCH 0/2] dm-verity: don't let FEC decode into a dm_bufio page that is already in the cache 周伟江 (Weijiang Zhou) 2026-11-10 13:06 ` [RFC PATCH 1/2] dm-verity: don't decode FEC " 周伟江 (Weijiang Zhou) 2026-11-10 21:08 ` Mikulas Patocka 2026-11-11 3:14 ` 周伟江 (Weijiang Zhou) 2026-11-11 23:33 ` Mikulas Patocka 2026-11-12 0:38 ` Sami Tolvanen 2026-11-13 5:36 ` Eric Biggers 2026-11-19 13:22 ` 周伟江 (Weijiang Zhou) 2026-12-02 13:05 ` 周伟江 (Weijiang Zhou) 2026-12-02 19:04 ` Eric Biggers 2026-11-10 13:06 ` [RFC PATCH 2/2] dm-verity: don't restart or panic on errors during system shutdown 周伟江 (Weijiang Zhou) 2026-11-10 21:13 ` Mikulas Patocka 2026-11-11 3:14 ` 周伟江 (Weijiang Zhou) 2026-11-11 22:48 ` Mikulas Patocka 2026-11-13 5:55 ` Eric Biggers 2026-11-13 7:40 ` 回复: " 周伟江 (Weijiang Zhou)
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.