]> git.dujemihanovic.xyz Git - linux.git/commitdiff
nfsd: Pass 'cred' instead of 'rqstp' to some functions.
authorNeilBrown <neilb@suse.de>
Fri, 26 Jul 2024 02:21:31 +0000 (12:21 +1000)
committerChuck Lever <chuck.lever@oracle.com>
Fri, 20 Sep 2024 23:31:03 +0000 (19:31 -0400)
nfsd_permission(), exp_rdonly(), nfsd_setuser(), and nfsexp_flags()
only ever need the cred out of rqstp, so pass it explicitly instead of
the whole rqstp.

This makes the interfaces cleaner.

Signed-off-by: NeilBrown <neilb@suse.de>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
fs/nfsd/auth.c
fs/nfsd/auth.h
fs/nfsd/export.h
fs/nfsd/nfs4state.c
fs/nfsd/nfsfh.c
fs/nfsd/nfsproc.c
fs/nfsd/vfs.c
fs/nfsd/vfs.h

index e6beaaf4f1700b0ac78d05128dc23fd74c902dcb..93e33d1ee8917fc5d462f56b5c65380f7555e638 100644 (file)
@@ -5,26 +5,26 @@
 #include "nfsd.h"
 #include "auth.h"
 
-int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
+int nfsexp_flags(struct svc_cred *cred, struct svc_export *exp)
 {
        struct exp_flavor_info *f;
        struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors;
 
        for (f = exp->ex_flavors; f < end; f++) {
-               if (f->pseudoflavor == rqstp->rq_cred.cr_flavor)
+               if (f->pseudoflavor == cred->cr_flavor)
                        return f->flags;
        }
        return exp->ex_flags;
 
 }
 
-int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)
+int nfsd_setuser(struct svc_cred *cred, struct svc_export *exp)
 {
        struct group_info *rqgi;
        struct group_info *gi;
        struct cred *new;
        int i;
-       int flags = nfsexp_flags(rqstp, exp);
+       int flags = nfsexp_flags(cred, exp);
 
        /* discard any old override before preparing the new set */
        revert_creds(get_cred(current_real_cred()));
@@ -32,10 +32,10 @@ int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)
        if (!new)
                return -ENOMEM;
 
-       new->fsuid = rqstp->rq_cred.cr_uid;
-       new->fsgid = rqstp->rq_cred.cr_gid;
+       new->fsuid = cred->cr_uid;
+       new->fsgid = cred->cr_gid;
 
-       rqgi = rqstp->rq_cred.cr_group_info;
+       rqgi = cred->cr_group_info;
 
        if (flags & NFSEXP_ALLSQUASH) {
                new->fsuid = exp->ex_anon_uid;
index dbd66424f600be9faff713408c12eb6499194e06..8c5031bbbcee2f5176cf9cad20d54687bb9c5352 100644 (file)
@@ -12,6 +12,6 @@
  * Set the current process's fsuid/fsgid etc to those of the NFS
  * client user
  */
-int nfsd_setuser(struct svc_rqst *, struct svc_export *);
+int nfsd_setuser(struct svc_cred *cred, struct svc_export *exp);
 
 #endif /* LINUX_NFSD_AUTH_H */
index cb17f05e332902e58250f601ce9dddae44bb27ba..3794ae253a7016dd6257b5711d85c718d56ef78c 100644 (file)
@@ -99,7 +99,8 @@ struct svc_expkey {
 #define EX_NOHIDE(exp)         ((exp)->ex_flags & NFSEXP_NOHIDE)
 #define EX_WGATHER(exp)                ((exp)->ex_flags & NFSEXP_GATHERED_WRITES)
 
-int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp);
+struct svc_cred;
+int nfsexp_flags(struct svc_cred *cred, struct svc_export *exp);
 __be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp);
 
 /*
index 8fddc2d1c80eadd2261bfce8e80c410f1a14d8e2..e18b7ef14f59f14041ce9ea8cc8255fa15793235 100644 (file)
@@ -6891,7 +6891,8 @@ nfs4_check_file(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfs4_stid *s,
 
        nf = nfs4_find_file(s, flags);
        if (nf) {
-               status = nfsd_permission(rqstp, fhp->fh_export, fhp->fh_dentry,
+               status = nfsd_permission(&rqstp->rq_cred,
+                                        fhp->fh_export, fhp->fh_dentry,
                                acc | NFSD_MAY_OWNER_OVERRIDE);
                if (status) {
                        nfsd_file_put(nf);
index 17d40600e02c3d753fa5bbbd87b9dae127ffeec7..fffeba0825400b6b63e7ff085a5bdae682297254 100644 (file)
@@ -102,7 +102,7 @@ static bool nfsd_originating_port_ok(struct svc_rqst *rqstp, int flags)
 static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp,
                                          struct svc_export *exp)
 {
-       int flags = nfsexp_flags(rqstp, exp);
+       int flags = nfsexp_flags(&rqstp->rq_cred, exp);
 
        /* Check if the request originated from a secure port. */
        if (!nfsd_originating_port_ok(rqstp, flags)) {
@@ -113,7 +113,7 @@ static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp,
        }
 
        /* Set user creds for this exportpoint */
-       return nfserrno(nfsd_setuser(rqstp, exp));
+       return nfserrno(nfsd_setuser(&rqstp->rq_cred, exp));
 }
 
 static inline __be32 check_pseudo_root(struct svc_rqst *rqstp,
@@ -394,7 +394,7 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, int access)
 
 skip_pseudoflavor_check:
        /* Finally, check access permissions. */
-       error = nfsd_permission(rqstp, exp, dentry, access);
+       error = nfsd_permission(&rqstp->rq_cred, exp, dentry, access);
 out:
        trace_nfsd_fh_verify_err(rqstp, fhp, type, access, error);
        if (error == nfserr_stale)
index 36370b957b63378f023005b73d0af27363d564e0..97aab34593ef0d59a34b09326e921091680765c7 100644 (file)
@@ -331,10 +331,11 @@ nfsd_proc_create(struct svc_rqst *rqstp)
                                         *   echo thing > device-special-file-or-pipe
                                         * by doing a CREATE with type==0
                                         */
-                                       resp->status = nfsd_permission(rqstp,
-                                                                newfhp->fh_export,
-                                                                newfhp->fh_dentry,
-                                                                NFSD_MAY_WRITE|NFSD_MAY_LOCAL_ACCESS);
+                                       resp->status = nfsd_permission(
+                                               &rqstp->rq_cred,
+                                               newfhp->fh_export,
+                                               newfhp->fh_dentry,
+                                               NFSD_MAY_WRITE|NFSD_MAY_LOCAL_ACCESS);
                                        if (resp->status && resp->status != nfserr_rofs)
                                                goto out_unlock;
                                }
index 29b1f3613800a360cc126d2f8a5803824c3eab8b..0862f6ae86a9c6fd0c4963a9354bee231213f89a 100644 (file)
@@ -421,8 +421,9 @@ nfsd_get_write_access(struct svc_rqst *rqstp, struct svc_fh *fhp,
        if (iap->ia_size < inode->i_size) {
                __be32 err;
 
-               err = nfsd_permission(rqstp, fhp->fh_export, fhp->fh_dentry,
-                               NFSD_MAY_TRUNC | NFSD_MAY_OWNER_OVERRIDE);
+               err = nfsd_permission(&rqstp->rq_cred,
+                                     fhp->fh_export, fhp->fh_dentry,
+                                     NFSD_MAY_TRUNC | NFSD_MAY_OWNER_OVERRIDE);
                if (err)
                        return err;
        }
@@ -814,7 +815,8 @@ nfsd_access(struct svc_rqst *rqstp, struct svc_fh *fhp, u32 *access, u32 *suppor
 
                        sresult |= map->access;
 
-                       err2 = nfsd_permission(rqstp, export, dentry, map->how);
+                       err2 = nfsd_permission(&rqstp->rq_cred, export,
+                                              dentry, map->how);
                        switch (err2) {
                        case nfs_ok:
                                result |= map->access;
@@ -1475,7 +1477,8 @@ nfsd_create_locked(struct svc_rqst *rqstp, struct svc_fh *fhp,
        dirp = d_inode(dentry);
 
        dchild = dget(resfhp->fh_dentry);
-       err = nfsd_permission(rqstp, fhp->fh_export, dentry, NFSD_MAY_CREATE);
+       err = nfsd_permission(&rqstp->rq_cred, fhp->fh_export, dentry,
+                             NFSD_MAY_CREATE);
        if (err)
                goto out;
 
@@ -2255,9 +2258,9 @@ nfsd_statfs(struct svc_rqst *rqstp, struct svc_fh *fhp, struct kstatfs *stat, in
        return err;
 }
 
-static int exp_rdonly(struct svc_rqst *rqstp, struct svc_export *exp)
+static int exp_rdonly(struct svc_cred *cred, struct svc_export *exp)
 {
-       return nfsexp_flags(rqstp, exp) & NFSEXP_READONLY;
+       return nfsexp_flags(cred, exp) & NFSEXP_READONLY;
 }
 
 #ifdef CONFIG_NFSD_V4
@@ -2501,8 +2504,8 @@ out_unlock:
  * Check for a user's access permissions to this inode.
  */
 __be32
-nfsd_permission(struct svc_rqst *rqstp, struct svc_export *exp,
-                                       struct dentry *dentry, int acc)
+nfsd_permission(struct svc_cred *cred, struct svc_export *exp,
+               struct dentry *dentry, int acc)
 {
        struct inode    *inode = d_inode(dentry);
        int             err;
@@ -2533,7 +2536,7 @@ nfsd_permission(struct svc_rqst *rqstp, struct svc_export *exp,
         */
        if (!(acc & NFSD_MAY_LOCAL_ACCESS))
                if (acc & (NFSD_MAY_WRITE | NFSD_MAY_SATTR | NFSD_MAY_TRUNC)) {
-                       if (exp_rdonly(rqstp, exp) ||
+                       if (exp_rdonly(cred, exp) ||
                            __mnt_is_readonly(exp->ex_path.mnt))
                                return nfserr_rofs;
                        if (/* (acc & NFSD_MAY_WRITE) && */ IS_IMMUTABLE(inode))
index 57cd70062048f50fcdd5a85a983201464362935d..01947561d3752f15b0af2d10f143e63e2746c19f 100644 (file)
@@ -153,8 +153,8 @@ __be32              nfsd_readdir(struct svc_rqst *, struct svc_fh *,
 __be32         nfsd_statfs(struct svc_rqst *, struct svc_fh *,
                                struct kstatfs *, int access);
 
-__be32         nfsd_permission(struct svc_rqst *, struct svc_export *,
-                               struct dentry *, int);
+__be32         nfsd_permission(struct svc_cred *cred, struct svc_export *exp,
+                               struct dentry *dentry, int acc);
 
 void           nfsd_filp_close(struct file *fp);