Commit 61ca2c4a authored by Sargun Dhillon's avatar Sargun Dhillon Committed by Anna Schumaker

NFS: Only reference user namespace from nfs4idmap struct instead of cred

The nfs4idmapper only needs access to the user namespace, and not the
entire cred struct. This replaces the struct cred* member with
struct user_namespace*. This is mostly hygiene, so we don't have to
hold onto the cred object, which has extraneous references to
things like user_struct. This also makes switching away
from init_user_ns more straightforward in the future.
Signed-off-by: default avatarSargun Dhillon <sargun@sargun.me>
Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
parent a2d24bcb
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include <keys/user-type.h> #include <keys/user-type.h>
#include <keys/request_key_auth-type.h> #include <keys/request_key_auth-type.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/user_namespace.h>
#include "internal.h" #include "internal.h"
#include "netns.h" #include "netns.h"
...@@ -69,13 +70,13 @@ struct idmap { ...@@ -69,13 +70,13 @@ struct idmap {
struct rpc_pipe *idmap_pipe; struct rpc_pipe *idmap_pipe;
struct idmap_legacy_upcalldata *idmap_upcall_data; struct idmap_legacy_upcalldata *idmap_upcall_data;
struct mutex idmap_mutex; struct mutex idmap_mutex;
const struct cred *cred; struct user_namespace *user_ns;
}; };
static struct user_namespace *idmap_userns(const struct idmap *idmap) static struct user_namespace *idmap_userns(const struct idmap *idmap)
{ {
if (idmap && idmap->cred) if (idmap && idmap->user_ns)
return idmap->cred->user_ns; return idmap->user_ns;
return &init_user_ns; return &init_user_ns;
} }
...@@ -286,7 +287,7 @@ static struct key *nfs_idmap_request_key(const char *name, size_t namelen, ...@@ -286,7 +287,7 @@ static struct key *nfs_idmap_request_key(const char *name, size_t namelen,
if (ret < 0) if (ret < 0)
return ERR_PTR(ret); return ERR_PTR(ret);
if (!idmap->cred || idmap->cred->user_ns == &init_user_ns) if (!idmap->user_ns || idmap->user_ns == &init_user_ns)
rkey = request_key(&key_type_id_resolver, desc, ""); rkey = request_key(&key_type_id_resolver, desc, "");
if (IS_ERR(rkey)) { if (IS_ERR(rkey)) {
mutex_lock(&idmap->idmap_mutex); mutex_lock(&idmap->idmap_mutex);
...@@ -462,7 +463,7 @@ nfs_idmap_new(struct nfs_client *clp) ...@@ -462,7 +463,7 @@ nfs_idmap_new(struct nfs_client *clp)
return -ENOMEM; return -ENOMEM;
mutex_init(&idmap->idmap_mutex); mutex_init(&idmap->idmap_mutex);
idmap->cred = get_cred(clp->cl_rpcclient->cl_cred); idmap->user_ns = get_user_ns(clp->cl_rpcclient->cl_cred->user_ns);
rpc_init_pipe_dir_object(&idmap->idmap_pdo, rpc_init_pipe_dir_object(&idmap->idmap_pdo,
&nfs_idmap_pipe_dir_object_ops, &nfs_idmap_pipe_dir_object_ops,
...@@ -486,7 +487,7 @@ nfs_idmap_new(struct nfs_client *clp) ...@@ -486,7 +487,7 @@ nfs_idmap_new(struct nfs_client *clp)
err_destroy_pipe: err_destroy_pipe:
rpc_destroy_pipe_data(idmap->idmap_pipe); rpc_destroy_pipe_data(idmap->idmap_pipe);
err: err:
put_cred(idmap->cred); get_user_ns(idmap->user_ns);
kfree(idmap); kfree(idmap);
return error; return error;
} }
...@@ -503,7 +504,7 @@ nfs_idmap_delete(struct nfs_client *clp) ...@@ -503,7 +504,7 @@ nfs_idmap_delete(struct nfs_client *clp)
&clp->cl_rpcclient->cl_pipedir_objects, &clp->cl_rpcclient->cl_pipedir_objects,
&idmap->idmap_pdo); &idmap->idmap_pdo);
rpc_destroy_pipe_data(idmap->idmap_pipe); rpc_destroy_pipe_data(idmap->idmap_pipe);
put_cred(idmap->cred); put_user_ns(idmap->user_ns);
kfree(idmap); kfree(idmap);
} }
......
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