]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commit
libxfs: fix call_rcu crash when unmounting the fake mount in mkfs
authorDarrick J. Wong <djwong@kernel.org>
Thu, 14 Oct 2021 16:35:43 +0000 (12:35 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Thu, 14 Oct 2021 16:35:43 +0000 (12:35 -0400)
commit7bf9cd9d3689a5a7f09d6b59ff1d05de4e22c1cf
tree023f39bab4420bd5c88b99825baa774a2c46f0b9
parent7c432f77bafa34b1c67371d78a67ac50a8a97e03
libxfs: fix call_rcu crash when unmounting the fake mount in mkfs

In commit a6fb6abe, we simplified the process by which mkfs.xfs computes
the minimum log size calculation by creating a dummy xfs_mount with the
draft superblock image, using the dummy to compute the log geometry, and
then unmounting the dummy.

Note that creating a dummy mount with no data device is supported by
libxfs, though with the caveat that we don't set up any perag structures
at all.  Up until this point this has worked perfectly well since free()
(and hence kmem_free()) are perfectly happy to ignore NULL pointers.

Unfortunately, this will cause problems with the upcoming patch to shift
per-AG setup and teardown to libxfs because call_rcu in the liburcu
library actually tries to access the rcu_head of the passed-in perag
structure, but they're all NULL in the dummy mount case.  IOWs,
xfs_free_perag requires that every AG have a per-AG structure, and it's
too late to change the 5.14 kernel libxfs now, so work around this by
altering libxfs_mount to remember when it has initialized the perag
structures and libxfs_umount to skip freeing them when the flag isn't
set.

Just to be clear: This fault has no user-visible consequences right now;
it's a fixup to avoid problems in the libxfs sync series for 5.14.

Fixes: a6fb6abe ("mkfs: simplify minimum log size calculation")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
include/xfs_mount.h
libxfs/init.c