All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 1/8] fs: move sgid strip operation from inode_init_owner into inode_sgid_strip
@ 2022-04-19 11:47 ` Yang Xu
  0 siblings, 0 replies; 48+ messages in thread
From: Yang Xu @ 2022-04-19 11:47 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: ceph-devel, linux-nfs, linux-xfs, viro, david, djwong, brauner,
	jlayton, ntfs3, chao, linux-f2fs-devel, Yang Xu

This has no functional change. Just create and export inode_sgid_strip api for
the subsequent patch. This function is used to strip S_ISGID mode when init
a new inode.

Acked-by: Christian Brauner (Microsoft) <brauner@kernel.org>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 fs/inode.c         | 22 ++++++++++++++++++----
 include/linux/fs.h |  3 ++-
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/fs/inode.c b/fs/inode.c
index 9d9b422504d1..3215e61a0021 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -2246,10 +2246,8 @@ void inode_init_owner(struct user_namespace *mnt_userns, struct inode *inode,
 		/* Directories are special, and always inherit S_ISGID */
 		if (S_ISDIR(mode))
 			mode |= S_ISGID;
-		else if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP) &&
-			 !in_group_p(i_gid_into_mnt(mnt_userns, dir)) &&
-			 !capable_wrt_inode_uidgid(mnt_userns, dir, CAP_FSETID))
-			mode &= ~S_ISGID;
+		else
+			inode_sgid_strip(mnt_userns, dir, &mode);
 	} else
 		inode_fsgid_set(inode, mnt_userns);
 	inode->i_mode = mode;
@@ -2405,3 +2403,19 @@ struct timespec64 current_time(struct inode *inode)
 	return timestamp_truncate(now, inode);
 }
 EXPORT_SYMBOL(current_time);
+
+void inode_sgid_strip(struct user_namespace *mnt_userns,
+		      const struct inode *dir, umode_t *mode)
+{
+	if (S_ISDIR(*mode) || !dir || !(dir->i_mode & S_ISGID))
+		return;
+	if ((*mode & (S_ISGID | S_IXGRP)) != (S_ISGID | S_IXGRP))
+		return;
+	if (in_group_p(i_gid_into_mnt(mnt_userns, dir)))
+		return;
+	if (capable_wrt_inode_uidgid(mnt_userns, dir, CAP_FSETID))
+		return;
+
+	*mode &= ~S_ISGID;
+}
+EXPORT_SYMBOL(inode_sgid_strip);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index bbde95387a23..4a617aaab6f6 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1897,7 +1897,8 @@ extern long compat_ptr_ioctl(struct file *file, unsigned int cmd,
 void inode_init_owner(struct user_namespace *mnt_userns, struct inode *inode,
 		      const struct inode *dir, umode_t mode);
 extern bool may_open_dev(const struct path *path);
-
+void inode_sgid_strip(struct user_namespace *mnt_userns,
+		      const struct inode *dir, umode_t *mode);
 /*
  * This is the "filldir" function type, used by readdir() to let
  * the kernel specify what kind of dirent layout it wants to have.
-- 
2.27.0


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

end of thread, other threads:[~2022-04-21  1:12 UTC | newest]

Thread overview: 48+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-19 11:47 [PATCH v4 1/8] fs: move sgid strip operation from inode_init_owner into inode_sgid_strip Yang Xu
2022-04-19 11:47 ` [f2fs-dev] " Yang Xu
2022-04-19 11:47 ` [PATCH v4 2/8] fs: Add missing umask strip in vfs_tmpfile Yang Xu
2022-04-19 11:47   ` [f2fs-dev] " Yang Xu
2022-04-19 11:47 ` [PATCH v4 3/8] xfs: only call posix_acl_create under CONFIG_XFS_POSIX_ACL Yang Xu
2022-04-19 11:47   ` [f2fs-dev] " Yang Xu
2022-04-19 13:53   ` Christian Brauner
2022-04-19 13:53     ` [f2fs-dev] " Christian Brauner
2022-04-20  1:12     ` xuyang2018.jy
2022-04-20  1:12       ` [f2fs-dev] " xuyang2018.jy
2022-04-20  4:49   ` Christoph Hellwig
2022-04-20  4:49     ` [f2fs-dev] " Christoph Hellwig
2022-04-19 11:47 ` [PATCH v4 4/8] NFSv3: only do posix_acl_create under CONFIG_NFS_V3_ACL Yang Xu
2022-04-19 11:47   ` [f2fs-dev] " Yang Xu
2022-04-19 13:59   ` Christian Brauner
2022-04-19 13:59     ` [f2fs-dev] " Christian Brauner
2022-04-19 14:11     ` Trond Myklebust
2022-04-19 14:11       ` [f2fs-dev] " Trond Myklebust
2022-04-20  1:12       ` xuyang2018.jy
2022-04-20  1:12         ` [f2fs-dev] " xuyang2018.jy
2022-04-19 11:47 ` [PATCH v4 5/8] f2fs: Remove useless NULL assign value for acl and default_acl Yang Xu
2022-04-19 11:47   ` [f2fs-dev] " Yang Xu
2022-04-19 14:02   ` Christian Brauner
2022-04-19 14:02     ` [f2fs-dev] " Christian Brauner
2022-04-20  1:14     ` xuyang2018.jy
2022-04-20  1:14       ` [f2fs-dev] " xuyang2018.jy
2022-04-19 11:47 ` [PATCH v4 6/8] ntfs3: Use the same order for acl pointer check in ntfs_init_acl Yang Xu
2022-04-19 11:47   ` [f2fs-dev] " Yang Xu
2022-04-19 14:03   ` Christian Brauner
2022-04-19 14:03     ` [f2fs-dev] " Christian Brauner
2022-04-20  1:15     ` xuyang2018.jy
2022-04-20  1:15       ` [f2fs-dev] " xuyang2018.jy
2022-04-19 11:47 ` [PATCH v4 7/8] fs: strip file's S_ISGID mode on vfs instead of on underlying filesystem Yang Xu
2022-04-19 11:47   ` [f2fs-dev] " Yang Xu
2022-04-19 14:09   ` Christian Brauner
2022-04-19 14:09     ` [f2fs-dev] " Christian Brauner
2022-04-20  1:16     ` xuyang2018.jy
2022-04-20  1:16       ` [f2fs-dev] " xuyang2018.jy
2022-04-19 11:47 ` [PATCH v4 8/8] ceph: Remove S_ISGID clear code in ceph_finish_async_create Yang Xu
2022-04-19 11:47   ` [f2fs-dev] " Yang Xu
2022-04-19 14:05 ` [PATCH v4 1/8] fs: move sgid strip operation from inode_init_owner into inode_sgid_strip Christian Brauner
2022-04-19 14:05   ` [f2fs-dev] " Christian Brauner
2022-04-20  1:27   ` xuyang2018.jy
2022-04-20  1:27     ` [f2fs-dev] " xuyang2018.jy
2022-04-20 21:52     ` Dave Chinner
2022-04-20 21:52       ` [f2fs-dev] " Dave Chinner
2022-04-21  1:11       ` xuyang2018.jy
2022-04-21  1:11         ` [f2fs-dev] " xuyang2018.jy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.