Linux XFS filesystem development
 help / color / mirror / Atom feed
* [PATCHSET 4/4] xfs_healer: codex-inspired bug fixes, part 3
@ 2026-06-30  1:02 Darrick J. Wong
  2026-06-30  1:04 ` [PATCH 1/1] xfs_healer: fix getmntent race in weakhandle Darrick J. Wong
  0 siblings, 1 reply; 3+ messages in thread
From: Darrick J. Wong @ 2026-06-30  1:02 UTC (permalink / raw)
  To: aalbersh, djwong; +Cc: linux-xfs, linux-xfs, hch

Hi all,

Here's a third batch of xfs_healer fixes resulting from Codex reviews.
I'm done now.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

With a bit of luck, this should all go splendidly.
Comments and questions are, as always, welcome.

--D

xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=healer-codex-fixes3
---
Commits in this patchset:
 * xfs_healer: fix getmntent race in weakhandle
---
 healer/weakhandle.c |   15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/1] xfs_healer: fix getmntent race in weakhandle
  2026-06-30  1:02 [PATCHSET 4/4] xfs_healer: codex-inspired bug fixes, part 3 Darrick J. Wong
@ 2026-06-30  1:04 ` Darrick J. Wong
  2026-06-30  5:19   ` Christoph Hellwig
  0 siblings, 1 reply; 3+ messages in thread
From: Darrick J. Wong @ 2026-06-30  1:04 UTC (permalink / raw)
  To: aalbersh, djwong; +Cc: linux-xfs, linux-xfs, hch

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

Codex points out that getmntent() can't be used in threaded programs
because it might employ hidden global static buffers.  GNU and musl libc
provide a getmntent_r variant that requires the caller to establish the
buffers, so let's use that.

Cc: <linux-xfs@vger.kernel.org> # v7.0.0
Fixes: 54c0ba68b007b3 ("xfs_healer: use getmntent to find moved filesystems")
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 healer/weakhandle.c |   15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)


diff --git a/healer/weakhandle.c b/healer/weakhandle.c
index 9aa8859881481b..0601011d167cd9 100644
--- a/healer/weakhandle.c
+++ b/healer/weakhandle.c
@@ -155,6 +155,9 @@ weakhandle_reopen_from(
 	return -1;
 }
 
+/* three paths, a filesystem type string of unknown length, and options */
+#define MNTENT_BUFLEN		(4 * PATH_MAX + NAME_MAX)
+
 /* Reopen a file handle obtained via weak reference. */
 int
 weakhandle_reopen(
@@ -163,11 +166,13 @@ weakhandle_reopen(
 	weakhandle_fd_t		is_acceptable,
 	void			*data)
 {
+	struct mntent		ent;
 	const size_t		smbuf_size =
 		libfrog_statmount_sizeof(PATH_MAX);
 	struct statmount	*smbuf = alloca(smbuf_size);
 	FILE			*mtab;
 	struct mntent		*mnt;
+	char			*buf;
 	int			ret;
 
 	/* First try reopening using the original mountpoint */
@@ -203,7 +208,13 @@ weakhandle_reopen(
 	if (!mtab)
 		return -1;
 
-	while ((mnt = getmntent(mtab)) != NULL) {
+	buf = malloc(MNTENT_BUFLEN);
+	if (!buf) {
+		ret = -1;
+		goto out_mtab;
+	}
+
+	while ((mnt = getmntent_r(mtab, &ent, buf, MNTENT_BUFLEN)) != NULL) {
 		if (strcmp(mnt->mnt_type, "xfs"))
 			continue;
 		if (strcmp(mnt->mnt_fsname, wh->fsname))
@@ -222,6 +233,8 @@ weakhandle_reopen(
 		ret = -1;
 	}
 
+	free(buf);
+out_mtab:
 	endmntent(mtab);
 	return ret;
 }


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] xfs_healer: fix getmntent race in weakhandle
  2026-06-30  1:04 ` [PATCH 1/1] xfs_healer: fix getmntent race in weakhandle Darrick J. Wong
@ 2026-06-30  5:19   ` Christoph Hellwig
  0 siblings, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2026-06-30  5:19 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: aalbersh, linux-xfs, hch

On Mon, Jun 29, 2026 at 06:04:59PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Codex points out that getmntent() can't be used in threaded programs
> because it might employ hidden global static buffers.

Can't be used is a bit strong.  It just can't be used by multiple
t─reads at the same time.


> GNU and musl libc
> provide a getmntent_r variant that requires the caller to establish the
> buffers, so let's use that.

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-06-30  5:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-30  1:02 [PATCHSET 4/4] xfs_healer: codex-inspired bug fixes, part 3 Darrick J. Wong
2026-06-30  1:04 ` [PATCH 1/1] xfs_healer: fix getmntent race in weakhandle Darrick J. Wong
2026-06-30  5:19   ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox