Skip to content

Commit 4cc9b9f

Browse files
neilbrownchucklever
authored andcommitted
nfsd: refine and rename NFSD_MAY_LOCK
NFSD_MAY_LOCK means a few different things. - it means that GSS is not required. - it means that with NFSEXP_NOAUTHNLM, authentication is not required - it means that OWNER_OVERRIDE is allowed. None of these are specific to locking, they are specific to the NLM protocol. So: - rename to NFSD_MAY_NLM - set NFSD_MAY_OWNER_OVERRIDE and NFSD_MAY_BYPASS_GSS in nlm_fopen() so that NFSD_MAY_NLM doesn't need to imply these. - move the test on NFSEXP_NOAUTHNLM out of nfsd_permission() and into fh_verify where other special-case tests on the MAY flags happen. nfsd_permission() can be called from other places than fh_verify(), but none of these will have NFSD_MAY_NLM. Signed-off-by: NeilBrown <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 6640556 commit 4cc9b9f

File tree

5 files changed

+18
-23
lines changed

5 files changed

+18
-23
lines changed

fs/nfsd/lockd.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,20 @@ nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp,
3838
memcpy(&fh.fh_handle.fh_raw, f->data, f->size);
3939
fh.fh_export = NULL;
4040

41+
/*
42+
* Allow BYPASS_GSS as some client implementations use AUTH_SYS
43+
* for NLM even when GSS is used for NFS.
44+
* Allow OWNER_OVERRIDE as permission might have been changed
45+
* after the file was opened.
46+
* Pass MAY_NLM so that authentication can be completely bypassed
47+
* if NFSEXP_NOAUTHNLM is set. Some older clients use AUTH_NULL
48+
* for NLM requests.
49+
*/
4150
access = (mode == O_WRONLY) ? NFSD_MAY_WRITE : NFSD_MAY_READ;
42-
access |= NFSD_MAY_LOCK;
51+
access |= NFSD_MAY_NLM | NFSD_MAY_OWNER_OVERRIDE | NFSD_MAY_BYPASS_GSS;
4352
nfserr = nfsd_open(rqstp, &fh, S_IFREG, access, filp);
4453
fh_put(&fh);
45-
/* We return nlm error codes as nlm doesn't know
54+
/* We return nlm error codes as nlm doesn't know
4655
* about nfsd, but nfsd does know about nlm..
4756
*/
4857
switch (nfserr) {

fs/nfsd/nfsfh.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,10 @@ __fh_verify(struct svc_rqst *rqstp,
363363
if (error)
364364
goto out;
365365

366-
/*
367-
* pseudoflavor restrictions are not enforced on NLM,
368-
* which clients virtually always use auth_sys for,
369-
* even while using RPCSEC_GSS for NFS.
370-
*/
371-
if (access & NFSD_MAY_LOCK)
372-
goto skip_pseudoflavor_check;
366+
if ((access & NFSD_MAY_NLM) && (exp->ex_flags & NFSEXP_NOAUTHNLM))
367+
/* NLM is allowed to fully bypass authentication */
368+
goto out;
369+
373370
if (access & NFSD_MAY_BYPASS_GSS)
374371
may_bypass_gss = true;
375372
/*
@@ -385,7 +382,6 @@ __fh_verify(struct svc_rqst *rqstp,
385382
if (error)
386383
goto out;
387384

388-
skip_pseudoflavor_check:
389385
/* Finally, check access permissions. */
390386
error = nfsd_permission(cred, exp, dentry, access);
391387
out:

fs/nfsd/trace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ DEFINE_NFSD_XDR_ERR_EVENT(cant_encode);
7979
{ NFSD_MAY_READ, "READ" }, \
8080
{ NFSD_MAY_SATTR, "SATTR" }, \
8181
{ NFSD_MAY_TRUNC, "TRUNC" }, \
82-
{ NFSD_MAY_LOCK, "LOCK" }, \
82+
{ NFSD_MAY_NLM, "NLM" }, \
8383
{ NFSD_MAY_OWNER_OVERRIDE, "OWNER_OVERRIDE" }, \
8484
{ NFSD_MAY_LOCAL_ACCESS, "LOCAL_ACCESS" }, \
8585
{ NFSD_MAY_BYPASS_GSS_ON_ROOT, "BYPASS_GSS_ON_ROOT" }, \

fs/nfsd/vfs.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,7 +2506,7 @@ nfsd_permission(struct svc_cred *cred, struct svc_export *exp,
25062506
(acc & NFSD_MAY_EXEC)? " exec" : "",
25072507
(acc & NFSD_MAY_SATTR)? " sattr" : "",
25082508
(acc & NFSD_MAY_TRUNC)? " trunc" : "",
2509-
(acc & NFSD_MAY_LOCK)? " lock" : "",
2509+
(acc & NFSD_MAY_NLM)? " nlm" : "",
25102510
(acc & NFSD_MAY_OWNER_OVERRIDE)? " owneroverride" : "",
25112511
inode->i_mode,
25122512
IS_IMMUTABLE(inode)? " immut" : "",
@@ -2531,16 +2531,6 @@ nfsd_permission(struct svc_cred *cred, struct svc_export *exp,
25312531
if ((acc & NFSD_MAY_TRUNC) && IS_APPEND(inode))
25322532
return nfserr_perm;
25332533

2534-
if (acc & NFSD_MAY_LOCK) {
2535-
/* If we cannot rely on authentication in NLM requests,
2536-
* just allow locks, otherwise require read permission, or
2537-
* ownership
2538-
*/
2539-
if (exp->ex_flags & NFSEXP_NOAUTHNLM)
2540-
return 0;
2541-
else
2542-
acc = NFSD_MAY_READ | NFSD_MAY_OWNER_OVERRIDE;
2543-
}
25442534
/*
25452535
* The file owner always gets access permission for accesses that
25462536
* would normally be checked at open time. This is to make

fs/nfsd/vfs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#define NFSD_MAY_READ 0x004 /* == MAY_READ */
2121
#define NFSD_MAY_SATTR 0x008
2222
#define NFSD_MAY_TRUNC 0x010
23-
#define NFSD_MAY_LOCK 0x020
23+
#define NFSD_MAY_NLM 0x020 /* request is from lockd */
2424
#define NFSD_MAY_MASK 0x03f
2525

2626
/* extra hints to permission and open routines: */

0 commit comments

Comments
 (0)