From: "Darrick J. Wong" <djwong@kernel.org>
To: tytso@mit.edu
Cc: linux-ext4@vger.kernel.org
Subject: [PATCH 29/29] fuse2fs: fix group membership checking in op_chmod
Date: Wed, 21 May 2025 15:42:30 -0700 [thread overview]
Message-ID: <174786678066.1383760.15547379523110361909.stgit@frogsfrogsfrogs> (raw)
In-Reply-To: <174786677421.1383760.15289906755026332870.stgit@frogsfrogsfrogs>
From: Darrick J. Wong <djwong@kernel.org>
In the decade or so since I touched fuse2fs, libfuse3 has grown the
ability to read the group ids of a process making a chmod request. So
now we actually /can/ determine if a file's gid is a in the group list
of the process that initiated a fuse request. Let's implement that too.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
misc/fuse2fs.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 76 insertions(+), 2 deletions(-)
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index a9f753c775db09..7ec9c6d861fd80 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -2020,6 +2020,70 @@ static int op_link(const char *src, const char *dest)
return ret;
}
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+/* Obtain group ids of the process that sent us a command(?) */
+static int get_req_groups(struct fuse2fs *ff, gid_t **gids, size_t *nr_gids)
+{
+ ext2_filsys fs = ff->fs;
+ errcode_t err;
+ gid_t *array;
+ int nr = 32; /* nobody has more than 32 groups right? */
+ int ret;
+
+ do {
+ err = ext2fs_get_array(nr, sizeof(gid_t), &array);
+ if (err)
+ return translate_error(fs, 0, err);
+
+ ret = fuse_getgroups(nr, array);
+ if (ret < 0)
+ return ret;
+
+ if (ret <= nr) {
+ *gids = array;
+ *nr_gids = ret;
+ return 0;
+ }
+
+ ext2fs_free_mem(&array);
+ nr = ret;
+ } while (0);
+
+ /* shut up gcc */
+ return -ENOMEM;
+}
+
+/*
+ * Is this file's group id in the set of groups associated with the process
+ * that initiated the fuse request? Returns 1 for yes, 0 for no, or a negative
+ * errno.
+ */
+static int in_file_group(struct fuse_context *ctxt,
+ const struct ext2_inode_large *inode)
+{
+ struct fuse2fs *ff = (struct fuse2fs *)ctxt->private_data;
+ gid_t *gids = NULL;
+ size_t i, nr_gids = 0;
+ gid_t gid = inode_gid(*inode);
+ int ret;
+
+ ret = get_req_groups(ff, &gids, &nr_gids);
+ if (ret < 0)
+ return ret;
+
+ for (i = 0; i < nr_gids; i++)
+ if (gids[i] == gid)
+ return 1;
+ return 0;
+}
+#else
+static int in_file_group(struct fuse_context *ctxt,
+ const struct ext2_inode_large *inode)
+{
+ return ctxt->gid == inode_gid(*inode);
+}
+#endif
+
static int op_chmod(const char *path, mode_t mode
#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
, struct fuse_file_info *fi EXT2FS_ATTR((unused))
@@ -2066,11 +2130,21 @@ static int op_chmod(const char *path, mode_t mode
* of the user's groups, but FUSE only tells us about the primary
* group.
*/
- if (!is_superuser(ff, ctxt) && ctxt->gid != inode_gid(inode))
- mode &= ~S_ISGID;
+ if (!is_superuser(ff, ctxt)) {
+ ret = in_file_group(ctxt, &inode);
+ if (ret < 0)
+ goto out;
+
+ if (!ret)
+ mode &= ~S_ISGID;
+ }
inode.i_mode &= ~0xFFF;
inode.i_mode |= mode & 0xFFF;
+
+ dbg_printf(ff, "%s: path=%s new_mode=0%o ino=%d\n", __func__,
+ path, inode.i_mode, ino);
+
ret = update_ctime(fs, ino, &inode);
if (ret)
goto out;
next prev parent reply other threads:[~2025-05-21 22:42 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-21 22:34 [PATCHSET 1/6] fuse2fs: even more bug fixes Darrick J. Wong
2025-05-21 22:35 ` [PATCH 01/29] libext2fs: fix unix io manager invalidation Darrick J. Wong
2025-05-21 22:35 ` [PATCH 02/29] libext2fs: fix livelock in the unix io manager Darrick J. Wong
2025-05-21 22:35 ` [PATCH 03/29] fuse2fs: clean up error messages Darrick J. Wong
2025-05-21 22:35 ` [PATCH 04/29] fuse2fs: fix cache size parsing Darrick J. Wong
2025-05-21 22:36 ` [PATCH 05/29] fuse2fs: compact all the boolean flags in struct fuse2fs Darrick J. Wong
2025-05-21 22:36 ` [PATCH 06/29] fuse2fs: support XATTR_CREATE/REPLACE in setxattr Darrick J. Wong
2025-05-21 22:36 ` [PATCH 07/29] fuse2fs: fix error return handling in op_truncate Darrick J. Wong
2025-05-21 22:37 ` [PATCH 08/29] fuse2fs: flip parameter order in __translate_error Darrick J. Wong
2025-05-21 22:37 ` [PATCH 09/29] fuse2fs: fix CLI argument parsing leaks Darrick J. Wong
2025-05-21 22:37 ` [PATCH 10/29] fuse2fs: allow some control over acls Darrick J. Wong
2025-05-21 22:37 ` [PATCH 11/29] fuse2fs: enable processing of acls in the kernel Darrick J. Wong
2025-05-21 22:38 ` [PATCH 12/29] fuse2fs: make removexattr work correctly Darrick J. Wong
2025-05-21 22:38 ` [PATCH 13/29] fuse2fs: implement O_TRUNC correctly Darrick J. Wong
2025-05-21 22:38 ` [PATCH 14/29] fuse2fs: rearrange check_inum_access parameters a bit Darrick J. Wong
2025-05-21 22:38 ` [PATCH 15/29] fuse2fs: make filesystem corruption a hard error Darrick J. Wong
2025-05-21 22:39 ` [PATCH 16/29] fuse2fs: make internal state " Darrick J. Wong
2025-05-21 22:39 ` [PATCH 17/29] fuse2fs: make bad magic numbers report a corruption error too Darrick J. Wong
2025-05-21 22:39 ` [PATCH 18/29] fuse2fs: return EPERM for write access to EXT2_IMMUTABLE_FL files Darrick J. Wong
2025-05-21 22:39 ` [PATCH 19/29] fuse2fs: check the immutable flag in more places Darrick J. Wong
2025-05-21 22:40 ` [PATCH 20/29] fuse2fs: implement O_APPEND correctly Darrick J. Wong
2025-05-21 22:40 ` [PATCH 21/29] fuse2fs: decode fuse_main error codes Darrick J. Wong
2025-05-21 22:40 ` [PATCH 22/29] fuse2fs: fix fallocate zero range Darrick J. Wong
2025-05-21 22:40 ` [PATCH 23/29] fuse2fs: check for supported xattr name prefixes Darrick J. Wong
2025-05-21 22:41 ` [PATCH 24/29] fuse2fs: fix return value handling Darrick J. Wong
2025-05-21 22:41 ` [PATCH 25/29] fuse2fs: fix removing ea inodes when freeing a file Darrick J. Wong
2025-05-21 22:41 ` [PATCH 26/29] fuse2fs: fix post-EOF preallocation clearing on truncation Darrick J. Wong
2025-05-21 22:41 ` [PATCH 27/29] fuse2fs: also ignore the nodelalloc mount option Darrick J. Wong
2025-05-21 22:42 ` [PATCH 28/29] fuse2fs: propagate default ACLs to new children Darrick J. Wong
2025-05-21 22:42 ` Darrick J. Wong [this message]
2025-05-23 14:03 ` [PATCHSET 1/6] fuse2fs: even more bug fixes Theodore Ts'o
2025-05-29 1:37 ` Darrick J. Wong
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=174786678066.1383760.15547379523110361909.stgit@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/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