fs/xfs/xfs_log_recover.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
In xlog_do_recovery_pass(),
commit 45cf976008dd ("xfs: fix log recovery buffer allocation for the
legacy h_size fixup")
added a fix to take the corrected h_size (from the xfsprogs bug
workaround) into consideration for the log recovery buffer calculation.
Without it, we would still allocate the buffer based on the incorrect
on-disk size.
However, in a scenario similar to 45cf976008dd, syzbot creates a fuzzed
record where xfs_has_logv2() but the xlog_rec_header h_version !=
XLOG_VERSION_2. Meaning, we skip the log recover buffer calculation
fix and allocate the buffer based on the incorrect on-disk size. Hence,
a KASAN: slab-out-of-bounds read in xlog_do_recovery_pass() ->
xlog_recover_process() -> xlog_cksum().
Fix by rejecting the record header for
h_size > XLOG_HEADER_CYCLE_SIZE && !XLOG_VERSION_2
since the larger h_size cannot work for v1 logs, and the log stripe unit
adjustment is only a v2 feature.
Reported-by: syzbot+9f6d080dece587cfdd4c@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=9f6d080dece587cfdd4c
Tested-by: syzbot+9f6d080dece587cfdd4c@syzkaller.appspotmail.com
Fixes: 45cf976008dd ("xfs: fix log recovery buffer allocation for the legacy h_size fixup")
Signed-off-by: Raphael Pinsonneault-Thibeault <rpthibeault@gmail.com>
---
changelog
v1 -> v2:
- reject the mount for h_size > XLOG_HEADER_CYCLE_SIZE && !XLOG_VERSION_2
- update commit subject and message
fs/xfs/xfs_log_recover.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c
index e6ed9e09c027..99a903e01869 100644
--- a/fs/xfs/xfs_log_recover.c
+++ b/fs/xfs/xfs_log_recover.c
@@ -3064,8 +3064,12 @@ xlog_do_recovery_pass(
* still allocate the buffer based on the incorrect on-disk
* size.
*/
- if (h_size > XLOG_HEADER_CYCLE_SIZE &&
- (rhead->h_version & cpu_to_be32(XLOG_VERSION_2))) {
+ if (h_size > XLOG_HEADER_CYCLE_SIZE) {
+ if (!(rhead->h_version & cpu_to_be32(XLOG_VERSION_2))) {
+ error = -EFSCORRUPTED;
+ goto bread_err1;
+ }
+
hblks = DIV_ROUND_UP(h_size, XLOG_HEADER_CYCLE_SIZE);
if (hblks > 1) {
kvfree(hbp);
--
2.43.0
On Wed, Nov 12, 2025 at 01:18:18PM -0500, Raphael Pinsonneault-Thibeault wrote:
> In xlog_do_recovery_pass(),
> commit 45cf976008dd ("xfs: fix log recovery buffer allocation for the
> legacy h_size fixup")
> added a fix to take the corrected h_size (from the xfsprogs bug
> workaround) into consideration for the log recovery buffer calculation.
> Without it, we would still allocate the buffer based on the incorrect
> on-disk size.
>
> However, in a scenario similar to 45cf976008dd, syzbot creates a fuzzed
> record where xfs_has_logv2() but the xlog_rec_header h_version !=
> XLOG_VERSION_2. Meaning, we skip the log recover buffer calculation
> fix and allocate the buffer based on the incorrect on-disk size. Hence,
> a KASAN: slab-out-of-bounds read in xlog_do_recovery_pass() ->
> xlog_recover_process() -> xlog_cksum().
>
> Fix by rejecting the record header for
> h_size > XLOG_HEADER_CYCLE_SIZE && !XLOG_VERSION_2
> since the larger h_size cannot work for v1 logs, and the log stripe unit
> adjustment is only a v2 feature.
>
> Reported-by: syzbot+9f6d080dece587cfdd4c@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=9f6d080dece587cfdd4c
> Tested-by: syzbot+9f6d080dece587cfdd4c@syzkaller.appspotmail.com
> Fixes: 45cf976008dd ("xfs: fix log recovery buffer allocation for the legacy h_size fixup")
> Signed-off-by: Raphael Pinsonneault-Thibeault <rpthibeault@gmail.com>
> ---
> changelog
> v1 -> v2:
> - reject the mount for h_size > XLOG_HEADER_CYCLE_SIZE && !XLOG_VERSION_2
> - update commit subject and message
>
> fs/xfs/xfs_log_recover.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c
> index e6ed9e09c027..99a903e01869 100644
> --- a/fs/xfs/xfs_log_recover.c
> +++ b/fs/xfs/xfs_log_recover.c
> @@ -3064,8 +3064,12 @@ xlog_do_recovery_pass(
> * still allocate the buffer based on the incorrect on-disk
> * size.
> */
> - if (h_size > XLOG_HEADER_CYCLE_SIZE &&
> - (rhead->h_version & cpu_to_be32(XLOG_VERSION_2))) {
Just out of curiosity, why is this a bit flag test? Did XFS ever emit a
log record with both XLOG_VERSION_2 *and* XLOG_VERSION_1 set? The code
that writes new log records only sets h_version to 1 or 2, not 3.
(I can't tell if this is a hysterical raisins compatibility thing, or
just bugs)
--D
> + if (h_size > XLOG_HEADER_CYCLE_SIZE) {
> + if (!(rhead->h_version & cpu_to_be32(XLOG_VERSION_2))) {
> + error = -EFSCORRUPTED;
> + goto bread_err1;
> + }
> +
> hblks = DIV_ROUND_UP(h_size, XLOG_HEADER_CYCLE_SIZE);
> if (hblks > 1) {
> kvfree(hbp);
> --
> 2.43.0
>
>
On Wed, Nov 12, 2025 at 10:45:04AM -0800, Darrick J. Wong wrote:
> > @@ -3064,8 +3064,12 @@ xlog_do_recovery_pass(
> > * still allocate the buffer based on the incorrect on-disk
> > * size.
> > */
> > - if (h_size > XLOG_HEADER_CYCLE_SIZE &&
> > - (rhead->h_version & cpu_to_be32(XLOG_VERSION_2))) {
>
> Just out of curiosity, why is this a bit flag test? Did XFS ever emit a
> log record with both XLOG_VERSION_2 *and* XLOG_VERSION_1 set? The code
> that writes new log records only sets h_version to 1 or 2, not 3.
Yeah. This particular instance got added by me, but it is a copy and
paste from xlog_logrec_hblks, which again consolidate multiple chunks
of this style of code, which were moved around a few times.
I think originally this came from Nathan fixing this:
- if ((h_version && XLOG_VERSION_2) &&
+
+ if ((h_version & XLOG_VERSION_2) &&
or in other words, this was a mess all the way back.
© 2016 - 2026 Red Hat, Inc.