mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] dm-integrity: initialize free_sectors when the superblock changes on resume
@ 2026-11-15 11:53 Aibing Chen
  2026-11-16 15:17 ` Mikulas Patocka
  0 siblings, 1 reply; 2+ messages in thread
From: Aibing Chen @ 2026-11-15 11:53 UTC (permalink / raw)
  To: Alasdair Kergon, Mike Snitzer, Mikulas Patocka, Benjamin Marzinski
  Cc: dm-devel, linux-kernel

fc79aeb86a2c ("dm-integrity: validate the superblock on resume") made
dm_integrity_resume() jump to skip_writes when the on-disk superblock was
modified while the device was suspended.  That path skips
replay_journal(), so the journal accounting variables stay
zero-initialized: free_sectors is 0 while journal_sections and
journal_section_entries are nonzero.

A later suspend or flush queues integrity_commit(), which calls
pad_uncommitted() in journal mode.  Its invariant

  journal_sections * journal_section_entries ==
  (n_uncommitted_sections + n_committed_sections) *
  journal_section_entries + free_sectors

no longer holds because the right-hand side evaluates to 0, and WARN_ON
fires.

Restore free_sectors on that error path, as replay_journal() does for the
normal resume.  The section counters are already zero and nothing will be
committed, since the device is marked failed.

Reported-by: syzbot+94dac3c75477e184f0b0@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=94dac3c75477e184f0b0
Fixes: fc79aeb86a2c ("dm-integrity: validate the superblock on resume")
Cc: stable@vger.kernel.org
Signed-off-by: Aibing Chen <chenaibing@cmss.chinamobile.com>
---
 drivers/md/dm-integrity.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c
index 802b37761..6ab305b60 100644
--- a/drivers/md/dm-integrity.c
+++ b/drivers/md/dm-integrity.c
@@ -3915,6 +3915,13 @@ static void dm_integrity_resume(struct dm_target *ti)
 		memcpy(ic->sb, ic->sb_copy, sizeof(struct superblock));
 		DMERR("The superblock was changed while the device was suspended");
 		dm_integrity_io_error(ic, "superblock check", -EINVAL);
+		/*
+		 * replay_journal() is skipped below, so the journal accounting stays
+		 * zero-initialized and pad_uncommitted() would trigger its WARN_ON.
+		 * Restore the free sector count; the section counters are already zero
+		 * and nothing is committed because the device is marked failed.
+		 */
+		ic->free_sectors = ic->journal_entries;
 		goto skip_writes;
 	}
 



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] dm-integrity: initialize free_sectors when the superblock changes on resume
  2026-11-15 11:53 [PATCH] dm-integrity: initialize free_sectors when the superblock changes on resume Aibing Chen
@ 2026-11-16 15:17 ` Mikulas Patocka
  0 siblings, 0 replies; 2+ messages in thread
From: Mikulas Patocka @ 2026-11-16 15:17 UTC (permalink / raw)
  To: Aibing Chen
  Cc: Alasdair Kergon, Mike Snitzer, Benjamin Marzinski, dm-devel,
	linux-kernel



On Sun, 15 Nov 2026, Aibing Chen wrote:

> fc79aeb86a2c ("dm-integrity: validate the superblock on resume") made
> dm_integrity_resume() jump to skip_writes when the on-disk superblock was
> modified while the device was suspended.  That path skips
> replay_journal(), so the journal accounting variables stay
> zero-initialized: free_sectors is 0 while journal_sections and
> journal_section_entries are nonzero.
> 
> A later suspend or flush queues integrity_commit(), which calls
> pad_uncommitted() in journal mode.  Its invariant
> 
>   journal_sections * journal_section_entries ==
>   (n_uncommitted_sections + n_committed_sections) *
>   journal_section_entries + free_sectors
> 
> no longer holds because the right-hand side evaluates to 0, and WARN_ON
> fires.
> 
> Restore free_sectors on that error path, as replay_journal() does for the
> normal resume.  The section counters are already zero and nothing will be
> committed, since the device is marked failed.
> 
> Reported-by: syzbot+94dac3c75477e184f0b0@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=94dac3c75477e184f0b0
> Fixes: fc79aeb86a2c ("dm-integrity: validate the superblock on resume")
> Cc: stable@vger.kernel.org
> Signed-off-by: Aibing Chen <chenaibing@cmss.chinamobile.com>

Hi

This should be already fixed by the commit 
e5e03918fbec31f0c896f4f43c2bd2aadf35d43d ("dm-integrity: don't attempt to 
commit journal on disabled device")

Mikulas

> ---
>  drivers/md/dm-integrity.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c
> index 802b37761..6ab305b60 100644
> --- a/drivers/md/dm-integrity.c
> +++ b/drivers/md/dm-integrity.c
> @@ -3915,6 +3915,13 @@ static void dm_integrity_resume(struct dm_target *ti)
>  		memcpy(ic->sb, ic->sb_copy, sizeof(struct superblock));
>  		DMERR("The superblock was changed while the device was suspended");
>  		dm_integrity_io_error(ic, "superblock check", -EINVAL);
> +		/*
> +		 * replay_journal() is skipped below, so the journal accounting stays
> +		 * zero-initialized and pad_uncommitted() would trigger its WARN_ON.
> +		 * Restore the free sector count; the section counters are already zero
> +		 * and nothing is committed because the device is marked failed.
> +		 */
> +		ic->free_sectors = ic->journal_entries;
>  		goto skip_writes;
>  	}
>  
> 
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-16 15:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-15 11:53 [PATCH] dm-integrity: initialize free_sectors when the superblock changes on resume Aibing Chen
2026-11-16 15:17 ` Mikulas Patocka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®