From: Christian Brauner <brauner@kernel.org>
To: Christoph Hellwig <hch@lst.de>,
linux-fsdevel@vger.kernel.org,
Seth Forshee <sforshee@digitalocean.com>
Cc: Christian Brauner <brauner@kernel.org>,
Aleksa Sarai <cyphar@cyphar.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Al Viro <viro@zeniv.linux.org.uk>
Subject: [PATCH v2 2/8] fs: add two type safe mapping helpers
Date: Tue, 21 Jun 2022 16:14:48 +0200 [thread overview]
Message-ID: <20220621141454.2914719-3-brauner@kernel.org> (raw)
In-Reply-To: <20220621141454.2914719-1-brauner@kernel.org>
Introduce i_{g,u}id_into_vfs{g,u}id(). They return vfs{g,u}id_t. This
makes it way harder to confused idmapped mount {g,u}ids with filesystem
{g,u}ids.
The two helpers will eventually replace the old non type safe
i_{g,u}id_into_mnt() helpers once we finished converting all places. Add
a comment noting that they will be removed in the future.
All new helpers are nops on non-idmapped mounts.
Cc: Seth Forshee <sforshee@digitalocean.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Aleksa Sarai <cyphar@cyphar.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
CC: linux-fsdevel@vger.kernel.org
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
---
/* v2 */
- Linus Torvalds <torvalds@linux-foundation.org>:
- Rename s/kmnt{g,u}id_t/vfs{g,u}id_t/g
---
include/linux/fs.h | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 9ad5e3520fae..2c0e8d634bc4 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1600,6 +1600,9 @@ static inline void i_gid_write(struct inode *inode, gid_t gid)
* @mnt_userns: user namespace of the mount the inode was found from
* @inode: inode to map
*
+ * Note, this will eventually be removed completely in favor of the type-safe
+ * i_uid_into_vfsuid().
+ *
* Return: the inode's i_uid mapped down according to @mnt_userns.
* If the inode's i_uid has no mapping INVALID_UID is returned.
*/
@@ -1609,11 +1612,28 @@ static inline kuid_t i_uid_into_mnt(struct user_namespace *mnt_userns,
return mapped_kuid_fs(mnt_userns, i_user_ns(inode), inode->i_uid);
}
+/**
+ * i_uid_into_vfsuid - map an inode's i_uid down into a mnt_userns
+ * @mnt_userns: user namespace of the mount the inode was found from
+ * @inode: inode to map
+ *
+ * Return: whe inode's i_uid mapped down according to @mnt_userns.
+ * If the inode's i_uid has no mapping INVALID_VFSUID is returned.
+ */
+static inline vfsuid_t i_uid_into_vfsuid(struct user_namespace *mnt_userns,
+ const struct inode *inode)
+{
+ return VFSUIDT_INIT(i_uid_into_mnt(mnt_userns, inode));
+}
+
/**
* i_gid_into_mnt - map an inode's i_gid down into a mnt_userns
* @mnt_userns: user namespace of the mount the inode was found from
* @inode: inode to map
*
+ * Note, this will eventually be removed completely in favor of the type-safe
+ * i_gid_into_vfsgid().
+ *
* Return: the inode's i_gid mapped down according to @mnt_userns.
* If the inode's i_gid has no mapping INVALID_GID is returned.
*/
@@ -1623,6 +1643,20 @@ static inline kgid_t i_gid_into_mnt(struct user_namespace *mnt_userns,
return mapped_kgid_fs(mnt_userns, i_user_ns(inode), inode->i_gid);
}
+/**
+ * i_gid_into_mnt - map an inode's i_gid down into a mnt_userns
+ * @mnt_userns: user namespace of the mount the inode was found from
+ * @inode: inode to map
+ *
+ * Return: the inode's i_gid mapped down according to @mnt_userns.
+ * If the inode's i_gid has no mapping INVALID_VFSGID is returned.
+ */
+static inline vfsgid_t i_gid_into_vfsgid(struct user_namespace *mnt_userns,
+ const struct inode *inode)
+{
+ return VFSGIDT_INIT(i_gid_into_mnt(mnt_userns, inode));
+}
+
/**
* inode_fsuid_set - initialize inode's i_uid field with callers fsuid
* @inode: inode to initialize
--
2.34.1
next prev parent reply other threads:[~2022-06-21 14:15 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-21 14:14 [PATCH v2 0/8] introduce dedicated type for idmapped mounts Christian Brauner
2022-06-21 14:14 ` [PATCH v2 1/8] mnt_idmapping: add vfs{g,u}id_t Christian Brauner
2022-06-21 18:22 ` Seth Forshee
2022-06-22 4:10 ` Christian Brauner
2022-06-21 14:14 ` Christian Brauner [this message]
2022-06-21 14:14 ` [PATCH v2 3/8] fs: use mount types in iattr Christian Brauner
2022-06-21 14:14 ` [PATCH v2 4/8] fs: introduce tiny iattr ownership update helpers Christian Brauner
2022-06-21 14:14 ` [PATCH v2 5/8] fs: port to " Christian Brauner
2022-06-21 14:14 ` [PATCH v2 6/8] quota: port quota helpers mount ids Christian Brauner
2022-06-21 14:14 ` [PATCH v2 7/8] security: pass down mount idmapping to setattr hook Christian Brauner
2022-06-21 14:14 ` [PATCH v2 8/8] attr: port attribute changes to new types Christian Brauner
2022-06-21 17:33 ` Linus Torvalds
2022-06-22 4:06 ` Christian Brauner
2022-06-23 20:48 ` Seth Forshee
2022-06-23 21:03 ` Christian Brauner
2022-06-23 21:01 ` [PATCH v2 0/8] introduce dedicated type for idmapped mounts Seth Forshee
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=20220621141454.2914719-3-brauner@kernel.org \
--to=brauner@kernel.org \
--cc=cyphar@cyphar.com \
--cc=hch@lst.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=sforshee@digitalocean.com \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).