Commit 6fa02839 authored by J. Bruce Fields's avatar J. Bruce Fields Committed by Linus Torvalds

nfsd4: recheck for secure ports in fh_verify

As with commit 7fc90ec9 ("knfsd: nfsd:
call nfsd_setuser() on fh_compose(), fix nfsd4 permissions problem")
this is a case where we need to redo a security check in fh_verify()
even though the filehandle already has an associated dentry--if the
filehandle was created by fh_compose() in an earlier operation of the
nfsv4 compound, then we may not have done these checks yet.

Without this fix it is possible, for example, to traverse from an export
without the secure ports requirement to one with it in a single
compound, and bypass the secure port check on the new export.

While we're here, fix up some minor style problems and change a printk()
to a dprintk(), to make it harder for random unprivileged users to spam
the logs.
Signed-off-by: default avatarJ. Bruce Fields <bfields@citi.umich.edu>
Reviewed-By: default avatarNeilBrown <neilb@suse.de>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ac8587dc
...@@ -95,6 +95,22 @@ nfsd_mode_check(struct svc_rqst *rqstp, umode_t mode, int type) ...@@ -95,6 +95,22 @@ nfsd_mode_check(struct svc_rqst *rqstp, umode_t mode, int type)
return 0; return 0;
} }
static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp,
struct svc_export *exp)
{
/* Check if the request originated from a secure port. */
if (!rqstp->rq_secure && EX_SECURE(exp)) {
char buf[RPC_MAX_ADDRBUFLEN];
dprintk(KERN_WARNING
"nfsd: request from insecure port %s!\n",
svc_print_addr(rqstp, buf, sizeof(buf)));
return nfserr_perm;
}
/* Set user creds for this exportpoint */
return nfserrno(nfsd_setuser(rqstp, exp));
}
/* /*
* Perform sanity checks on the dentry in a client's file handle. * Perform sanity checks on the dentry in a client's file handle.
* *
...@@ -167,18 +183,7 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access) ...@@ -167,18 +183,7 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access)
goto out; goto out;
} }
/* Check if the request originated from a secure port. */ error = nfsd_setuser_and_check_port(rqstp, exp);
error = nfserr_perm;
if (!rqstp->rq_secure && EX_SECURE(exp)) {
char buf[RPC_MAX_ADDRBUFLEN];
printk(KERN_WARNING
"nfsd: request from insecure port %s!\n",
svc_print_addr(rqstp, buf, sizeof(buf)));
goto out;
}
/* Set user creds for this exportpoint */
error = nfserrno(nfsd_setuser(rqstp, exp));
if (error) if (error)
goto out; goto out;
...@@ -227,18 +232,22 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access) ...@@ -227,18 +232,22 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access)
fhp->fh_export = exp; fhp->fh_export = exp;
nfsd_nr_verified++; nfsd_nr_verified++;
} else { } else {
/* just rechecking permissions /*
* (e.g. nfsproc_create calls fh_verify, then nfsd_create does as well) * just rechecking permissions
* (e.g. nfsproc_create calls fh_verify, then nfsd_create
* does as well)
*/ */
dprintk("nfsd: fh_verify - just checking\n"); dprintk("nfsd: fh_verify - just checking\n");
dentry = fhp->fh_dentry; dentry = fhp->fh_dentry;
exp = fhp->fh_export; exp = fhp->fh_export;
/* Set user creds for this exportpoint; necessary even /*
* Set user creds for this exportpoint; necessary even
* in the "just checking" case because this may be a * in the "just checking" case because this may be a
* filehandle that was created by fh_compose, and that * filehandle that was created by fh_compose, and that
* is about to be used in another nfsv4 compound * is about to be used in another nfsv4 compound
* operation */ * operation.
error = nfserrno(nfsd_setuser(rqstp, exp)); */
error = nfsd_setuser_and_check_port(rqstp, exp);
if (error) if (error)
goto out; goto out;
} }
......
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