Skip to contentSkip to conversation

xfs: initialize first bad log block in head verification

PATCH In review Yousef Alhouseen 2 participants 3 messages Jun 28 – Jun 30

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: initialize first bad log block in head verification

xlog_do_recovery_pass() only writes first_bad when it reaches the common error exit after processing a log record. An earlier CRC or corruption failure can therefore return without initializing the out-parameter.

xlog_verify_head() tests first_bad on those errors and may then use its uninitialized stack value as a log block number while searching for the last good record. Initialize it to zero, matching xlog_verify_tail(), so an error without a recorded bad block is returned directly.

Fixes 7088c4136fa1 ("xfs: detect and trim torn writes during log recovery")
Reported-by [email protected]
---
 fs/xfs/xfs_log_recover.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_log_recover.c +1 -1
index 09e6678ca487..d8125f3add4b 100644
@@ -1028,7 +1028,7 @@ xlog_verify_head(
 {
 	struct xlog_rec_header	*tmp_rhead;
 	char			*tmp_buffer;
-	xfs_daddr_t		first_bad;
+	xfs_daddr_t		first_bad = 0;
 	xfs_daddr_t		tmp_rhead_blk;
 	int			found;
 	int			error;
Signature · 1 line
2.54.0
#1 lore raw
Quoted 23 lines · Yousef Alhouseen

xlog_do_recovery_pass() only writes first_bad when it reaches the common error exit after processing a log record. An earlier CRC or corruption failure can therefore return without initializing the out-parameter.

xlog_verify_head() tests first_bad on those errors and may then use its uninitialized stack value as a log block number while searching for the last good record. Initialize it to zero, matching xlog_verify_tail(), so an error without a recorded bad block is returned directly.

Fixes 7088c4136fa1 ("xfs: detect and trim torn writes during log recovery")
Reported-by [email protected]
---
 fs/xfs/xfs_log_recover.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_log_recover.c +0 -0
index 09e6678ca487..d8125f3add4b 100644

fs/xfs/xfs_log_recover.c xlog_verify_head( · line 1031

Quoted 5 lines
fs/xfs/xfs_log_recover.c +1 -1
@@ -1028,7 +1028,7 @@ xlog_verify_head(
 {
 	struct xlog_rec_header	*tmp_rhead;
 	char			*tmp_buffer;
-	xfs_daddr_t		first_bad;
+	xfs_daddr_t		first_bad = 0;

Why is it safe to set this to the first daddr of the log? Is it possible that a filesystem could have a log record starting near the end of the log which wrapped around, and later suffered a CRC corruption in daddr 0?

xfs_daddr_t already defines an explicit null value (XFS_BUF_DADDR_NULL); wouldn't it be /much/ safer to set that here and update the if test body later?

--D

Quoted 7 lines
fs/xfs/xfs_log_recover.c +0 -0
 	xfs_daddr_t		tmp_rhead_blk;
 	int			found;
 	int			error;
Signature · 1 line
2.54.0
#2 lore raw

Agreed. Log block zero is valid, so using it as the sentinel is unsafe for exactly that wrapped-log case.

I'll send v2 initializing first_bad to XFS_BUF_DADDR_NULL and checking explicitly against that sentinel before entering the torn-write recovery path.

Thanks,
Yousef

Quoted 48 lines · Darrick J. Wong
Quoted 23 lines · Yousef Alhouseen

xlog_do_recovery_pass() only writes first_bad when it reaches the common error exit after processing a log record. An earlier CRC or corruption failure can therefore return without initializing the out-parameter.

xlog_verify_head() tests first_bad on those errors and may then use its uninitialized stack value as a log block number while searching for the last good record. Initialize it to zero, matching xlog_verify_tail(), so an error without a recorded bad block is returned directly.

Fixes 7088c4136fa1 ("xfs: detect and trim torn writes during log recovery")
Reported-by [email protected]

---
fs/xfs/xfs_log_recover.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_log_recover.c +0 -0
index 09e6678ca487..d8125f3add4b 100644

fs/xfs/xfs_log_recover.c xlog_verify_head( · line 1031

Quoted 5 lines
fs/xfs/xfs_log_recover.c +1 -1
@@ -1028,7 +1028,7 @@ xlog_verify_head(
 {
 struct xlog_rec_header *tmp_rhead;
 char *tmp_buffer;
- xfs_daddr_t first_bad;
+ xfs_daddr_t first_bad = 0;

Why is it safe to set this to the first daddr of the log? Is it possible that a filesystem could have a log record starting near the end of the log which wrapped around, and later suffered a CRC corruption in daddr 0?

xfs_daddr_t already defines an explicit null value (XFS_BUF_DADDR_NULL); wouldn't it be /much/ safer to set that here and update the if test body later?

--D

Quoted 7 lines
fs/xfs/xfs_log_recover.c +0 -1
 xfs_daddr_t tmp_rhead_blk;
 int found;
 int error;
--

2.54.0