public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs_db: make sure agblocks is valid to prevent corruption
@ 2024-08-21 10:44 liuhuan01
  2024-08-23  0:49 ` Darrick J. Wong
  0 siblings, 1 reply; 10+ messages in thread
From: liuhuan01 @ 2024-08-21 10:44 UTC (permalink / raw)
  To: linux-xfs; +Cc: djwong, cmaiolino, liuh

From: liuh <liuhuan01@kylinos.cn>

Recently, I was testing xfstests. When I run xfs/350 case, it always generate coredump during the process.
	xfs_db -c "sb 0" -c "p agblocks" /dev/loop1

System will generate signal SIGFPE corrupt the process. And the stack as follow:
corrupt at: (*bpp)->b_pag = xfs_perag_get(btp->bt_mount, xfs_daddr_to_agno(btp->bt_mount, blkno)); in function libxfs_getbuf_flags
	#0  libxfs_getbuf_flags
	#1  libxfs_getbuf_flags
	#2  libxfs_buf_read_map
	#3  libxfs_buf_read
	#4  libxfs_mount
	#5  init
	#6  main

The coredump was caused by the corrupt superblock metadata: (mp)->m_sb.sb_agblocks, it was 0.
In this case, user cannot run in expert mode also.

Never check (mp)->m_sb.sb_agblocks before use it cause this issue.
Make sure (mp)->m_sb.sb_agblocks > 0 before libxfs_mount to prevent corruption and leave a message.

Signed-off-by: liuh <liuhuan01@kylinos.cn>
---
 db/init.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/db/init.c b/db/init.c
index cea25ae5..2d3295ba 100644
--- a/db/init.c
+++ b/db/init.c
@@ -129,6 +129,13 @@ init(
 		}
 	}
 
+	if (unlikely(sbp->sb_agblocks == 0)) {
+		fprintf(stderr,
+			_("%s: device %s agblocks unexpected\n"),
+			progname, x.data.name);
+		exit(1);
+	}
+
 	agcount = sbp->sb_agcount;
 	mp = libxfs_mount(&xmount, sbp, &x, LIBXFS_MOUNT_DEBUGGER);
 	if (!mp) {
-- 
2.43.0


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

end of thread, other threads:[~2024-09-16  6:55 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-21 10:44 [PATCH] xfs_db: make sure agblocks is valid to prevent corruption liuhuan01
2024-08-23  0:49 ` Darrick J. Wong
2024-08-27  3:23   ` Dave Chinner
2024-08-27 10:24     ` liuh
2024-08-27 23:37       ` Dave Chinner
2024-09-02 10:12         ` [PATCH v2] " liuhuan01
2024-09-02 18:56           ` Darrick J. Wong
2024-09-03  2:28           ` Dave Chinner
2024-09-03 10:24             ` [PATCH v3] " liuhuan01
2024-09-16  6:55               ` Carlos Maiolino

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