linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Eric Sandeen <sandeen@redhat.com>
Cc: xfs <linux-xfs@vger.kernel.org>
Subject: [PATCH] libxfs: fix crash on second attempt to initialize library
Date: Tue, 5 Oct 2021 15:32:52 -0700	[thread overview]
Message-ID: <20211005223252.GF24307@magnolia> (raw)

From: Darrick J. Wong <djwong@kernel.org>

xfs_repair crashes when it tries to initialize the libxfs library but
the initialization fails because the fs is already mounted:

# xfs_repair /dev/sdd
xfs_repair: /dev/sdd contains a mounted filesystem
xfs_repair: urcu.c:553: urcu_memb_register_thread: Assertion `!URCU_TLS(rcu_reader).registered' failed.
Aborted

This is because libxfs_init() registers the main thread with liburcu,
but doesn't unregister the thread if libxfs library initialization
fails.  When repair sets more dangerous options and tries again, the
second initialization attempt causes liburcu to abort.  Fix this by
unregistering the thread with liburcu if libxfs initialization fails.

Observed by running xfs/284.

Fixes: e4da1b16 ("xfsprogs: introduce liburcu support")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 libxfs/init.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libxfs/init.c b/libxfs/init.c
index d0753ce5..14911596 100644
--- a/libxfs/init.c
+++ b/libxfs/init.c
@@ -407,8 +407,10 @@ libxfs_init(libxfs_init_t *a)
 		unlink(rtpath);
 	if (fd >= 0)
 		close(fd);
-	if (!rval)
+	if (!rval) {
 		libxfs_close_devices(a);
+		rcu_unregister_thread();
+	}
 
 	return rval;
 }

             reply	other threads:[~2021-10-05 22:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-05 22:32 Darrick J. Wong [this message]
2021-10-15 20:29 ` [PATCH] libxfs: fix crash on second attempt to initialize library Eric Sandeen

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=20211005223252.GF24307@magnolia \
    --to=djwong@kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@redhat.com \
    /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).