From: Christian Brauner <brauner@kernel.org>
To: Christoph Hellwig <hch@lst.de>, Chris Mason <clm@fb.com>,
Josef Bacik <josef@toxicpanda.com>,
David Sterba <dsterba@suse.com>,
Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org,
Christian Brauner <christian.brauner@ubuntu.com>,
Christoph Hellwig <hch@infradead.org>
Subject: [PATCH 03/24] namei: handle mappings in lookup_positive_unlocked()
Date: Tue, 13 Jul 2021 13:13:23 +0200 [thread overview]
Message-ID: <20210713111344.1149376-4-brauner@kernel.org> (raw)
In-Reply-To: <20210713111344.1149376-1-brauner@kernel.org>
From: Christian Brauner <christian.brauner@ubuntu.com>
Various filesystems use the lookup_positive_unlocked() helper to lookup a
single path component relative to a well-known starting point. Allow such
filesystems to support idmapped mounts by enabling lookup_positive_unlocked()
to take the idmap into account when calling inode_permission(). This change is
a required to let btrfs (and other filesystems) support idmapped mounts.
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
---
fs/cifs/cifsfs.c | 3 ++-
fs/debugfs/inode.c | 3 ++-
fs/kernfs/mount.c | 4 ++--
fs/namei.c | 7 ++++---
fs/nfsd/nfs3xdr.c | 3 ++-
fs/nfsd/nfs4xdr.c | 3 ++-
fs/overlayfs/namei.c | 10 ++++++----
fs/quota/dquot.c | 3 ++-
include/linux/namei.h | 3 ++-
9 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index 64b71c4e2a9d..b61643427e46 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -804,7 +804,8 @@ cifs_get_root(struct smb3_fs_context *ctx, struct super_block *sb)
while (*s && *s != sep)
s++;
- child = lookup_positive_unlocked(p, dentry, s - p);
+ child = lookup_positive_unlocked(&init_user_ns, p,
+ dentry, s - p);
dput(dentry);
dentry = child;
} while (!IS_ERR(dentry));
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 92db343f35f4..eda31d0966a5 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -307,7 +307,8 @@ struct dentry *debugfs_lookup(const char *name, struct dentry *parent)
if (!parent)
parent = debugfs_mount->mnt_root;
- dentry = lookup_positive_unlocked(name, parent, strlen(name));
+ dentry = lookup_positive_unlocked(&init_user_ns, name,
+ parent, strlen(name));
if (IS_ERR(dentry))
return NULL;
return dentry;
diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c
index 9dc7e7a64e10..20b8617e619b 100644
--- a/fs/kernfs/mount.c
+++ b/fs/kernfs/mount.c
@@ -223,8 +223,8 @@ struct dentry *kernfs_node_dentry(struct kernfs_node *kn,
dput(dentry);
return ERR_PTR(-EINVAL);
}
- dtmp = lookup_positive_unlocked(kntmp->name, dentry,
- strlen(kntmp->name));
+ dtmp = lookup_positive_unlocked(&init_user_ns, kntmp->name,
+ dentry, strlen(kntmp->name));
dput(dentry);
if (IS_ERR(dtmp))
return dtmp;
diff --git a/fs/namei.c b/fs/namei.c
index 53561311b492..68489c23bc44 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -2706,10 +2706,11 @@ EXPORT_SYMBOL(lookup_one_len_unlocked);
* need to be very careful; pinned positives have ->d_inode stable, so
* this one avoids such problems.
*/
-struct dentry *lookup_positive_unlocked(const char *name,
- struct dentry *base, int len)
+struct dentry *lookup_positive_unlocked(struct user_namespace *mnt_userns,
+ const char *name, struct dentry *base,
+ int len)
{
- struct dentry *ret = lookup_one_len_unlocked(&init_user_ns, name, base, len);
+ struct dentry *ret = lookup_one_len_unlocked(mnt_userns, name, base, len);
if (!IS_ERR(ret) && d_flags_negative(smp_load_acquire(&ret->d_flags))) {
dput(ret);
ret = ERR_PTR(-ENOENT);
diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c
index 0a5ebc52e6a9..0fad12be94cd 100644
--- a/fs/nfsd/nfs3xdr.c
+++ b/fs/nfsd/nfs3xdr.c
@@ -1109,7 +1109,8 @@ compose_entry_fh(struct nfsd3_readdirres *cd, struct svc_fh *fhp,
} else
dchild = dget(dparent);
} else
- dchild = lookup_positive_unlocked(name, dparent, namlen);
+ dchild = lookup_positive_unlocked(&init_user_ns, name,
+ dparent, namlen);
if (IS_ERR(dchild))
return rv;
if (d_mountpoint(dchild))
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 7abeccb975b2..a0425d120e6a 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3413,7 +3413,8 @@ nfsd4_encode_dirent_fattr(struct xdr_stream *xdr, struct nfsd4_readdir *cd,
__be32 nfserr;
int ignore_crossmnt = 0;
- dentry = lookup_positive_unlocked(name, cd->rd_fhp->fh_dentry, namlen);
+ dentry = lookup_positive_unlocked(&init_user_ns, name,
+ cd->rd_fhp->fh_dentry, namlen);
if (IS_ERR(dentry))
return nfserrno(PTR_ERR(dentry));
diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c
index 291985b79a6d..52721af35dcf 100644
--- a/fs/overlayfs/namei.c
+++ b/fs/overlayfs/namei.c
@@ -673,7 +673,8 @@ struct dentry *ovl_get_index_fh(struct ovl_fs *ofs, struct ovl_fh *fh)
if (err)
return ERR_PTR(err);
- index = lookup_positive_unlocked(name.name, ofs->indexdir, name.len);
+ index = lookup_positive_unlocked(&init_user_ns, name.name,
+ ofs->indexdir, name.len);
kfree(name.name);
if (IS_ERR(index)) {
if (PTR_ERR(index) == -ENOENT)
@@ -705,7 +706,8 @@ struct dentry *ovl_lookup_index(struct ovl_fs *ofs, struct dentry *upper,
if (err)
return ERR_PTR(err);
- index = lookup_positive_unlocked(name.name, ofs->indexdir, name.len);
+ index = lookup_positive_unlocked(&init_user_ns, name.name,
+ ofs->indexdir, name.len);
if (IS_ERR(index)) {
err = PTR_ERR(index);
if (err == -ENOENT) {
@@ -1164,8 +1166,8 @@ bool ovl_lower_positive(struct dentry *dentry)
struct dentry *this;
struct dentry *lowerdir = poe->lowerstack[i].dentry;
- this = lookup_positive_unlocked(name->name, lowerdir,
- name->len);
+ this = lookup_positive_unlocked(&init_user_ns, name->name,
+ lowerdir, name->len);
if (IS_ERR(this)) {
switch (PTR_ERR(this)) {
case -ENOENT:
diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c
index 22d904bde6ab..8cdd6df7597a 100644
--- a/fs/quota/dquot.c
+++ b/fs/quota/dquot.c
@@ -2487,7 +2487,8 @@ int dquot_quota_on_mount(struct super_block *sb, char *qf_name,
struct dentry *dentry;
int error;
- dentry = lookup_positive_unlocked(qf_name, sb->s_root, strlen(qf_name));
+ dentry = lookup_positive_unlocked(&init_user_ns, qf_name,
+ sb->s_root, strlen(qf_name));
if (IS_ERR(dentry))
return PTR_ERR(dentry);
diff --git a/include/linux/namei.h b/include/linux/namei.h
index b4073e36450a..c177edfb2364 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -69,7 +69,8 @@ extern struct dentry *lookup_one_len(struct user_namespace *mnt_userns,
const char *, struct dentry *, int);
extern struct dentry *lookup_one_len_unlocked(struct user_namespace *,
const char *, struct dentry *, int);
-extern struct dentry *lookup_positive_unlocked(const char *, struct dentry *, int);
+extern struct dentry *lookup_positive_unlocked(struct user_namespace *,
+ const char *, struct dentry *, int);
extern int follow_down_one(struct path *);
extern int follow_down(struct path *);
--
2.30.2
next prev parent reply other threads:[~2021-07-13 11:15 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-13 11:13 [PATCH 00/24] btrfs: support idmapped mounts Christian Brauner
2021-07-13 11:13 ` [PATCH 01/24] namei: handle mappings in lookup_one_len() Christian Brauner
2021-07-13 13:32 ` Al Viro
2021-07-13 13:41 ` Christian Brauner
2021-07-13 11:13 ` [PATCH 02/24] namei: handle mappings in lookup_one_len_unlocked() Christian Brauner
2021-07-13 13:34 ` Al Viro
2021-07-13 11:13 ` Christian Brauner [this message]
2021-07-13 11:13 ` [PATCH 04/24] namei: handle mappings in try_lookup_one_len() Christian Brauner
2021-07-13 11:13 ` [PATCH 05/24] btrfs/inode: handle idmaps in btrfs_new_inode() Christian Brauner
2021-07-13 11:13 ` [PATCH 06/24] btrfs/inode: allow idmapped rename iop Christian Brauner
2021-07-13 11:13 ` [PATCH 07/24] btrfs/inode: allow idmapped getattr iop Christian Brauner
2021-07-13 11:13 ` [PATCH 08/24] btrfs/inode: allow idmapped mknod iop Christian Brauner
2021-07-13 11:13 ` [PATCH 09/24] btrfs/inode: allow idmapped create iop Christian Brauner
2021-07-13 11:13 ` [PATCH 10/24] btrfs/inode: allow idmapped mkdir iop Christian Brauner
2021-07-13 11:13 ` [PATCH 11/24] btrfs/inode: allow idmapped symlink iop Christian Brauner
2021-07-13 11:13 ` [PATCH 12/24] btrfs/inode: allow idmapped tmpfile iop Christian Brauner
2021-07-13 11:13 ` [PATCH 13/24] btrfs/inode: allow idmapped setattr iop Christian Brauner
2021-07-13 11:13 ` [PATCH 14/24] btrfs/inode: allow idmapped permission iop Christian Brauner
2021-07-13 11:13 ` [PATCH 15/24] btrfs/ioctl: check whether fs{g,u}id are mapped during subvolume creation Christian Brauner
2021-07-13 11:13 ` [PATCH 16/24] btrfs/inode: allow idmapped BTRFS_IOC_{SNAP,SUBVOL}_CREATE{_V2} ioctl Christian Brauner
2021-07-13 11:13 ` [PATCH 17/24] btrfs/ioctl: allow idmapped BTRFS_IOC_SNAP_DESTROY{_V2} ioctl Christian Brauner
2021-07-14 1:00 ` Qu Wenruo
2021-07-13 11:13 ` [PATCH 18/24] btrfs/ioctl: relax restrictions for BTRFS_IOC_SNAP_DESTROY_V2 with subvolids Christian Brauner
2021-07-13 11:13 ` [PATCH 19/24] btrfs/ioctl: allow idmapped BTRFS_IOC_SET_RECEIVED_SUBVOL{_32} ioctl Christian Brauner
2021-07-13 11:13 ` [PATCH 20/24] btrfs/ioctl: allow idmapped BTRFS_IOC_SUBVOL_SETFLAGS ioctl Christian Brauner
2021-07-13 11:13 ` [PATCH 21/24] btrfs/ioctl: allow idmapped BTRFS_IOC_INO_LOOKUP_USER ioctl Christian Brauner
2021-07-13 11:13 ` [PATCH 22/24] btrfs/acl: handle idmapped mounts Christian Brauner
2021-07-13 11:13 ` [PATCH 23/24] btrfs/super: allow idmapped btrfs Christian Brauner
2021-07-13 11:13 ` [PATCH 24/24] btrfs/242: introduce btrfs specific idmapped mounts tests Christian Brauner
2021-07-13 11:23 ` [PATCH 00/24] btrfs: support idmapped mounts Qu Wenruo
2021-07-13 13:59 ` 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=20210713111344.1149376-4-brauner@kernel.org \
--to=brauner@kernel.org \
--cc=christian.brauner@ubuntu.com \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=hch@infradead.org \
--cc=hch@lst.de \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.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).