Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * NFS server file handle treatment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Portions Copyright (C) 1999 G. Allen Morris III <gam3@acm.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Extensive rewrite by Neil Brown <neilb@cse.unsw.edu.au> Southern-Spring 1999
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * ... and again Southern-Winter 2001 to support export_operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/exportfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/sunrpc/svcauth_gss.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "nfsd.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "vfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "auth.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "trace.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define NFSDDBG_FACILITY		NFSDDBG_FH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * our acceptability function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * if NOSUBTREECHECK, accept anything
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * if not, require that we can walk up to exp->ex_dentry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * doing some checks on the 'x' bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static int nfsd_acceptable(void *expv, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct svc_export *exp = expv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct dentry *tdentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct dentry *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	if (exp->ex_flags & NFSEXP_NOSUBTREECHECK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	tdentry = dget(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	while (tdentry != exp->ex_path.dentry && !IS_ROOT(tdentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		/* make sure parents give x permission to user */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		parent = dget_parent(tdentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		err = inode_permission(d_inode(parent), MAY_EXEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 			dput(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		dput(tdentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		tdentry = parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	if (tdentry != exp->ex_path.dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		dprintk("nfsd_acceptable failed at %p %pd\n", tdentry, tdentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	rv = (tdentry == exp->ex_path.dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	dput(tdentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) /* Type check. The correct error return for type mismatches does not seem to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * generally agreed upon. SunOS seems to use EISDIR if file isn't S_IFREG; a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * comment in the NFSv3 spec says this is incorrect (implementation notes for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * the write call).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static inline __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) nfsd_mode_check(struct svc_rqst *rqstp, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		umode_t requested)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	umode_t mode = d_inode(dentry)->i_mode & S_IFMT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	if (requested == 0) /* the caller doesn't care */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		return nfs_ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (mode == requested) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		if (mode == S_IFDIR && !d_can_lookup(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			WARN_ON_ONCE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			return nfserr_notdir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		return nfs_ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	 * v4 has an error more specific than err_notdir which we should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	 * return in preference to err_notdir:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	if (rqstp->rq_vers == 4 && mode == S_IFLNK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		return nfserr_symlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (requested == S_IFDIR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		return nfserr_notdir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (mode == S_IFDIR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		return nfserr_isdir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	return nfserr_inval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static bool nfsd_originating_port_ok(struct svc_rqst *rqstp, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (flags & NFSEXP_INSECURE_PORT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	/* We don't require gss requests to use low ports: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	if (rqstp->rq_cred.cr_flavor >= RPC_AUTH_GSS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	return test_bit(RQ_SECURE, &rqstp->rq_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 					  struct svc_export *exp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	int flags = nfsexp_flags(rqstp, exp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	/* Check if the request originated from a secure port. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	if (!nfsd_originating_port_ok(rqstp, flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		dprintk("nfsd: request from insecure port %s!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		        svc_print_addr(rqstp, buf, sizeof(buf)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return nfserr_perm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	/* Set user creds for this exportpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	return nfserrno(nfsd_setuser(rqstp, exp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static inline __be32 check_pseudo_root(struct svc_rqst *rqstp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	struct dentry *dentry, struct svc_export *exp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (!(exp->ex_flags & NFSEXP_V4ROOT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		return nfs_ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	 * v2/v3 clients have no need for the V4ROOT export--they use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	 * the mount protocl instead; also, further V4ROOT checks may be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	 * in v4-specific code, in which case v2/v3 clients could bypass
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	 * them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (!nfsd_v4client(rqstp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		return nfserr_stale;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	 * We're exposing only the directories and symlinks that have to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	 * traversed on the way to real exports:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if (unlikely(!d_is_dir(dentry) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		     !d_is_symlink(dentry)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		return nfserr_stale;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	 * A pseudoroot export gives permission to access only one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	 * single directory; the kernel has to make another upcall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	 * before granting access to anything else under it:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (unlikely(dentry != exp->ex_path.dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		return nfserr_stale;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	return nfs_ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  * Use the given filehandle to look up the corresponding export and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  * dentry.  On success, the results are used to set fh_export and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  * fh_dentry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	struct knfsd_fh	*fh = &fhp->fh_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	struct fid *fid = NULL, sfid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	struct svc_export *exp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	int fileid_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	int data_left = fh->fh_size/4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	__be32 error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	error = nfserr_stale;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (rqstp->rq_vers > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		error = nfserr_badhandle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (rqstp->rq_vers == 4 && fh->fh_size == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		return nfserr_nofilehandle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (fh->fh_version == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		if (--data_left < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		if (fh->fh_auth_type != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		len = key_len(fh->fh_fsid_type) / 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		if (len == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		if  (fh->fh_fsid_type == FSID_MAJOR_MINOR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			/* deprecated, convert to type 3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			len = key_len(FSID_ENCODE_DEV)/4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			fh->fh_fsid_type = FSID_ENCODE_DEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			 * struct knfsd_fh uses host-endian fields, which are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 			 * sometimes used to hold net-endian values. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 			 * confuses sparse, so we must use __force here to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			 * keep it from complaining.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			fh->fh_fsid[0] = new_encode_dev(MKDEV(ntohl((__force __be32)fh->fh_fsid[0]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 							ntohl((__force __be32)fh->fh_fsid[1])));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			fh->fh_fsid[1] = fh->fh_fsid[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		data_left -= len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		if (data_left < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		exp = rqst_exp_find(rqstp, fh->fh_fsid_type, fh->fh_fsid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		fid = (struct fid *)(fh->fh_fsid + len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		__u32 tfh[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		dev_t xdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		ino_t xino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		if (fh->fh_size != NFS_FHSIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		/* assume old filehandle format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		xdev = old_decode_dev(fh->ofh_xdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		xino = u32_to_ino_t(fh->ofh_xino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		mk_fsid(FSID_DEV, tfh, xdev, xino, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		exp = rqst_exp_find(rqstp, FSID_DEV, tfh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	error = nfserr_stale;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	if (IS_ERR(exp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		trace_nfsd_set_fh_dentry_badexport(rqstp, fhp, PTR_ERR(exp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		if (PTR_ERR(exp) == -ENOENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		return nfserrno(PTR_ERR(exp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	if (exp->ex_flags & NFSEXP_NOSUBTREECHECK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		/* Elevate privileges so that the lack of 'r' or 'x'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		 * permission on some parent directory will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		 * not stop exportfs_decode_fh from being able
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		 * to reconnect a directory into the dentry cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		 * The same problem can affect "SUBTREECHECK" exports,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		 * but as nfsd_acceptable depends on correct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		 * access control settings being in effect, we cannot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		 * fix that case easily.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		struct cred *new = prepare_creds();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		if (!new) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			error =  nfserrno(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		new->cap_effective =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			cap_raise_nfsd_set(new->cap_effective,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 					   new->cap_permitted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		put_cred(override_creds(new));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		put_cred(new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		error = nfsd_setuser_and_check_port(rqstp, exp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	 * Look up the dentry using the NFS file handle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	error = nfserr_stale;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if (rqstp->rq_vers > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		error = nfserr_badhandle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	if (fh->fh_version != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		sfid.i32.ino = fh->ofh_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		sfid.i32.gen = fh->ofh_generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		sfid.i32.parent_ino = fh->ofh_dirino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		fid = &sfid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		data_left = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		if (fh->ofh_dirino == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			fileid_type = FILEID_INO32_GEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			fileid_type = FILEID_INO32_GEN_PARENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		fileid_type = fh->fh_fileid_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (fileid_type == FILEID_ROOT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		dentry = dget(exp->ex_path.dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		dentry = exportfs_decode_fh(exp->ex_path.mnt, fid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 				data_left, fileid_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 				nfsd_acceptable, exp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		if (IS_ERR_OR_NULL(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			trace_nfsd_set_fh_dentry_badhandle(rqstp, fhp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 					dentry ?  PTR_ERR(dentry) : -ESTALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	if (dentry == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	if (IS_ERR(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		if (PTR_ERR(dentry) != -EINVAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			error = nfserrno(PTR_ERR(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	if (d_is_dir(dentry) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			(dentry->d_flags & DCACHE_DISCONNECTED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		printk("nfsd: find_fh_dentry returned a DISCONNECTED directory: %pd2\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 				dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	fhp->fh_dentry = dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	fhp->fh_export = exp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	exp_put(exp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)  * fh_verify - filehandle lookup and access checking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)  * @rqstp: pointer to current rpc request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  * @fhp: filehandle to be verified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  * @type: expected type of object pointed to by filehandle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)  * @access: type of access needed to object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)  * Look up a dentry from the on-the-wire filehandle, check the client's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)  * access to the export, and set the current task's credentials.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)  * Regardless of success or failure of fh_verify(), fh_put() should be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)  * called on @fhp when the caller is finished with the filehandle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)  * fh_verify() may be called multiple times on a given filehandle, for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)  * example, when processing an NFSv4 compound.  The first call will look
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)  * up a dentry using the on-the-wire filehandle.  Subsequent calls will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)  * skip the lookup and just perform the other checks and possibly change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)  * the current task's credentials.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)  * @type specifies the type of object expected using one of the S_IF*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)  * constants defined in include/linux/stat.h.  The caller may use zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)  * to indicate that it doesn't care, or a negative integer to indicate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)  * that it expects something not of the given type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)  * @access is formed from the NFSD_MAY_* constants defined in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)  * fs/nfsd/vfs.h.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, int access)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	struct svc_export *exp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	struct dentry	*dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	__be32		error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	dprintk("nfsd: fh_verify(%s)\n", SVCFH_fmt(fhp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	if (!fhp->fh_dentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		error = nfsd_set_fh_dentry(rqstp, fhp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	dentry = fhp->fh_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	exp = fhp->fh_export;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	 * We still have to do all these permission checks, even when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	 * fh_dentry is already set:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	 * 	- fh_verify may be called multiple times with different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	 * 	  "access" arguments (e.g. nfsd_proc_create calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	 * 	  fh_verify(...,NFSD_MAY_EXEC) first, then later (in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	 * 	  nfsd_create) calls fh_verify(...,NFSD_MAY_CREATE).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	 *	- in the NFSv4 case, the filehandle may have been filled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	 *	  in by fh_compose, and given a dentry, but further
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	 *	  compound operations performed with that filehandle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	 *	  still need permissions checks.  In the worst case, a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	 *	  mountpoint crossing may have changed the export
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	 *	  options, and we may now need to use a different uid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	 *	  (for example, if different id-squashing options are in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	 *	  effect on the new filesystem).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	error = check_pseudo_root(rqstp, dentry, exp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	error = nfsd_setuser_and_check_port(rqstp, exp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	error = nfsd_mode_check(rqstp, dentry, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	 * pseudoflavor restrictions are not enforced on NLM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	 * which clients virtually always use auth_sys for,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	 * even while using RPCSEC_GSS for NFS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	if (access & NFSD_MAY_LOCK || access & NFSD_MAY_BYPASS_GSS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		goto skip_pseudoflavor_check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	 * Clients may expect to be able to use auth_sys during mount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	 * even if they use gss for everything else; see section 2.3.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	 * of rfc 2623.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	if (access & NFSD_MAY_BYPASS_GSS_ON_ROOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 			&& exp->ex_path.dentry == dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		goto skip_pseudoflavor_check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	error = check_nfsd_access(exp, rqstp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) skip_pseudoflavor_check:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	/* Finally, check access permissions. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	error = nfsd_permission(rqstp, exp, dentry, access);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		dprintk("fh_verify: %pd2 permission failure, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 			"acc=%x, error=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 			dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 			access, ntohl(error));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	if (error == nfserr_stale)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		nfsdstats.fh_stale++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)  * Compose a file handle for an NFS reply.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)  * Note that when first composed, the dentry may not yet have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)  * an inode.  In this case a call to fh_update should be made
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)  * before the fh goes out on the wire ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) static void _fh_update(struct svc_fh *fhp, struct svc_export *exp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	if (dentry != exp->ex_path.dentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		struct fid *fid = (struct fid *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 			(fhp->fh_handle.fh_fsid + fhp->fh_handle.fh_size/4 - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		int maxsize = (fhp->fh_maxsize - fhp->fh_handle.fh_size)/4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		int subtreecheck = !(exp->ex_flags & NFSEXP_NOSUBTREECHECK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		fhp->fh_handle.fh_fileid_type =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 			exportfs_encode_fh(dentry, fid, &maxsize, subtreecheck);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		fhp->fh_handle.fh_size += maxsize * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		fhp->fh_handle.fh_fileid_type = FILEID_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)  * for composing old style file handles
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) static inline void _fh_update_old(struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 				  struct svc_export *exp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 				  struct knfsd_fh *fh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	fh->ofh_ino = ino_t_to_u32(d_inode(dentry)->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	fh->ofh_generation = d_inode(dentry)->i_generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	if (d_is_dir(dentry) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	    (exp->ex_flags & NFSEXP_NOSUBTREECHECK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		fh->ofh_dirino = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) static bool is_root_export(struct svc_export *exp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	return exp->ex_path.dentry == exp->ex_path.dentry->d_sb->s_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) static struct super_block *exp_sb(struct svc_export *exp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	return exp->ex_path.dentry->d_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) static bool fsid_type_ok_for_exp(u8 fsid_type, struct svc_export *exp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	switch (fsid_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	case FSID_DEV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		if (!old_valid_dev(exp_sb(exp)->s_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	case FSID_MAJOR_MINOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	case FSID_ENCODE_DEV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		return exp_sb(exp)->s_type->fs_flags & FS_REQUIRES_DEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	case FSID_NUM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 		return exp->ex_flags & NFSEXP_FSID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	case FSID_UUID8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	case FSID_UUID16:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		if (!is_root_export(exp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	case FSID_UUID4_INUM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	case FSID_UUID16_INUM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		return exp->ex_uuid != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) static void set_version_and_fsid_type(struct svc_fh *fhp, struct svc_export *exp, struct svc_fh *ref_fh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	u8 version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	u8 fsid_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	version = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	if (ref_fh && ref_fh->fh_export == exp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		version = ref_fh->fh_handle.fh_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		fsid_type = ref_fh->fh_handle.fh_fsid_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		ref_fh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		switch (version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		case 0xca:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 			fsid_type = FSID_DEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 			goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		 * As the fsid -> filesystem mapping was guided by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		 * user-space, there is no guarantee that the filesystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		 * actually supports that fsid type. If it doesn't we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 		 * loop around again without ref_fh set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		if (!fsid_type_ok_for_exp(fsid_type, exp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 			goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	} else if (exp->ex_flags & NFSEXP_FSID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		fsid_type = FSID_NUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	} else if (exp->ex_uuid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		if (fhp->fh_maxsize >= 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 			if (is_root_export(exp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 				fsid_type = FSID_UUID16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 				fsid_type = FSID_UUID16_INUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 			if (is_root_export(exp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 				fsid_type = FSID_UUID8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 				fsid_type = FSID_UUID4_INUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	} else if (!old_valid_dev(exp_sb(exp)->s_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		/* for newer device numbers, we must use a newer fsid format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		fsid_type = FSID_ENCODE_DEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		fsid_type = FSID_DEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	fhp->fh_handle.fh_version = version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	if (version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		fhp->fh_handle.fh_fsid_type = fsid_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	   struct svc_fh *ref_fh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	/* ref_fh is a reference file handle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	 * if it is non-null and for the same filesystem, then we should compose
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	 * a filehandle which is of the same version, where possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	 * Currently, that means that if ref_fh->fh_handle.fh_version == 0xca
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	 * Then create a 32byte filehandle using nfs_fhbase_old
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	struct inode * inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	dev_t ex_dev = exp_sb(exp)->s_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	dprintk("nfsd: fh_compose(exp %02x:%02x/%ld %pd2, ino=%ld)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 		MAJOR(ex_dev), MINOR(ex_dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		(long) d_inode(exp->ex_path.dentry)->i_ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 		(inode ? inode->i_ino : 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	/* Choose filehandle version and fsid type based on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	 * the reference filehandle (if it is in the same export)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	 * or the export options.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	set_version_and_fsid_type(fhp, exp, ref_fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	if (ref_fh == fhp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 		fh_put(ref_fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	if (fhp->fh_locked || fhp->fh_dentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 		printk(KERN_ERR "fh_compose: fh %pd2 not initialized!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 		       dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	if (fhp->fh_maxsize < NFS_FHSIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 		printk(KERN_ERR "fh_compose: called with maxsize %d! %pd2\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 		       fhp->fh_maxsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 		       dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	fhp->fh_dentry = dget(dentry); /* our internal copy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	fhp->fh_export = exp_get(exp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	if (fhp->fh_handle.fh_version == 0xca) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 		/* old style filehandle please */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 		memset(&fhp->fh_handle.fh_base, 0, NFS_FHSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 		fhp->fh_handle.fh_size = NFS_FHSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 		fhp->fh_handle.ofh_dcookie = 0xfeebbaca;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 		fhp->fh_handle.ofh_dev =  old_encode_dev(ex_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 		fhp->fh_handle.ofh_xdev = fhp->fh_handle.ofh_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 		fhp->fh_handle.ofh_xino =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 			ino_t_to_u32(d_inode(exp->ex_path.dentry)->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 		fhp->fh_handle.ofh_dirino = ino_t_to_u32(parent_ino(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 		if (inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 			_fh_update_old(dentry, exp, &fhp->fh_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 		fhp->fh_handle.fh_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 			key_len(fhp->fh_handle.fh_fsid_type) + 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 		fhp->fh_handle.fh_auth_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 		mk_fsid(fhp->fh_handle.fh_fsid_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 			fhp->fh_handle.fh_fsid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 			ex_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 			d_inode(exp->ex_path.dentry)->i_ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 			exp->ex_fsid, exp->ex_uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 		if (inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 			_fh_update(fhp, exp, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 		if (fhp->fh_handle.fh_fileid_type == FILEID_INVALID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 			fh_put(fhp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 			return nfserr_opnotsupp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)  * Update file handle information after changing a dentry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)  * This is only called by nfsd_create, nfsd_create_v3 and nfsd_proc_create
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) fh_update(struct svc_fh *fhp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	if (!fhp->fh_dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 		goto out_bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	dentry = fhp->fh_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	if (d_really_is_negative(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 		goto out_negative;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	if (fhp->fh_handle.fh_version != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 		_fh_update_old(dentry, fhp->fh_export, &fhp->fh_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 		if (fhp->fh_handle.fh_fileid_type != FILEID_ROOT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 		_fh_update(fhp, fhp->fh_export, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 		if (fhp->fh_handle.fh_fileid_type == FILEID_INVALID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 			return nfserr_opnotsupp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) out_bad:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	printk(KERN_ERR "fh_update: fh not verified!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	return nfserr_serverfault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) out_negative:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	printk(KERN_ERR "fh_update: %pd2 still negative!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 		dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	return nfserr_serverfault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)  * Release a file handle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) fh_put(struct svc_fh *fhp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	struct dentry * dentry = fhp->fh_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	struct svc_export * exp = fhp->fh_export;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	if (dentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 		fh_unlock(fhp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 		fhp->fh_dentry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 		dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 		fh_clear_wcc(fhp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	fh_drop_write(fhp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	if (exp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 		exp_put(exp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 		fhp->fh_export = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)  * Shorthand for dprintk()'s
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) char * SVCFH_fmt(struct svc_fh *fhp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	struct knfsd_fh *fh = &fhp->fh_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	static char buf[80];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	sprintf(buf, "%d: %08x %08x %08x %08x %08x %08x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 		fh->fh_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 		fh->fh_base.fh_pad[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 		fh->fh_base.fh_pad[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 		fh->fh_base.fh_pad[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 		fh->fh_base.fh_pad[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 		fh->fh_base.fh_pad[4],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 		fh->fh_base.fh_pad[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	return buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) enum fsid_source fsid_source(struct svc_fh *fhp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	if (fhp->fh_handle.fh_version != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 		return FSIDSOURCE_DEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	switch(fhp->fh_handle.fh_fsid_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 	case FSID_DEV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	case FSID_ENCODE_DEV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	case FSID_MAJOR_MINOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 		if (exp_sb(fhp->fh_export)->s_type->fs_flags & FS_REQUIRES_DEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 			return FSIDSOURCE_DEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	case FSID_NUM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 		if (fhp->fh_export->ex_flags & NFSEXP_FSID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 			return FSIDSOURCE_FSID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	/* either a UUID type filehandle, or the filehandle doesn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	 * match the export.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	if (fhp->fh_export->ex_flags & NFSEXP_FSID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 		return FSIDSOURCE_FSID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 	if (fhp->fh_export->ex_uuid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 		return FSIDSOURCE_UUID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	return FSIDSOURCE_DEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) }