From: "Darrick J. Wong" <djwong@kernel.org>
To: Christoph Hellwig <hch@infradead.org>
Cc: cem@kernel.org, stable@vger.kernel.org, linux-xfs@vger.kernel.org
Subject: Re: [PATCH 02/12] xfs: improve dirent bounds checking in scrub and repair
Date: Mon, 28 Sep 2026 21:12:22 -0700 [thread overview]
Message-ID: <20260929041222.GR2705364@frogsfrogsfrogs> (raw)
In-Reply-To: <aroLMeT0OiY37AnN@infradead.org>
On Sun, Sep 27, 2026 at 11:37:37PM -0700, Christoph Hellwig wrote:
> On Sun, Sep 27, 2026 at 11:16:20PM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@kernel.org>
> >
> > LOLLM complains that we don't do enough bounds checking of the directory
> > entries in directory blocks when we're looking for errors or trying to
> > salvage entries. Let's improve that with more detailed checks.
> >
> > Cc: <stable@vger.kernel.org> # v4.16
> > Fixes: ce92d29ddf9908 ("xfs: directory scrubber must walk through data block to offset")
> > Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
> > Assisted-by: LOLLM # finding obvious bugs
> > ---
> > fs/xfs/scrub/dir.c | 56 +++++++++++++++++++++++++++++++++++++++++----
> > fs/xfs/scrub/dir_repair.c | 30 +++++++++++++++++++++++-
> > 2 files changed, 79 insertions(+), 7 deletions(-)
> >
> >
> > diff --git a/fs/xfs/scrub/dir.c b/fs/xfs/scrub/dir.c
> > index a63eebf39fd496..dd21570378b281 100644
> > --- a/fs/xfs/scrub/dir.c
> > +++ b/fs/xfs/scrub/dir.c
> > @@ -340,6 +340,7 @@ xchk_dir_rec(
> > xfs_dahash_t hash;
> > struct xfs_dir3_icleaf_hdr hdr;
> > unsigned int tag;
> > + bool foundit = false;
> > int error;
> >
> > ASSERT(blk->magic == XFS_DIR2_LEAF1_MAGIC ||
> > @@ -390,22 +391,60 @@ xchk_dir_rec(
> > xchk_fblock_set_corrupt(ds->sc, XFS_DATA_FORK, rec_bno);
> > goto out_relse;
> > }
> > - for (;;) {
> > + while (iter_off < end) {
>
> Nit: maybe move the iter_off initialization just above this for
> clarify?
Ok.
> > struct xfs_dir2_data_entry *dep = bp->b_addr + iter_off;
> > struct xfs_dir2_data_unused *dup = bp->b_addr + iter_off;
> > + unsigned int advance;
> >
> > - if (iter_off >= end) {
> > + /* must have freetag */
> > + if (iter_off + offsetof(struct xfs_dir2_data_unused, length) >= end) {
>
> Overly long line.
Will fix these.
/* must have freetag */
advance = offsetof(struct xfs_dir2_data_unused, length);
if (offset + advance >= end)
break;
> In general it feels like the inner body would benefit from being
> split into a helper for readability given how big it becomes.
I really wish C had a way to make it so that you could hoist just the
*dirent walking code* whilst retaining the custom bits of functionality
(each error handling, and finding dirents). I don't know of a good way
to do that in C that doesn't involve cpp.
> That would also ease deduplicating the xchk_fblock_set_corrupt calls.
I prefer to keep those separate because xchk_*_set_corrupt contains a
tracepoint that captures the callsite, so you can use gdb or other tools
to go find the exact line in the source code that set the corruption
flag.
Originally I had a fugly macro that wrapped the exact metadata check so
that we could stringify it and record that directly in the tracepoint
buffer but enough people complained that I morphed it into what's there
now.
--D
next prev parent reply other threads:[~2026-09-29 4:12 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 6:15 [PATCHSET] xfs: LLM-inspired bug fixes, part 19 Darrick J. Wong
2026-09-28 6:16 ` [PATCH 01/12] xfs: be extra careful about replacement directory construction Darrick J. Wong
2026-09-28 6:34 ` Christoph Hellwig
2026-09-29 3:59 ` Darrick J. Wong
2026-09-28 6:16 ` [PATCH 02/12] xfs: improve dirent bounds checking in scrub and repair Darrick J. Wong
2026-09-28 6:37 ` Christoph Hellwig
2026-09-29 4:12 ` Darrick J. Wong [this message]
2026-09-28 6:16 ` [PATCH 03/12] xfs: abort dirtree repair if the live update hook dies Darrick J. Wong
2026-09-28 6:38 ` Christoph Hellwig
2026-09-28 6:16 ` [PATCH 04/12] xfs: bail out of directory tree repairs on error Darrick J. Wong
2026-09-28 8:07 ` Christoph Hellwig
2026-09-28 6:17 ` [PATCH 05/12] xfs: fix revalidation of xchk_dquot_iter cached mappings Darrick J. Wong
2026-09-28 8:08 ` Christoph Hellwig
2026-09-28 6:17 ` [PATCH 06/12] xfs: don't repair fs summary counters with garbage Darrick J. Wong
2026-09-28 8:08 ` Christoph Hellwig
2026-09-28 6:17 ` [PATCH 07/12] xfs: allow softlimit with no hardlimit in quota scrub Darrick J. Wong
2026-09-28 8:08 ` Christoph Hellwig
2026-09-28 6:17 ` [PATCH 08/12] xfs: assign an owner to scrub_stats_fops Darrick J. Wong
2026-09-28 8:09 ` Christoph Hellwig
2026-09-28 6:18 ` [PATCH 09/12] xfs: fix lost errno returned from xfarray_foliosort Darrick J. Wong
2026-09-28 8:09 ` Christoph Hellwig
2026-09-28 6:18 ` [PATCH 10/12] xfs: fix skipped inode mask handling in iscan Darrick J. Wong
2026-09-28 8:10 ` Christoph Hellwig
2026-09-28 6:18 ` [PATCH 11/12] xfs: don't proceed with xattr repair if the live update fails Darrick J. Wong
2026-09-28 8:10 ` Christoph Hellwig
2026-09-28 6:18 ` [PATCH 12/12] xfs: don't fix the directory tree if " Darrick J. Wong
2026-09-28 8:10 ` Christoph Hellwig
2026-10-08 13:32 ` [PATCHSET] xfs: LLM-inspired bug fixes, part 19 Carlos Maiolino
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260929041222.GR2705364@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=cem@kernel.org \
--cc=hch@infradead.org \
--cc=linux-xfs@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox