Commit f05d147f authored by Bryan Schumaker's avatar Bryan Schumaker Committed by Trond Myklebust

NFS: Fix following referral mount points with different security

I create a new proc_lookup_mountpoint() to use when submounting an NFS
v4 share.  This function returns an rpc_clnt to use for performing an
fs_locations() call on a referral's mountpoint.
Signed-off-by: default avatarBryan Schumaker <bjschuma@netapp.com>
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 72de53ec
...@@ -186,10 +186,10 @@ static inline void nfs_fs_proc_exit(void) ...@@ -186,10 +186,10 @@ static inline void nfs_fs_proc_exit(void)
/* nfs4namespace.c */ /* nfs4namespace.c */
#ifdef CONFIG_NFS_V4 #ifdef CONFIG_NFS_V4
extern struct vfsmount *nfs_do_refmount(struct dentry *dentry); extern struct vfsmount *nfs_do_refmount(struct rpc_clnt *client, struct dentry *dentry);
#else #else
static inline static inline
struct vfsmount *nfs_do_refmount(struct dentry *dentry) struct vfsmount *nfs_do_refmount(struct rpc_clnt *client, struct dentry *dentry)
{ {
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
} }
......
...@@ -200,6 +200,22 @@ static int nfs_lookup_with_sec(struct nfs_server *server, struct dentry *parent, ...@@ -200,6 +200,22 @@ static int nfs_lookup_with_sec(struct nfs_server *server, struct dentry *parent,
out: out:
return err; return err;
} }
static struct rpc_clnt *nfs_lookup_mountpoint(struct inode *dir,
struct qstr *name,
struct nfs_fh *fh,
struct nfs_fattr *fattr)
{
int err;
if (NFS_PROTO(dir)->version == 4)
return nfs4_proc_lookup_mountpoint(dir, name, fh, fattr);
err = NFS_PROTO(dir)->lookup(NFS_SERVER(dir)->client, dir, name, fh, fattr);
if (err)
return ERR_PTR(err);
return rpc_clone_client(NFS_SERVER(dir)->client);
}
#else /* CONFIG_NFS_V4 */ #else /* CONFIG_NFS_V4 */
static inline int nfs_lookup_with_sec(struct nfs_server *server, static inline int nfs_lookup_with_sec(struct nfs_server *server,
struct dentry *parent, struct dentry *dentry, struct dentry *parent, struct dentry *dentry,
...@@ -209,6 +225,17 @@ static inline int nfs_lookup_with_sec(struct nfs_server *server, ...@@ -209,6 +225,17 @@ static inline int nfs_lookup_with_sec(struct nfs_server *server,
{ {
return -EPERM; return -EPERM;
} }
static inline struct rpc_clnt *nfs_lookup_mountpoint(struct inode *dir,
struct qstr *name,
struct nfs_fh *fh,
struct nfs_fattr *fattr)
{
int err = NFS_PROTO(dir)->lookup(NFS_SERVER(dir)->client, dir, name, fh, fattr);
if (err)
return ERR_PTR(err);
return rpc_clone_client(NFS_SERVER(dir)->client);
}
#endif /* CONFIG_NFS_V4 */ #endif /* CONFIG_NFS_V4 */
/* /*
...@@ -226,11 +253,10 @@ static inline int nfs_lookup_with_sec(struct nfs_server *server, ...@@ -226,11 +253,10 @@ static inline int nfs_lookup_with_sec(struct nfs_server *server,
struct vfsmount *nfs_d_automount(struct path *path) struct vfsmount *nfs_d_automount(struct path *path)
{ {
struct vfsmount *mnt; struct vfsmount *mnt;
struct nfs_server *server = NFS_SERVER(path->dentry->d_inode);
struct dentry *parent; struct dentry *parent;
struct nfs_fh *fh = NULL; struct nfs_fh *fh = NULL;
struct nfs_fattr *fattr = NULL; struct nfs_fattr *fattr = NULL;
int err; struct rpc_clnt *client;
rpc_authflavor_t flavor = RPC_AUTH_UNIX; rpc_authflavor_t flavor = RPC_AUTH_UNIX;
dprintk("--> nfs_d_automount()\n"); dprintk("--> nfs_d_automount()\n");
...@@ -249,21 +275,19 @@ struct vfsmount *nfs_d_automount(struct path *path) ...@@ -249,21 +275,19 @@ struct vfsmount *nfs_d_automount(struct path *path)
/* Look it up again to get its attributes */ /* Look it up again to get its attributes */
parent = dget_parent(path->dentry); parent = dget_parent(path->dentry);
err = server->nfs_client->rpc_ops->lookup(server->client, parent->d_inode, client = nfs_lookup_mountpoint(parent->d_inode, &path->dentry->d_name, fh, fattr);
&path->dentry->d_name,
fh, fattr);
if (err == -EPERM && NFS_PROTO(parent->d_inode)->secinfo != NULL)
err = nfs_lookup_with_sec(server, parent, path->dentry, path, fh, fattr, &flavor);
dput(parent); dput(parent);
if (err != 0) { if (IS_ERR(client)) {
mnt = ERR_PTR(err); mnt = ERR_CAST(client);
goto out; goto out;
} }
if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL)
mnt = nfs_do_refmount(path->dentry); mnt = nfs_do_refmount(client, path->dentry);
else else
mnt = nfs_do_submount(path->dentry, fh, fattr, flavor); mnt = nfs_do_submount(path->dentry, fh, fattr, flavor);
rpc_shutdown_client(client);
if (IS_ERR(mnt)) if (IS_ERR(mnt))
goto out; goto out;
......
...@@ -216,8 +216,10 @@ extern int nfs4_init_clientid(struct nfs_client *, struct rpc_cred *); ...@@ -216,8 +216,10 @@ extern int nfs4_init_clientid(struct nfs_client *, struct rpc_cred *);
extern int nfs41_init_clientid(struct nfs_client *, struct rpc_cred *); extern int nfs41_init_clientid(struct nfs_client *, struct rpc_cred *);
extern int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait, bool roc); extern int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait, bool roc);
extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle); extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle);
extern int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, extern int nfs4_proc_fs_locations(struct rpc_clnt *, struct inode *, const struct qstr *,
struct nfs4_fs_locations *fs_locations, struct page *page); struct nfs4_fs_locations *, struct page *);
extern struct rpc_clnt *nfs4_proc_lookup_mountpoint(struct inode *, struct qstr *,
struct nfs_fh *, struct nfs_fattr *);
extern int nfs4_proc_secinfo(struct inode *, const struct qstr *, struct nfs4_secinfo_flavors *); extern int nfs4_proc_secinfo(struct inode *, const struct qstr *, struct nfs4_secinfo_flavors *);
extern int nfs4_release_lockowner(struct nfs4_lock_state *); extern int nfs4_release_lockowner(struct nfs4_lock_state *);
extern const struct xattr_handler *nfs4_xattr_handlers[]; extern const struct xattr_handler *nfs4_xattr_handlers[];
......
...@@ -300,7 +300,7 @@ static struct vfsmount *nfs_follow_referral(struct dentry *dentry, ...@@ -300,7 +300,7 @@ static struct vfsmount *nfs_follow_referral(struct dentry *dentry,
* @dentry - dentry of referral * @dentry - dentry of referral
* *
*/ */
struct vfsmount *nfs_do_refmount(struct dentry *dentry) struct vfsmount *nfs_do_refmount(struct rpc_clnt *client, struct dentry *dentry)
{ {
struct vfsmount *mnt = ERR_PTR(-ENOMEM); struct vfsmount *mnt = ERR_PTR(-ENOMEM);
struct dentry *parent; struct dentry *parent;
...@@ -326,7 +326,7 @@ struct vfsmount *nfs_do_refmount(struct dentry *dentry) ...@@ -326,7 +326,7 @@ struct vfsmount *nfs_do_refmount(struct dentry *dentry)
dprintk("%s: getting locations for %s/%s\n", dprintk("%s: getting locations for %s/%s\n",
__func__, parent->d_name.name, dentry->d_name.name); __func__, parent->d_name.name, dentry->d_name.name);
err = nfs4_proc_fs_locations(parent->d_inode, &dentry->d_name, fs_locations, page); err = nfs4_proc_fs_locations(client, parent->d_inode, &dentry->d_name, fs_locations, page);
dput(parent); dput(parent);
if (err != 0 || if (err != 0 ||
fs_locations->nlocations <= 0 || fs_locations->nlocations <= 0 ||
......
...@@ -2377,8 +2377,9 @@ static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, ...@@ -2377,8 +2377,9 @@ static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
* Note that we'll actually follow the referral later when * Note that we'll actually follow the referral later when
* we detect fsid mismatch in inode revalidation * we detect fsid mismatch in inode revalidation
*/ */
static int nfs4_get_referral(struct inode *dir, const struct qstr *name, static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir,
struct nfs_fattr *fattr, struct nfs_fh *fhandle) const struct qstr *name, struct nfs_fattr *fattr,
struct nfs_fh *fhandle)
{ {
int status = -ENOMEM; int status = -ENOMEM;
struct page *page = NULL; struct page *page = NULL;
...@@ -2391,7 +2392,7 @@ static int nfs4_get_referral(struct inode *dir, const struct qstr *name, ...@@ -2391,7 +2392,7 @@ static int nfs4_get_referral(struct inode *dir, const struct qstr *name,
if (locations == NULL) if (locations == NULL)
goto out; goto out;
status = nfs4_proc_fs_locations(dir, name, locations, page); status = nfs4_proc_fs_locations(client, dir, name, locations, page);
if (status != 0) if (status != 0)
goto out; goto out;
/* Make sure server returned a different fsid for the referral */ /* Make sure server returned a different fsid for the referral */
...@@ -2550,7 +2551,7 @@ static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, ...@@ -2550,7 +2551,7 @@ static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir,
err = -ENOENT; err = -ENOENT;
goto out; goto out;
case -NFS4ERR_MOVED: case -NFS4ERR_MOVED:
err = nfs4_get_referral(dir, name, fattr, fhandle); err = nfs4_get_referral(client, dir, name, fattr, fhandle);
goto out; goto out;
case -NFS4ERR_WRONGSEC: case -NFS4ERR_WRONGSEC:
err = -EPERM; err = -EPERM;
...@@ -2591,6 +2592,21 @@ static int nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, struct qst ...@@ -2591,6 +2592,21 @@ static int nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, struct qst
return status; return status;
} }
struct rpc_clnt *
nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name,
struct nfs_fh *fhandle, struct nfs_fattr *fattr)
{
int status;
struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir));
status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr);
if (status < 0) {
rpc_shutdown_client(client);
return ERR_PTR(status);
}
return client;
}
static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
{ {
struct nfs_server *server = NFS_SERVER(inode); struct nfs_server *server = NFS_SERVER(inode);
...@@ -4951,8 +4967,10 @@ static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) ...@@ -4951,8 +4967,10 @@ static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr)
fattr->nlink = 2; fattr->nlink = 2;
} }
static int _nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir,
struct nfs4_fs_locations *fs_locations, struct page *page) const struct qstr *name,
struct nfs4_fs_locations *fs_locations,
struct page *page)
{ {
struct nfs_server *server = NFS_SERVER(dir); struct nfs_server *server = NFS_SERVER(dir);
u32 bitmask[2] = { u32 bitmask[2] = {
...@@ -4986,19 +5004,21 @@ static int _nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, ...@@ -4986,19 +5004,21 @@ static int _nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name,
nfs_fattr_init(&fs_locations->fattr); nfs_fattr_init(&fs_locations->fattr);
fs_locations->server = server; fs_locations->server = server;
fs_locations->nlocations = 0; fs_locations->nlocations = 0;
status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); status = nfs4_call_sync(client, server, &msg, &args.seq_args, &res.seq_res, 0);
dprintk("%s: returned status = %d\n", __func__, status); dprintk("%s: returned status = %d\n", __func__, status);
return status; return status;
} }
int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir,
struct nfs4_fs_locations *fs_locations, struct page *page) const struct qstr *name,
struct nfs4_fs_locations *fs_locations,
struct page *page)
{ {
struct nfs4_exception exception = { }; struct nfs4_exception exception = { };
int err; int err;
do { do {
err = nfs4_handle_exception(NFS_SERVER(dir), err = nfs4_handle_exception(NFS_SERVER(dir),
_nfs4_proc_fs_locations(dir, name, fs_locations, page), _nfs4_proc_fs_locations(client, dir, name, fs_locations, page),
&exception); &exception);
} while (exception.retry); } while (exception.retry);
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment