From: Glenn Washburn <development@efficientek.com>
To: Richard Weinberger <richard@nod.at>,
Anton Ivanov <anton.ivanov@cambridgegreys.com>,
Johannes Berg <johannes@sipsolutions.net>,
linux-um@lists.infradead.org
Cc: Glenn Washburn <development@efficientek.com>,
linux-kernel@vger.kernel.org,
Christian Brauner <brauner@kernel.org>,
Seth Forshee <sforshee@kernel.org>,
linux-fsdevel@vger.kernel.org
Subject: [RFC PATCH v2] hostfs: handle idmapped mounts
Date: Tue, 28 Feb 2023 19:50:02 -0600 [thread overview]
Message-ID: <20230301015002.2402544-1-development@efficientek.com> (raw)
Let hostfs handle idmapped mounts. This allows to have the same hostfs
mount appear in multiple locations with different id mappings.
root@(none):/media# id
uid=0(root) gid=0(root) groups=0(root)
root@(none):/media# mkdir mnt idmapped
root@(none):/media# mount -thostfs -o/home/user hostfs mnt
root@(none):/media# touch mnt/aaa
root@(none):/media# mount-idmapped --map-mount u:`id -u user`:0:1 --map-mount g:`id -g user`:0:1 /media/mnt /media/idmapped
root@(none):/media# ls -l mnt/aaa idmapped/aaa
-rw-r--r-- 1 root root 0 Jan 28 01:23 idmapped/aaa
-rw-r--r-- 1 user user 0 Jan 28 01:23 mnt/aaa
root@(none):/media# touch idmapped/bbb
root@(none):/media# ls -l mnt/bbb idmapped/bbb
-rw-r--r-- 1 root root 0 Jan 28 01:26 idmapped/bbb
-rw-r--r-- 1 user user 0 Jan 28 01:26 mnt/bbb
Signed-off-by: Glenn Washburn <development@efficientek.com>
---
Changes from v1:
* Rebase on to tip. The above commands work and have the results expected.
The __vfsuid_val(make_vfsuid(...)) seems ugly to get the uid_t, but it
seemed like the best one I've come across. Is there a better way?
Glenn
---
fs/hostfs/hostfs_kern.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index c18bb50c31b6..9459da99a0db 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -786,7 +786,7 @@ static int hostfs_permission(struct mnt_idmap *idmap,
err = access_file(name, r, w, x);
__putname(name);
if (!err)
- err = generic_permission(&nop_mnt_idmap, ino, desired);
+ err = generic_permission(idmap, ino, desired);
return err;
}
@@ -794,13 +794,14 @@ static int hostfs_setattr(struct mnt_idmap *idmap,
struct dentry *dentry, struct iattr *attr)
{
struct inode *inode = d_inode(dentry);
+ struct user_namespace *fs_userns = i_user_ns(inode);
struct hostfs_iattr attrs;
char *name;
int err;
int fd = HOSTFS_I(inode)->fd;
- err = setattr_prepare(&nop_mnt_idmap, dentry, attr);
+ err = setattr_prepare(idmap, dentry, attr);
if (err)
return err;
@@ -814,11 +815,11 @@ static int hostfs_setattr(struct mnt_idmap *idmap,
}
if (attr->ia_valid & ATTR_UID) {
attrs.ia_valid |= HOSTFS_ATTR_UID;
- attrs.ia_uid = from_kuid(&init_user_ns, attr->ia_uid);
+ attrs.ia_uid = __vfsuid_val(make_vfsuid(idmap, fs_userns, attr->ia_uid));
}
if (attr->ia_valid & ATTR_GID) {
attrs.ia_valid |= HOSTFS_ATTR_GID;
- attrs.ia_gid = from_kgid(&init_user_ns, attr->ia_gid);
+ attrs.ia_gid = __vfsgid_val(make_vfsgid(idmap, fs_userns, attr->ia_gid));
}
if (attr->ia_valid & ATTR_SIZE) {
attrs.ia_valid |= HOSTFS_ATTR_SIZE;
@@ -857,7 +858,7 @@ static int hostfs_setattr(struct mnt_idmap *idmap,
attr->ia_size != i_size_read(inode))
truncate_setsize(inode, attr->ia_size);
- setattr_copy(&nop_mnt_idmap, inode, attr);
+ setattr_copy(idmap, inode, attr);
mark_inode_dirty(inode);
return 0;
}
@@ -991,7 +992,7 @@ static struct file_system_type hostfs_type = {
.name = "hostfs",
.mount = hostfs_read_sb,
.kill_sb = hostfs_kill_sb,
- .fs_flags = 0,
+ .fs_flags = FS_ALLOW_IDMAP,
};
MODULE_ALIAS_FS("hostfs");
base-commit: 7fa08de735e41001a70c8ca869b2b159d74c2339
--
2.30.2
next reply other threads:[~2023-03-01 1:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-01 1:50 Glenn Washburn [this message]
2023-03-02 8:39 ` [RFC PATCH v2] hostfs: handle idmapped mounts Christian Brauner
2023-03-04 6:28 ` Glenn Washburn
2023-03-04 12:01 ` Christian Brauner
2023-03-16 6:20 ` Glenn Washburn
2023-03-16 10:37 ` Christian Brauner
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=20230301015002.2402544-1-development@efficientek.com \
--to=development@efficientek.com \
--cc=anton.ivanov@cambridgegreys.com \
--cc=brauner@kernel.org \
--cc=johannes@sipsolutions.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-um@lists.infradead.org \
--cc=richard@nod.at \
--cc=sforshee@kernel.org \
/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).