Skip to content

Commit b0d87db

Browse files
neilbrownAnna Schumaker
authored andcommitted
NFSD: Refactor nfsd_setuser_and_check_port()
There are several places where __fh_verify unconditionally dereferences rqstp to check that the connection is suitably secure. They look at rqstp->rq_xprt which is not meaningful in the target use case of "localio" NFS in which the client talks directly to the local server. Prepare these to always succeed when rqstp is NULL. Signed-off-by: NeilBrown <[email protected]> Co-developed-by: Mike Snitzer <[email protected]> Signed-off-by: Mike Snitzer <[email protected]> Signed-off-by: Chuck Lever <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent 0a183f2 commit b0d87db

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

fs/nfsd/nfsfh.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,31 +87,32 @@ nfsd_mode_check(struct dentry *dentry, umode_t requested)
8787
return nfserr_wrong_type;
8888
}
8989

90-
static bool nfsd_originating_port_ok(struct svc_rqst *rqstp, int flags)
90+
static bool nfsd_originating_port_ok(struct svc_rqst *rqstp,
91+
struct svc_cred *cred,
92+
struct svc_export *exp)
9193
{
92-
if (flags & NFSEXP_INSECURE_PORT)
94+
if (nfsexp_flags(cred, exp) & NFSEXP_INSECURE_PORT)
9395
return true;
9496
/* We don't require gss requests to use low ports: */
95-
if (rqstp->rq_cred.cr_flavor >= RPC_AUTH_GSS)
97+
if (cred->cr_flavor >= RPC_AUTH_GSS)
9698
return true;
9799
return test_bit(RQ_SECURE, &rqstp->rq_flags);
98100
}
99101

100102
static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp,
103+
struct svc_cred *cred,
101104
struct svc_export *exp)
102105
{
103-
int flags = nfsexp_flags(&rqstp->rq_cred, exp);
104-
105106
/* Check if the request originated from a secure port. */
106-
if (!nfsd_originating_port_ok(rqstp, flags)) {
107+
if (rqstp && !nfsd_originating_port_ok(rqstp, cred, exp)) {
107108
RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]);
108109
dprintk("nfsd: request from insecure port %s!\n",
109110
svc_print_addr(rqstp, buf, sizeof(buf)));
110111
return nfserr_perm;
111112
}
112113

113114
/* Set user creds for this exportpoint */
114-
return nfserrno(nfsd_setuser(&rqstp->rq_cred, exp));
115+
return nfserrno(nfsd_setuser(cred, exp));
115116
}
116117

117118
static inline __be32 check_pseudo_root(struct dentry *dentry,
@@ -219,7 +220,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp)
219220
put_cred(override_creds(new));
220221
put_cred(new);
221222
} else {
222-
error = nfsd_setuser_and_check_port(rqstp, exp);
223+
error = nfsd_setuser_and_check_port(rqstp, &rqstp->rq_cred, exp);
223224
if (error)
224225
goto out;
225226
}
@@ -358,7 +359,7 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, int access)
358359
if (error)
359360
goto out;
360361

361-
error = nfsd_setuser_and_check_port(rqstp, exp);
362+
error = nfsd_setuser_and_check_port(rqstp, &rqstp->rq_cred, exp);
362363
if (error)
363364
goto out;
364365

0 commit comments

Comments
 (0)