From: "Darrick J. Wong" <djwong@kernel.org>
To: djwong@kernel.org
Cc: linux-xfs@vger.kernel.org, hch@lst.de, dchinner@redhat.com,
christian.brauner@ubuntu.com
Subject: [PATCH 2/3] xfs: avoid buffer deadlocks in inumbers/bulkstat
Date: Tue, 02 Mar 2021 14:28:28 -0800 [thread overview]
Message-ID: <161472410813.3421449.1691962515820573818.stgit@magnolia> (raw)
In-Reply-To: <161472409643.3421449.2100229515469727212.stgit@magnolia>
From: Darrick J. Wong <djwong@kernel.org>
When we're servicing an INUMBERS or BULKSTAT request, grab an empty
transaction so that we don't hit an ABBA buffer deadlock if the inode
btree contains a cycle.
Found by fuzzing an inode btree pointer to introduce a cycle into the
tree (xfs/365).
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
fs/xfs/xfs_itable.c | 46 ++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 42 insertions(+), 4 deletions(-)
diff --git a/fs/xfs/xfs_itable.c b/fs/xfs/xfs_itable.c
index ca310a125d1e..2339a1874efa 100644
--- a/fs/xfs/xfs_itable.c
+++ b/fs/xfs/xfs_itable.c
@@ -19,6 +19,7 @@
#include "xfs_error.h"
#include "xfs_icache.h"
#include "xfs_health.h"
+#include "xfs_trans.h"
/*
* Bulk Stat
@@ -166,6 +167,7 @@ xfs_bulkstat_one(
.formatter = formatter,
.breq = breq,
};
+ struct xfs_trans *tp;
int error;
ASSERT(breq->icount == 1);
@@ -175,9 +177,20 @@ xfs_bulkstat_one(
if (!bc.buf)
return -ENOMEM;
+ /*
+ * Grab freeze protection and allocate an empty transaction so that
+ * we avoid deadlocking if the inobt is corrupt.
+ */
+ sb_start_write(breq->mp->m_super);
+ error = xfs_trans_alloc_empty(breq->mp, &tp);
+ if (error)
+ goto out;
+
error = xfs_bulkstat_one_int(breq->mp, breq->mnt_userns, NULL,
breq->startino, &bc);
-
+ xfs_trans_cancel(tp);
+out:
+ sb_end_write(breq->mp->m_super);
kmem_free(bc.buf);
/*
@@ -241,6 +254,7 @@ xfs_bulkstat(
.formatter = formatter,
.breq = breq,
};
+ struct xfs_trans *tp;
int error;
if (breq->mnt_userns != &init_user_ns) {
@@ -256,9 +270,20 @@ xfs_bulkstat(
if (!bc.buf)
return -ENOMEM;
- error = xfs_iwalk(breq->mp, NULL, breq->startino, breq->flags,
+ /*
+ * Grab freeze protection and allocate an empty transaction so that
+ * we avoid deadlocking if the inobt is corrupt.
+ */
+ sb_start_write(breq->mp->m_super);
+ error = xfs_trans_alloc_empty(breq->mp, &tp);
+ if (error)
+ goto out;
+
+ error = xfs_iwalk(breq->mp, tp, breq->startino, breq->flags,
xfs_bulkstat_iwalk, breq->icount, &bc);
-
+ xfs_trans_cancel(tp);
+out:
+ sb_end_write(breq->mp->m_super);
kmem_free(bc.buf);
/*
@@ -371,13 +396,26 @@ xfs_inumbers(
.formatter = formatter,
.breq = breq,
};
+ struct xfs_trans *tp;
int error = 0;
if (xfs_bulkstat_already_done(breq->mp, breq->startino))
return 0;
- error = xfs_inobt_walk(breq->mp, NULL, breq->startino, breq->flags,
+ /*
+ * Grab freeze protection and allocate an empty transaction so that
+ * we avoid deadlocking if the inobt is corrupt.
+ */
+ sb_start_write(breq->mp->m_super);
+ error = xfs_trans_alloc_empty(breq->mp, &tp);
+ if (error)
+ goto out;
+
+ error = xfs_inobt_walk(breq->mp, tp, breq->startino, breq->flags,
xfs_inumbers_walk, breq->icount, &ic);
+ xfs_trans_cancel(tp);
+out:
+ sb_end_write(breq->mp->m_super);
/*
* We found some inode groups, so clear the error status and return
next prev parent reply other threads:[~2021-03-03 3:19 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-02 22:28 [PATCHSET 0/3] xfs: small fixes for 5.12 Darrick J. Wong
2021-03-02 22:28 ` [PATCH 1/3] xfs: fix quota accounting when a mount is idmapped Darrick J. Wong
2021-03-03 6:43 ` Christoph Hellwig
2021-03-03 14:44 ` Christian Brauner
2021-03-03 18:33 ` Darrick J. Wong
2021-03-03 19:09 ` Christian Brauner
2021-03-02 22:28 ` Darrick J. Wong [this message]
2021-03-03 6:45 ` [PATCH 2/3] xfs: avoid buffer deadlocks in inumbers/bulkstat Christoph Hellwig
2021-03-03 18:57 ` Darrick J. Wong
2021-03-02 22:28 ` [PATCH 3/3] xfs: force log and push AIL to clear pinned inodes when aborting mount Darrick J. Wong
2021-03-03 6:48 ` Christoph Hellwig
2021-03-03 19:02 ` Darrick J. Wong
2021-03-02 23:07 ` [PATCHSET 0/3] xfs: small fixes for 5.12 Christian Brauner
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=161472410813.3421449.1691962515820573818.stgit@magnolia \
--to=djwong@kernel.org \
--cc=christian.brauner@ubuntu.com \
--cc=dchinner@redhat.com \
--cc=hch@lst.de \
--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;
as well as URLs for NNTP newsgroup(s).