Re: [PATCH] xfs: reject log records with v2 size but v1 header version to avoid OOB
From: Christoph Hellwig
Date: Thu Nov 13 2025 - 01:55:43 EST
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.