diff options
Diffstat (limited to 'fs/nfsd/nfsfh.c')
-rw-r--r-- | fs/nfsd/nfsfh.c | 102 |
1 files changed, 60 insertions, 42 deletions
diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c index 01965b2f3a76..1c12177b908c 100644 --- a/fs/nfsd/nfsfh.c +++ b/fs/nfsd/nfsfh.c | |||
@@ -1,6 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * linux/fs/nfsd/nfsfh.c | ||
3 | * | ||
4 | * NFS server file handle treatment. | 2 | * NFS server file handle treatment. |
5 | * | 3 | * |
6 | * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> | 4 | * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> |
@@ -9,19 +7,11 @@ | |||
9 | * ... and again Southern-Winter 2001 to support export_operations | 7 | * ... and again Southern-Winter 2001 to support export_operations |
10 | */ | 8 | */ |
11 | 9 | ||
12 | #include <linux/slab.h> | ||
13 | #include <linux/fs.h> | ||
14 | #include <linux/unistd.h> | ||
15 | #include <linux/string.h> | ||
16 | #include <linux/stat.h> | ||
17 | #include <linux/dcache.h> | ||
18 | #include <linux/exportfs.h> | 10 | #include <linux/exportfs.h> |
19 | #include <linux/mount.h> | ||
20 | 11 | ||
21 | #include <linux/sunrpc/clnt.h> | ||
22 | #include <linux/sunrpc/svc.h> | ||
23 | #include <linux/sunrpc/svcauth_gss.h> | 12 | #include <linux/sunrpc/svcauth_gss.h> |
24 | #include <linux/nfsd/nfsd.h> | 13 | #include "nfsd.h" |
14 | #include "vfs.h" | ||
25 | #include "auth.h" | 15 | #include "auth.h" |
26 | 16 | ||
27 | #define NFSDDBG_FACILITY NFSDDBG_FH | 17 | #define NFSDDBG_FACILITY NFSDDBG_FH |
@@ -96,8 +86,10 @@ nfsd_mode_check(struct svc_rqst *rqstp, umode_t mode, int type) | |||
96 | static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp, | 86 | static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp, |
97 | struct svc_export *exp) | 87 | struct svc_export *exp) |
98 | { | 88 | { |
89 | int flags = nfsexp_flags(rqstp, exp); | ||
90 | |||
99 | /* Check if the request originated from a secure port. */ | 91 | /* Check if the request originated from a secure port. */ |
100 | if (!rqstp->rq_secure && EX_SECURE(exp)) { | 92 | if (!rqstp->rq_secure && (flags & NFSEXP_INSECURE_PORT)) { |
101 | RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]); | 93 | RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]); |
102 | dprintk(KERN_WARNING | 94 | dprintk(KERN_WARNING |
103 | "nfsd: request from insecure port %s!\n", | 95 | "nfsd: request from insecure port %s!\n", |
@@ -109,6 +101,36 @@ static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp, | |||
109 | return nfserrno(nfsd_setuser(rqstp, exp)); | 101 | return nfserrno(nfsd_setuser(rqstp, exp)); |
110 | } | 102 | } |
111 | 103 | ||
104 | static inline __be32 check_pseudo_root(struct svc_rqst *rqstp, | ||
105 | struct dentry *dentry, struct svc_export *exp) | ||
106 | { | ||
107 | if (!(exp->ex_flags & NFSEXP_V4ROOT)) | ||
108 | return nfs_ok; | ||
109 | /* | ||
110 | * v2/v3 clients have no need for the V4ROOT export--they use | ||
111 | * the mount protocl instead; also, further V4ROOT checks may be | ||
112 | * in v4-specific code, in which case v2/v3 clients could bypass | ||
113 | * them. | ||
114 | */ | ||
115 | if (!nfsd_v4client(rqstp)) | ||
116 | return nfserr_stale; | ||
117 | /* | ||
118 | * We're exposing only the directories and symlinks that have to be | ||
119 | * traversed on the way to real exports: | ||
120 | */ | ||
121 | if (unlikely(!S_ISDIR(dentry->d_inode->i_mode) && | ||
122 | !S_ISLNK(dentry->d_inode->i_mode))) | ||
123 | return nfserr_stale; | ||
124 | /* | ||
125 | * A pseudoroot export gives permission to access only one | ||
126 | * single directory; the kernel has to make another upcall | ||
127 | * before granting access to anything else under it: | ||
128 | */ | ||
129 | if (unlikely(dentry != exp->ex_path.dentry)) | ||
130 | return nfserr_stale; | ||
131 | return nfs_ok; | ||
132 | } | ||
133 | |||
112 | /* | 134 | /* |
113 | * Use the given filehandle to look up the corresponding export and | 135 | * Use the given filehandle to look up the corresponding export and |
114 | * dentry. On success, the results are used to set fh_export and | 136 | * dentry. On success, the results are used to set fh_export and |
@@ -232,14 +254,6 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp) | |||
232 | goto out; | 254 | goto out; |
233 | } | 255 | } |
234 | 256 | ||
235 | if (exp->ex_flags & NFSEXP_NOSUBTREECHECK) { | ||
236 | error = nfsd_setuser_and_check_port(rqstp, exp); | ||
237 | if (error) { | ||
238 | dput(dentry); | ||
239 | goto out; | ||
240 | } | ||
241 | } | ||
242 | |||
243 | if (S_ISDIR(dentry->d_inode->i_mode) && | 257 | if (S_ISDIR(dentry->d_inode->i_mode) && |
244 | (dentry->d_flags & DCACHE_DISCONNECTED)) { | 258 | (dentry->d_flags & DCACHE_DISCONNECTED)) { |
245 | printk("nfsd: find_fh_dentry returned a DISCONNECTED directory: %s/%s\n", | 259 | printk("nfsd: find_fh_dentry returned a DISCONNECTED directory: %s/%s\n", |
@@ -294,28 +308,32 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access) | |||
294 | error = nfsd_set_fh_dentry(rqstp, fhp); | 308 | error = nfsd_set_fh_dentry(rqstp, fhp); |
295 | if (error) | 309 | if (error) |
296 | goto out; | 310 | goto out; |
297 | dentry = fhp->fh_dentry; | ||
298 | exp = fhp->fh_export; | ||
299 | } else { | ||
300 | /* | ||
301 | * just rechecking permissions | ||
302 | * (e.g. nfsproc_create calls fh_verify, then nfsd_create | ||
303 | * does as well) | ||
304 | */ | ||
305 | dprintk("nfsd: fh_verify - just checking\n"); | ||
306 | dentry = fhp->fh_dentry; | ||
307 | exp = fhp->fh_export; | ||
308 | /* | ||
309 | * Set user creds for this exportpoint; necessary even | ||
310 | * in the "just checking" case because this may be a | ||
311 | * filehandle that was created by fh_compose, and that | ||
312 | * is about to be used in another nfsv4 compound | ||
313 | * operation. | ||
314 | */ | ||
315 | error = nfsd_setuser_and_check_port(rqstp, exp); | ||
316 | if (error) | ||
317 | goto out; | ||
318 | } | 311 | } |
312 | dentry = fhp->fh_dentry; | ||
313 | exp = fhp->fh_export; | ||
314 | /* | ||
315 | * We still have to do all these permission checks, even when | ||
316 | * fh_dentry is already set: | ||
317 | * - fh_verify may be called multiple times with different | ||
318 | * "access" arguments (e.g. nfsd_proc_create calls | ||
319 | * fh_verify(...,NFSD_MAY_EXEC) first, then later (in | ||
320 | * nfsd_create) calls fh_verify(...,NFSD_MAY_CREATE). | ||
321 | * - in the NFSv4 case, the filehandle may have been filled | ||
322 | * in by fh_compose, and given a dentry, but further | ||
323 | * compound operations performed with that filehandle | ||
324 | * still need permissions checks. In the worst case, a | ||
325 | * mountpoint crossing may have changed the export | ||
326 | * options, and we may now need to use a different uid | ||
327 | * (for example, if different id-squashing options are in | ||
328 | * effect on the new filesystem). | ||
329 | */ | ||
330 | error = check_pseudo_root(rqstp, dentry, exp); | ||
331 | if (error) | ||
332 | goto out; | ||
333 | |||
334 | error = nfsd_setuser_and_check_port(rqstp, exp); | ||
335 | if (error) | ||
336 | goto out; | ||
319 | 337 | ||
320 | error = nfsd_mode_check(rqstp, dentry->d_inode->i_mode, type); | 338 | error = nfsd_mode_check(rqstp, dentry->d_inode->i_mode, type); |
321 | if (error) | 339 | if (error) |