linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHSET 1/2] fuse2fs: round 5 bug fixes
@ 2025-09-15 22:37 Darrick J. Wong
  2025-09-15 22:37 ` [PATCH 01/12] libext2fs: use F_GETFL, not F_GETFD, in unixfd_open Darrick J. Wong
                   ` (11 more replies)
  0 siblings, 12 replies; 15+ messages in thread
From: Darrick J. Wong @ 2025-09-15 22:37 UTC (permalink / raw)
  To: tytso; +Cc: linux-ext4, linux-ext4

Hi all,

This series fixes more bugs in fuse2fs.

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

Comments and questions are, as always, welcome.

e2fsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse2fs-fixes
---
Commits in this patchset:
 * libext2fs: use F_GETFL, not F_GETFD, in unixfd_open
 * libext2fs: don't look for O_EXCL in the F_GETFL output
 * fuse2fs: update manpage
 * fuse2fs: quiet down EXT2_ET_RO_FILSYS errors
 * fuse2fs: free global_fs after a failed ext2fs_close call
 * fuse2fs: fix memory corruption when parsing mount options
 * fuse2fs: fix fssetxattr flags updates
 * fuse2fs: fix default acls propagating to non-dir children
 * fuse2fs: don't update atime when reading executable file content
 * fuse2fs: fix in_file_group missing the primary process gid
 * fuse2fs: work around EBUSY discard returns from dm-thinp
 * fuse2fs: check free space when creating a symlink
---
 lib/ext2fs/unix_io.c |    7 ++--
 misc/fuse2fs.1.in    |   42 ++++++++++++++--------
 misc/fuse2fs.c       |   94 +++++++++++++++++++++++++++++++++++++++-----------
 3 files changed, 103 insertions(+), 40 deletions(-)


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

* [PATCH 01/12] libext2fs: use F_GETFL, not F_GETFD, in unixfd_open
  2025-09-15 22:37 [PATCHSET 1/2] fuse2fs: round 5 bug fixes Darrick J. Wong
@ 2025-09-15 22:37 ` Darrick J. Wong
  2025-09-15 22:38 ` [PATCH 02/12] libext2fs: don't look for O_EXCL in the F_GETFL output Darrick J. Wong
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Darrick J. Wong @ 2025-09-15 22:37 UTC (permalink / raw)
  To: tytso; +Cc: linux-ext4, linux-ext4

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

F_GETFD is the fcntl command that returns FD_* flags, but the callsite
wants to look at the O_* flags.  F_GETFL is the fcntl command that
returns the O_* flags, so change the subcommand to be correct.

Cc: <linux-ext4@vger.kernel.org> # v1.43.2
Fixes: 4ccf9e4fe165cf ("libext2fs: add unixfd_io_manager")
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 lib/ext2fs/unix_io.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c
index cb408f51779aa7..adbdd5f6603d74 100644
--- a/lib/ext2fs/unix_io.c
+++ b/lib/ext2fs/unix_io.c
@@ -1086,7 +1086,7 @@ static errcode_t unixfd_open(const char *str_fd, int flags,
 
 	fd = atoi(str_fd);
 #if defined(HAVE_FCNTL)
-	fd_flags = fcntl(fd, F_GETFD);
+	fd_flags = fcntl(fd, F_GETFL);
 	if (fd_flags == -1)
 		return EBADF;
 


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

* [PATCH 02/12] libext2fs: don't look for O_EXCL in the F_GETFL output
  2025-09-15 22:37 [PATCHSET 1/2] fuse2fs: round 5 bug fixes Darrick J. Wong
  2025-09-15 22:37 ` [PATCH 01/12] libext2fs: use F_GETFL, not F_GETFD, in unixfd_open Darrick J. Wong
@ 2025-09-15 22:38 ` Darrick J. Wong
  2025-09-15 22:38 ` [PATCH 03/12] fuse2fs: update manpage Darrick J. Wong
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Darrick J. Wong @ 2025-09-15 22:38 UTC (permalink / raw)
  To: tytso; +Cc: linux-ext4, linux-ext4

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

For decades, Linux has never propagated O_EXCL into the user-visible
file flags in do_dentry_open:

	f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);

Therefore, one cannot use F_GETFL to determine if the file was opened
with O_EXCL.  The unixfd IO manager will have to trust that the caller
opened the file in O_EXCL mode.  Without this patch, the upcoming flock
patch will not work correctly in determining the lock mode to keep other
copies of fuse4fs and/or systemd from touching a fuse4fs mounted
filesystem.

Cc: <linux-ext4@vger.kernel.org> # v1.43.2
Fixes: 4ccf9e4fe165cf ("libext2fs: add unixfd_io_manager")
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 lib/ext2fs/unix_io.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)


diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c
index adbdd5f6603d74..723a5c2474cdd5 100644
--- a/lib/ext2fs/unix_io.c
+++ b/lib/ext2fs/unix_io.c
@@ -1090,11 +1090,10 @@ static errcode_t unixfd_open(const char *str_fd, int flags,
 	if (fd_flags == -1)
 		return EBADF;
 
-	flags = 0;
+	/* O_EXCL is cleared by Linux at open and not returned by F_GETFL */
+	flags &= IO_FLAG_EXCLUSIVE;
 	if (fd_flags & O_RDWR)
 		flags |= IO_FLAG_RW;
-	if (fd_flags & O_EXCL)
-		flags |= IO_FLAG_EXCLUSIVE;
 #if defined(O_DIRECT)
 	if (fd_flags & O_DIRECT)
 		flags |= IO_FLAG_DIRECT_IO;


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

* [PATCH 03/12] fuse2fs: update manpage
  2025-09-15 22:37 [PATCHSET 1/2] fuse2fs: round 5 bug fixes Darrick J. Wong
  2025-09-15 22:37 ` [PATCH 01/12] libext2fs: use F_GETFL, not F_GETFD, in unixfd_open Darrick J. Wong
  2025-09-15 22:38 ` [PATCH 02/12] libext2fs: don't look for O_EXCL in the F_GETFL output Darrick J. Wong
@ 2025-09-15 22:38 ` Darrick J. Wong
  2025-09-15 22:38 ` [PATCH 04/12] fuse2fs: quiet down EXT2_ET_RO_FILSYS errors Darrick J. Wong
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Darrick J. Wong @ 2025-09-15 22:38 UTC (permalink / raw)
  To: tytso; +Cc: linux-ext4

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

Update the manpage to list current options for fuse2fs.  While we're at
it, alphabetize the non-grouped mount options (e.g. rw/ro, *df).

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 misc/fuse2fs.1.in |   42 +++++++++++++++++++++++++++---------------
 1 file changed, 27 insertions(+), 15 deletions(-)


diff --git a/misc/fuse2fs.1.in b/misc/fuse2fs.1.in
index 21f5760742c639..69fc6b01d7b639 100644
--- a/misc/fuse2fs.1.in
+++ b/misc/fuse2fs.1.in
@@ -36,21 +36,33 @@ .SS "fuse2fs options:"
 \fB-o\fR ro
 read-only mount
 .TP
-\fB-o\fR errors=panic
-dump core on error
+\fB-o\fR rw
+read-write mount (default)
+.TP
+\fB-o\fR bsddf
+bsd-style df (default)
 .TP
 \fB-o\fR minixdf
 minix-style df
 .TP
+\fB-o\fR acl
+enable file access control lists
+.TP
+\fB-o\fR cache_size
+Set the disk cache size to this quantity.
+The quantity may contain the suffixes k, m, or g.
+By default, the size is 32MB.
+The size may not be larger than 2GB.
+.TP
+\fB-o\fR direct
+Use O_DIRECT to access the block device.
+.TP
+\fB-o\fR errors=panic
+dump core on error
+.TP
 \fB-o\fR fakeroot
 pretend to be root for permission checks
 .TP
-\fB-o\fR no_default_opts
-do not include default fuse options
-.TP
-\fB-o\fR norecovery
-do not replay the journal and mount the file system read-only
-.TP
 \fB-o\fR fuse2fs_debug
 enable fuse2fs debugging
 .TP
@@ -63,14 +75,14 @@ .SS "fuse2fs options:"
 .I nosuid
 ) later.
 .TP
-\fB-o\fR direct
-Use O_DIRECT to access the block device.
+\fB-o\fR lockfile=path
+use this file to control access to the filesystem
 .TP
-\fB-o\fR cache_size
-Set the disk cache size to this quantity.
-The quantity may contain the suffixes k, m, or g.
-By default, the size is 32MB.
-The size may not be larger than 2GB.
+\fB-o\fR no_default_opts
+do not include default fuse options
+.TP
+\fB-o\fR norecovery
+do not replay the journal and mount the file system read-only
 .SS "FUSE options:"
 .TP
 \fB-d -o\fR debug


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

* [PATCH 04/12] fuse2fs: quiet down EXT2_ET_RO_FILSYS errors
  2025-09-15 22:37 [PATCHSET 1/2] fuse2fs: round 5 bug fixes Darrick J. Wong
                   ` (2 preceding siblings ...)
  2025-09-15 22:38 ` [PATCH 03/12] fuse2fs: update manpage Darrick J. Wong
@ 2025-09-15 22:38 ` Darrick J. Wong
  2025-09-15 22:39 ` [PATCH 05/12] fuse2fs: free global_fs after a failed ext2fs_close call Darrick J. Wong
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Darrick J. Wong @ 2025-09-15 22:38 UTC (permalink / raw)
  To: tytso; +Cc: linux-ext4, linux-ext4

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

If an fs update fails because the ext2_filsys is opened in readonly
mode, just return EROFS and don't log that.  This prevents unnecessary
spew for norecovery mounts.

Cc: <linux-ext4@vger.kernel.org> # v1.43
Fixes: 81cbf1ef4f5dab ("misc: add fuse2fs, a FUSE server for e2fsprogs")
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 misc/fuse2fs.c |    3 +++
 1 file changed, 3 insertions(+)


diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index cb5620c7e2ee33..4d92e1e818b1c4 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -4983,6 +4983,9 @@ static int __translate_error(ext2_filsys fs, ext2_ino_t ino, errcode_t err,
 	case EXT2_ET_UNIMPLEMENTED:
 		ret = -EOPNOTSUPP;
 		break;
+	case EXT2_ET_RO_FILSYS:
+		ret = -EROFS;
+		break;
 	case EXT2_ET_MAGIC_EXT2FS_FILSYS:
 	case EXT2_ET_MAGIC_BADBLOCKS_LIST:
 	case EXT2_ET_MAGIC_BADBLOCKS_ITERATE:


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

* [PATCH 05/12] fuse2fs: free global_fs after a failed ext2fs_close call
  2025-09-15 22:37 [PATCHSET 1/2] fuse2fs: round 5 bug fixes Darrick J. Wong
                   ` (3 preceding siblings ...)
  2025-09-15 22:38 ` [PATCH 04/12] fuse2fs: quiet down EXT2_ET_RO_FILSYS errors Darrick J. Wong
@ 2025-09-15 22:39 ` Darrick J. Wong
  2025-10-06 21:23   ` Darrick J. Wong
  2025-09-15 22:39 ` [PATCH 06/12] fuse2fs: fix memory corruption when parsing mount options Darrick J. Wong
                   ` (6 subsequent siblings)
  11 siblings, 1 reply; 15+ messages in thread
From: Darrick J. Wong @ 2025-09-15 22:39 UTC (permalink / raw)
  To: tytso; +Cc: linux-ext4, linux-ext4

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

If ext2fs_close fails for any reason, it won't free the ext2_filsys
object or any of the other things that hang off of it, like the io
managers and whatnot.  Right now this results in a memory leak of
global_fs, which is mostly benign because we're nearly to the end of
main() anyway.

However, a future patch will move the ext2fs_close call to op_destroy
prior to introducing fuseblk support, which means that we won't close
the (O_EXCL) block device before returning from umount, which will cause
problems with fstests and the user expectation that block devices are
closed when umount(8) returns.

Therefore, free the context after a failed close.

Cc: <linux-ext4@vger.kernel.org> # v1.43.7
Fixes: 6ae16a6814f47c ("misc: clean up error handling for ext2fs_run_ext3_journal()")
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 misc/fuse2fs.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)


diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 4d92e1e818b1c4..08470a99dc7b4d 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -4905,8 +4905,10 @@ int main(int argc, char *argv[])
 	}
 	if (global_fs) {
 		err = ext2fs_close(global_fs);
-		if (err)
+		if (err) {
 			com_err(argv[0], err, "while closing fs");
+			ext2fs_free(global_fs);
+		}
 		global_fs = NULL;
 	}
 	if (fctx.lockfile) {


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

* [PATCH 06/12] fuse2fs: fix memory corruption when parsing mount options
  2025-09-15 22:37 [PATCHSET 1/2] fuse2fs: round 5 bug fixes Darrick J. Wong
                   ` (4 preceding siblings ...)
  2025-09-15 22:39 ` [PATCH 05/12] fuse2fs: free global_fs after a failed ext2fs_close call Darrick J. Wong
@ 2025-09-15 22:39 ` Darrick J. Wong
  2025-10-10 15:30   ` Dave Dykstra
  2025-09-15 22:39 ` [PATCH 07/12] fuse2fs: fix fssetxattr flags updates Darrick J. Wong
                   ` (5 subsequent siblings)
  11 siblings, 1 reply; 15+ messages in thread
From: Darrick J. Wong @ 2025-09-15 22:39 UTC (permalink / raw)
  To: tytso; +Cc: linux-ext4, linux-ext4

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

struct fuse_opt has this interesting behavior -- if you set the offset
field to a non-negative value, then it will treat that value as a byte
offset into the data parameter that is passed to fuse_opt_parse.

Unfortnately, process_opt computes a pointer from ((char *)data +
offset), casts that to an int pointer(!), and dereferences the int
pointer to set the value.  Therefore, we cannot have uint8_t fields in
struct fuse2fs because that will lead to subtle memory corruption.

Cc: <linux-ext4@vger.kernel.org> # v1.47.3
Fixes: c7f2688540d95e ("fuse2fs: compact all the boolean flags in struct fuse2fs")
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 misc/fuse2fs.c |   24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)


diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 08470a99dc7b4d..4ebc949b53d1fe 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -217,17 +217,19 @@ struct fuse2fs {
 	pthread_mutex_t bfl;
 	char *device;
 	char *shortdev;
-	uint8_t ro;
-	uint8_t debug;
-	uint8_t no_default_opts;
-	uint8_t panic_on_error;
-	uint8_t minixdf;
-	uint8_t fakeroot;
-	uint8_t alloc_all_blocks;
-	uint8_t norecovery;
-	uint8_t kernel;
-	uint8_t directio;
-	uint8_t acl;
+
+	/* options set by fuse_opt_parse must be of type int */
+	int ro;
+	int debug;
+	int no_default_opts;
+	int panic_on_error;
+	int minixdf;
+	int fakeroot;
+	int alloc_all_blocks;
+	int norecovery;
+	int kernel;
+	int directio;
+	int acl;
 
 	int logfd;
 	int blocklog;


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

* [PATCH 07/12] fuse2fs: fix fssetxattr flags updates
  2025-09-15 22:37 [PATCHSET 1/2] fuse2fs: round 5 bug fixes Darrick J. Wong
                   ` (5 preceding siblings ...)
  2025-09-15 22:39 ` [PATCH 06/12] fuse2fs: fix memory corruption when parsing mount options Darrick J. Wong
@ 2025-09-15 22:39 ` Darrick J. Wong
  2025-09-15 22:39 ` [PATCH 08/12] fuse2fs: fix default acls propagating to non-dir children Darrick J. Wong
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Darrick J. Wong @ 2025-09-15 22:39 UTC (permalink / raw)
  To: tytso; +Cc: linux-ext4, linux-ext4

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

Fix flags setting so that it actually works -- we need to preserve the
iflags bits that don't exist in xflags.

Cc: <linux-ext4@vger.kernel.org> # v1.47.3
Fixes: 9b5012c1569d4e ("fuse2fs: support getting and setting via struct fsxattr")
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 misc/fuse2fs.c |   30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)


diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 4ebc949b53d1fe..de675b4ecb9438 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -3891,6 +3891,33 @@ static __u32 fsxflags_to_iflags(__u32 xflags)
 	return iflags;
 }
 
+#define FUSE2FS_MODIFIABLE_XFLAGS (FS_XFLAG_IMMUTABLE | \
+				   FS_XFLAG_APPEND | \
+				   FS_XFLAG_SYNC | \
+				   FS_XFLAG_NOATIME | \
+				   FS_XFLAG_NODUMP | \
+				   FS_XFLAG_PROJINHERIT)
+
+#define FUSE2FS_MODIFIABLE_IXFLAGS (FS_IMMUTABLE_FL | \
+				    FS_APPEND_FL | \
+				    FS_SYNC_FL | \
+				    FS_NOATIME_FL | \
+				    FS_NODUMP_FL | \
+				    FS_PROJINHERIT_FL)
+
+static inline int set_xflags(struct ext2_inode_large *inode, __u32 xflags)
+{
+	__u32 iflags;
+
+	if (xflags & ~FUSE2FS_MODIFIABLE_XFLAGS)
+		return -EINVAL;
+
+	iflags = fsxflags_to_iflags(xflags);
+	inode->i_flags = (inode->i_flags & ~FUSE2FS_MODIFIABLE_IXFLAGS) |
+			 (iflags & FUSE2FS_MODIFIABLE_IXFLAGS);
+	return 0;
+}
+
 static int ioctl_fssetxattr(struct fuse2fs *ff, struct fuse2fs_file_handle *fh,
 			    void *data)
 {
@@ -3900,7 +3927,6 @@ static int ioctl_fssetxattr(struct fuse2fs *ff, struct fuse2fs_file_handle *fh,
 	int ret;
 	struct fuse_context *ctxt = fuse_get_context();
 	struct fsxattr *fsx = data;
-	__u32 flags = fsxflags_to_iflags(fsx->fsx_xflags);
 	unsigned int inode_size;
 
 	FUSE2FS_CHECK_MAGIC(fs, fh, FUSE2FS_FILE_MAGIC);
@@ -3912,7 +3938,7 @@ static int ioctl_fssetxattr(struct fuse2fs *ff, struct fuse2fs_file_handle *fh,
 	if (want_check_owner(ff, ctxt) && inode_uid(inode) != ctxt->uid)
 		return -EPERM;
 
-	ret = set_iflags(&inode, flags);
+	ret = set_xflags(&inode, fsx->fsx_xflags);
 	if (ret)
 		return ret;
 


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

* [PATCH 08/12] fuse2fs: fix default acls propagating to non-dir children
  2025-09-15 22:37 [PATCHSET 1/2] fuse2fs: round 5 bug fixes Darrick J. Wong
                   ` (6 preceding siblings ...)
  2025-09-15 22:39 ` [PATCH 07/12] fuse2fs: fix fssetxattr flags updates Darrick J. Wong
@ 2025-09-15 22:39 ` Darrick J. Wong
  2025-09-15 22:40 ` [PATCH 09/12] fuse2fs: don't update atime when reading executable file content Darrick J. Wong
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Darrick J. Wong @ 2025-09-15 22:39 UTC (permalink / raw)
  To: tytso; +Cc: linux-ext4, linux-ext4

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

New non-directory children should not be copying the default ACLs of the
parents.  Caught by generic/099 in fuseblk mode.

Cc: <linux-ext4@vger.kernel.org> # v1.47.3
Fixes: 2c7900387620a6 ("fuse2fs: propagate default ACLs to new children")
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 misc/fuse2fs.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)


diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index de675b4ecb9438..b5b860466742d2 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -1167,13 +1167,13 @@ static int __setxattr(struct fuse2fs *ff, ext2_ino_t ino, const char *name,
 }
 
 static int propagate_default_acls(struct fuse2fs *ff, ext2_ino_t parent,
-				  ext2_ino_t child)
+				  ext2_ino_t child, mode_t mode)
 {
 	void *def;
 	size_t deflen;
 	int ret;
 
-	if (!ff->acl)
+	if (!ff->acl || S_ISDIR(mode))
 		return 0;
 
 	ret = __getxattr(ff, parent, XATTR_NAME_POSIX_ACL_DEFAULT, &def,
@@ -1346,7 +1346,7 @@ static int op_mknod(const char *path, mode_t mode, dev_t dev)
 
 	ext2fs_inode_alloc_stats2(fs, child, 1, 0);
 
-	ret = propagate_default_acls(ff, parent, child);
+	ret = propagate_default_acls(ff, parent, child, inode.i_mode);
 	if (ret)
 		goto out2;
 out2:
@@ -1474,7 +1474,7 @@ static int op_mkdir(const char *path, mode_t mode)
 		goto out3;
 	}
 
-	ret = propagate_default_acls(ff, parent, child);
+	ret = propagate_default_acls(ff, parent, child, inode.i_mode);
 	if (ret)
 		goto out3;
 
@@ -3543,7 +3543,7 @@ static int op_create(const char *path, mode_t mode, struct fuse_file_info *fp)
 
 	ext2fs_inode_alloc_stats2(fs, child, 1, 0);
 
-	ret = propagate_default_acls(ff, parent, child);
+	ret = propagate_default_acls(ff, parent, child, inode.i_mode);
 	if (ret)
 		goto out2;
 


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

* [PATCH 09/12] fuse2fs: don't update atime when reading executable file content
  2025-09-15 22:37 [PATCHSET 1/2] fuse2fs: round 5 bug fixes Darrick J. Wong
                   ` (7 preceding siblings ...)
  2025-09-15 22:39 ` [PATCH 08/12] fuse2fs: fix default acls propagating to non-dir children Darrick J. Wong
@ 2025-09-15 22:40 ` Darrick J. Wong
  2025-09-15 22:40 ` [PATCH 10/12] fuse2fs: fix in_file_group missing the primary process gid Darrick J. Wong
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Darrick J. Wong @ 2025-09-15 22:40 UTC (permalink / raw)
  To: tytso; +Cc: linux-ext4, linux-ext4

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

The kernel doesn't update the atime of program files when it's paging
their content into memory, so fuse2fs shouldn't either.  Found by
generic/120.

Cc: <linux-ext4@vger.kernel.org> # v1.43
Fixes: 81cbf1ef4f5dab ("misc: add fuse2fs, a FUSE server for e2fsprogs")
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 misc/fuse2fs.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)


diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index b5b860466742d2..a075e3055bd743 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -207,6 +207,7 @@ struct fuse2fs_file_handle {
 	unsigned long magic;
 	ext2_ino_t ino;
 	int open_flags;
+	int check_flags;
 };
 
 /* Main program context */
@@ -2672,6 +2673,7 @@ static int __op_open(struct fuse2fs *ff, const char *path,
 			ret = check_inum_access(ff, file->ino, X_OK);
 			if (ret)
 				goto out;
+			check = X_OK;
 		} else
 			goto out;
 	}
@@ -2682,6 +2684,7 @@ static int __op_open(struct fuse2fs *ff, const char *path,
 			goto out;
 	}
 
+	file->check_flags = check;
 	fp->fh = (uintptr_t)file;
 
 out:
@@ -2750,7 +2753,7 @@ static int op_read(const char *path EXT2FS_ATTR((unused)), char *buf,
 		goto out;
 	}
 
-	if (fs_writeable(fs)) {
+	if (fh->check_flags != X_OK && fs_writeable(fs)) {
 		ret = update_atime(fs, fh->ino);
 		if (ret)
 			goto out;


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

* [PATCH 10/12] fuse2fs: fix in_file_group missing the primary process gid
  2025-09-15 22:37 [PATCHSET 1/2] fuse2fs: round 5 bug fixes Darrick J. Wong
                   ` (8 preceding siblings ...)
  2025-09-15 22:40 ` [PATCH 09/12] fuse2fs: don't update atime when reading executable file content Darrick J. Wong
@ 2025-09-15 22:40 ` Darrick J. Wong
  2025-09-15 22:40 ` [PATCH 11/12] fuse2fs: work around EBUSY discard returns from dm-thinp Darrick J. Wong
  2025-09-15 22:40 ` [PATCH 12/12] fuse2fs: check free space when creating a symlink Darrick J. Wong
  11 siblings, 0 replies; 15+ messages in thread
From: Darrick J. Wong @ 2025-09-15 22:40 UTC (permalink / raw)
  To: tytso; +Cc: linux-ext4, linux-ext4

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

I forgot that Unix processes have both a primary group id and a list of
supplementary group ids.  The primary is provided by the fuse client;
the supplemental groups are noted by the Groups: field of
/proc/self/status.

If a process does not have /any/ supplemental group ids, then
in_file_group returns the wrong answer if the inode gid matches the
group id provided by the fuse client because it doesn't check that
anymore.  Make it so the primary group id check always happens.

Found by generic/375.

Cc: <linux-ext4@vger.kernel.org> # v1.47.3
Fixes: 3469e6ff606af8 ("fuse2fs: fix group membership checking in op_chmod")
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 misc/fuse2fs.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)


diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index a075e3055bd743..7ec7875d9108a2 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -2303,10 +2303,14 @@ static int in_file_group(struct fuse_context *ctxt,
 	gid_t gid = inode_gid(*inode);
 	int ret;
 
+	/* If the inode gid matches the process' primary group, we're done. */
+	if (ctxt->gid == gid)
+		return 1;
+
 	ret = get_req_groups(ff, &gids, &nr_gids);
 	if (ret == -ENOENT) {
 		/* magic return code for "could not get caller group info" */
-		return ctxt->gid == inode_gid(*inode);
+		return 0;
 	}
 	if (ret < 0)
 		return ret;


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

* [PATCH 11/12] fuse2fs: work around EBUSY discard returns from dm-thinp
  2025-09-15 22:37 [PATCHSET 1/2] fuse2fs: round 5 bug fixes Darrick J. Wong
                   ` (9 preceding siblings ...)
  2025-09-15 22:40 ` [PATCH 10/12] fuse2fs: fix in_file_group missing the primary process gid Darrick J. Wong
@ 2025-09-15 22:40 ` Darrick J. Wong
  2025-09-15 22:40 ` [PATCH 12/12] fuse2fs: check free space when creating a symlink Darrick J. Wong
  11 siblings, 0 replies; 15+ messages in thread
From: Darrick J. Wong @ 2025-09-15 22:40 UTC (permalink / raw)
  To: tytso; +Cc: linux-ext4

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

generic/500 has this interesting failure mode when fuse2fs is running in
fuseblk mode:

 --- /run/fstests/bin/tests/generic/500.out      2025-07-15 14:45:15.092576090 -0700
 +++ /var/tmp/fstests/generic/500.out.bad        2025-09-05 15:09:35.211499883 -0700
 @@ -1,2 +1,22 @@
  QA output created by 500
 +fstrim: /opt: FITRIM ioctl failed: Device or resource busy

Apparently you can overwhelm dm-thinp with a large number of discard
requests, at which point it starts returning EBUSY.  This is unexpected
behavior but let's mask that off because discard is advisory anyways.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 misc/fuse2fs.c |    8 ++++++++
 1 file changed, 8 insertions(+)


diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 7ec7875d9108a2..c09b2aa04c02fb 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -4038,6 +4038,14 @@ static int ioctl_fitrim(struct fuse2fs *ff, struct fuse2fs_file_handle *fh,
 
 		if (b - start >= minlen) {
 			err = io_channel_discard(fs->io, start, b - start);
+			if (err == EBUSY) {
+				/*
+				 * Apparently dm-thinp can return EBUSY when
+				 * it's too busy deallocating thinp units to
+				 * deallocate more.  Swallow these errors.
+				 */
+				err = 0;
+			}
 			if (err)
 				return translate_error(fs, fh->ino, err);
 			cleared += b - start;


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

* [PATCH 12/12] fuse2fs: check free space when creating a symlink
  2025-09-15 22:37 [PATCHSET 1/2] fuse2fs: round 5 bug fixes Darrick J. Wong
                   ` (10 preceding siblings ...)
  2025-09-15 22:40 ` [PATCH 11/12] fuse2fs: work around EBUSY discard returns from dm-thinp Darrick J. Wong
@ 2025-09-15 22:40 ` Darrick J. Wong
  11 siblings, 0 replies; 15+ messages in thread
From: Darrick J. Wong @ 2025-09-15 22:40 UTC (permalink / raw)
  To: tytso; +Cc: linux-ext4, linux-ext4

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

Make sure we have enough space to create the symlink and its remote
block.

Cc: <linux-ext4@vger.kernel.org> # v1.43
Fixes: 81cbf1ef4f5dab ("misc: add fuse2fs, a FUSE server for e2fsprogs")
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 misc/fuse2fs.c |    4 ++++
 1 file changed, 4 insertions(+)


diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index c09b2aa04c02fb..569ac402427767 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -1825,6 +1825,10 @@ static int op_symlink(const char *src, const char *dest)
 	*node_name = 0;
 
 	pthread_mutex_lock(&ff->bfl);
+	if (!fs_can_allocate(ff, 1)) {
+		ret = -ENOSPC;
+		goto out2;
+	}
 	err = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, temp_path,
 			   &parent);
 	*node_name = a;


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

* Re: [PATCH 05/12] fuse2fs: free global_fs after a failed ext2fs_close call
  2025-09-15 22:39 ` [PATCH 05/12] fuse2fs: free global_fs after a failed ext2fs_close call Darrick J. Wong
@ 2025-10-06 21:23   ` Darrick J. Wong
  0 siblings, 0 replies; 15+ messages in thread
From: Darrick J. Wong @ 2025-10-06 21:23 UTC (permalink / raw)
  To: tytso; +Cc: linux-ext4

On Mon, Sep 15, 2025 at 03:39:01PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> If ext2fs_close fails for any reason, it won't free the ext2_filsys
> object or any of the other things that hang off of it, like the io
> managers and whatnot.  Right now this results in a memory leak of
> global_fs, which is mostly benign because we're nearly to the end of
> main() anyway.
> 
> However, a future patch will move the ext2fs_close call to op_destroy
> prior to introducing fuseblk support, which means that we won't close
> the (O_EXCL) block device before returning from umount, which will cause
> problems with fstests and the user expectation that block devices are
> closed when umount(8) returns.
> 
> Therefore, free the context after a failed close.
> 
> Cc: <linux-ext4@vger.kernel.org> # v1.43.7
> Fixes: 6ae16a6814f47c ("misc: clean up error handling for ext2fs_run_ext3_journal()")
> Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
> ---
>  misc/fuse2fs.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> 
> diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
> index 4d92e1e818b1c4..08470a99dc7b4d 100644
> --- a/misc/fuse2fs.c
> +++ b/misc/fuse2fs.c
> @@ -4905,8 +4905,10 @@ int main(int argc, char *argv[])
>  	}
>  	if (global_fs) {
>  		err = ext2fs_close(global_fs);

Heh, this could have been ext2fs_close_free(&global_fs).  Will resubmit.

--D

> -		if (err)
> +		if (err) {
>  			com_err(argv[0], err, "while closing fs");
> +			ext2fs_free(global_fs);
> +		}
>  		global_fs = NULL;
>  	}
>  	if (fctx.lockfile) {
> 
> 

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

* Re: [PATCH 06/12] fuse2fs: fix memory corruption when parsing mount options
  2025-09-15 22:39 ` [PATCH 06/12] fuse2fs: fix memory corruption when parsing mount options Darrick J. Wong
@ 2025-10-10 15:30   ` Dave Dykstra
  0 siblings, 0 replies; 15+ messages in thread
From: Dave Dykstra @ 2025-10-10 15:30 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: tytso, linux-ext4

Yes, I have tested this and agree it is very important and urgent to fix.
I hope it can get into a new release of e2fsprogs soon.

I submitted an issue about this at
    https://github.com/tytso/e2fsprogs/issues/245
and an identical pull request at
    https://github.com/tytso/e2fsprogs/pull/246

Dave

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

end of thread, other threads:[~2025-10-10 15:30 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-15 22:37 [PATCHSET 1/2] fuse2fs: round 5 bug fixes Darrick J. Wong
2025-09-15 22:37 ` [PATCH 01/12] libext2fs: use F_GETFL, not F_GETFD, in unixfd_open Darrick J. Wong
2025-09-15 22:38 ` [PATCH 02/12] libext2fs: don't look for O_EXCL in the F_GETFL output Darrick J. Wong
2025-09-15 22:38 ` [PATCH 03/12] fuse2fs: update manpage Darrick J. Wong
2025-09-15 22:38 ` [PATCH 04/12] fuse2fs: quiet down EXT2_ET_RO_FILSYS errors Darrick J. Wong
2025-09-15 22:39 ` [PATCH 05/12] fuse2fs: free global_fs after a failed ext2fs_close call Darrick J. Wong
2025-10-06 21:23   ` Darrick J. Wong
2025-09-15 22:39 ` [PATCH 06/12] fuse2fs: fix memory corruption when parsing mount options Darrick J. Wong
2025-10-10 15:30   ` Dave Dykstra
2025-09-15 22:39 ` [PATCH 07/12] fuse2fs: fix fssetxattr flags updates Darrick J. Wong
2025-09-15 22:39 ` [PATCH 08/12] fuse2fs: fix default acls propagating to non-dir children Darrick J. Wong
2025-09-15 22:40 ` [PATCH 09/12] fuse2fs: don't update atime when reading executable file content Darrick J. Wong
2025-09-15 22:40 ` [PATCH 10/12] fuse2fs: fix in_file_group missing the primary process gid Darrick J. Wong
2025-09-15 22:40 ` [PATCH 11/12] fuse2fs: work around EBUSY discard returns from dm-thinp Darrick J. Wong
2025-09-15 22:40 ` [PATCH 12/12] fuse2fs: check free space when creating a symlink Darrick J. Wong

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).