From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Brian Foster <bfoster@redhat.com>
Cc: xfs <linux-xfs@vger.kernel.org>
Subject: Re: [PATCH] xfs: harden directory integrity checks some more
Date: Tue, 9 Jan 2018 10:25:42 -0800 [thread overview]
Message-ID: <20180109182542.GE5602@magnolia> (raw)
In-Reply-To: <20180109160915.GB888@bfoster.bfoster>
On Tue, Jan 09, 2018 at 11:09:16AM -0500, Brian Foster wrote:
> On Mon, Jan 08, 2018 at 11:13:36PM -0800, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> >
> > If a malicious filesystem image contains a block+ format directory
> > wherein the directory inode's core.mode is set such that
> > S_ISDIR(core.mode) == 0, and if there are subdirectories of the
> > corrupted directory, an attempt to traverse up the directory tree will
> > crash the kernel in __xfs_dir3_data_check. Running the online scrub's
> > parent checks will tend to do this.
> >
> > The crash occurs because the directory inode's d_ops get set to
> > xfs_dir[23]_nondir_ops (it's not a directory) but the parent pointer
> > scrubber's indiscriminate call to xfs_readdir proceeds past the ASSERT
> > if we have non fatal asserts configured.
> >
> > Fix the null pointer dereference crash in __xfs_dir3_data_check by
> > looking for S_ISDIR or NULL data_entry_p; and teach the parent scrubber
> > to bail out if it is fed a non-directory "parent".
> >
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> > fs/xfs/libxfs/xfs_dir2_data.c | 7 +++++++
> > fs/xfs/scrub/parent.c | 2 +-
> > 2 files changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/fs/xfs/libxfs/xfs_dir2_data.c b/fs/xfs/libxfs/xfs_dir2_data.c
> > index 3237812..31d5ec6 100644
> > --- a/fs/xfs/libxfs/xfs_dir2_data.c
> > +++ b/fs/xfs/libxfs/xfs_dir2_data.c
> > @@ -73,6 +73,13 @@ __xfs_dir3_data_check(
> > */
> > ops = xfs_dir_get_ops(mp, dp);
> >
> > + /*
> > + * If this isn't a directory, or we got handed the non-dir ops,
> > + * something is seriously wrong. Bail out.
> > + */
> > + if ((dp && !S_ISDIR(VFS_I(dp)->i_mode)) || !ops->data_entry_p)
> > + return __this_address;
> > +
>
> I wonder if something like (ops == xfs_nondir_get_ops(mp, NULL)) would
> be a bit more explicit for the second part of this check..? Otherwise
> seems Ok to me.
Sure, though I prefer (ops != xfs_dir_get_ops(mp, NULL)) for defensive
reasons.
--D
>
> Brian
>
> > hdr = bp->b_addr;
> > p = (char *)ops->data_entry_p(hdr);
> >
> > diff --git a/fs/xfs/scrub/parent.c b/fs/xfs/scrub/parent.c
> > index dd704fd..0d38514 100644
> > --- a/fs/xfs/scrub/parent.c
> > +++ b/fs/xfs/scrub/parent.c
> > @@ -171,7 +171,7 @@ xfs_scrub_parent_validate(
> > error = xfs_iget(mp, sc->tp, dnum, 0, 0, &dp);
> > if (!xfs_scrub_fblock_xref_process_error(sc, XFS_DATA_FORK, 0, &error))
> > goto out;
> > - if (dp == sc->ip) {
> > + if (dp == sc->ip || !S_ISDIR(VFS_I(dp)->i_mode)) {
> > xfs_scrub_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);
> > goto out_rele;
> > }
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2018-01-09 18:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-09 7:13 [PATCH] xfs: harden directory integrity checks some more Darrick J. Wong
2018-01-09 16:09 ` Brian Foster
2018-01-09 18:25 ` Darrick J. Wong [this message]
2018-01-09 18:47 ` [PATCH v2] " Darrick J. Wong
2018-01-09 18:56 ` Brian Foster
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=20180109182542.GE5602@magnolia \
--to=darrick.wong@oracle.com \
--cc=bfoster@redhat.com \
--cc=linux-xfs@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