NFSD: Replace use of NFSD_MAY_LOCK in nfsd4_lock()
Subsystems (2)
[email protected]
maintainerRFC PATCH 1/1 NFSD: Replace use of NFSD_MAY_LOCK in nfsd4_lock()
From: Chuck Lever <[email protected]>
NFSv4 LOCK operations should not avoid the set of authorization checks that apply to all other NFSv4 operations. Also, the "no_auth_nlm" export option should apply only to NLM LOCK requests. It's not necessary or sensible to apply it to NFSv4 LOCK operations.
The replacement MAY bit mask,
"NFSD_MAY_READ | NFSD_MAY_OWNER_OVERRIDE", comes from the access bits that are set in nfsd_permission() when the caller has set NFSD_MAY_LOCK.
--- fs/nfsd/nfs4state.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
fs/nfsd/nfs4state.c +3 -4
@@ -7967,11 +7967,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (check_lock_length (lock->lk_offset, lock->lk_length))return nfserr_inval; -if ((status =fh_verify (rqstp, &cstate->current_fh, -S_IFREG ,NFSD_MAY_LOCK ))) { -dprintk ("NFSD: nfsd4_lock: permission denied!\n" ); + status =fh_verify (rqstp, &cstate->current_fh,S_IFREG , +NFSD_MAY_READ |NFSD_MAY_OWNER_OVERRIDE ); +if (status != nfs_ok)return status; - } sb = cstate->current_fh.fh_dentry->d_sb;if (lock->lk_is_new) {
Signature · 1 line
2.46.2
Quoted 24 lines · On Fri, 11 Oct 2024, [email protected] wrote:
From: Chuck Lever <[email protected]>
NFSv4 LOCK operations should not avoid the set of authorization checks that apply to all other NFSv4 operations. Also, the "
no_auth_nlm" export option should apply only to NLM LOCK requests. It's not necessary or sensible to apply it to NFSv4 LOCK operations.The replacement MAY bit mask,
"NFSD_MAY_READ|NFSD_MAY_OWNER_OVERRIDE", comes from the access bits that are set innfsd_permission()when the caller has setNFSD_MAY_LOCK.Reported-by NeilBrown <[email protected]>Signed-off-by Chuck Lever <[email protected]>--- fs/nfsd/nfs4state.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)fs/nfsd/nfs4state.c +0
-0@@ -7967,11 +7967,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (check_lock_length (lock->lk_offset, lock->lk_length))
fs/nfsd/nfs4state.c nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 7974
Quoted 10 lines
fs/nfsd/nfs4state.c +3
-4return nfserr_inval; -if ((status =fh_verify (rqstp, &cstate->current_fh, -S_IFREG ,NFSD_MAY_LOCK ))) { -dprintk ("NFSD: nfsd4_lock: permission denied!\n" ); + status =fh_verify (rqstp, &cstate->current_fh,S_IFREG , +NFSD_MAY_READ |NFSD_MAY_OWNER_OVERRIDE ); +if (status != nfs_ok)return status; - }
though I think we want a follow-on patch which uses NFSD_MAY_WRITE for write locks for consistency with check_fmode_for_setlk().
And I'm wondering about NFSD_MAY_OWNER_OVERRIDE ... that is really an NFSv3 thing. For NFSv4 we should be checking permission at "open" time, recording that in the state (both of which we do) and then performing permission checks against the state rather than against the inode. But that is a whole different can of worms.
Thanks,
NeilBrown
Quoted 7 lines
fs/nfsd/nfs4state.c +0
-0sb = cstate->current_fh.fh_dentry->d_sb;if (lock->lk_is_new) {Signature · 1 line
2.46.2
Quoted 27 lines · On Thu, 2024-10-10 at 11:33 -0400, [email protected] wrote:
From: Chuck Lever <[email protected]>
NFSv4 LOCK operations should not avoid the set of authorization checks that apply to all other NFSv4 operations. Also, the "
no_auth_nlm" export option should apply only to NLM LOCK requests. It's not necessary or sensible to apply it to NFSv4 LOCK operations.The replacement MAY bit mask,
"NFSD_MAY_READ|NFSD_MAY_OWNER_OVERRIDE", comes from the access bits that are set innfsd_permission()when the caller has setNFSD_MAY_LOCK.Reported-by NeilBrown <[email protected]>Signed-off-by Chuck Lever <[email protected]>--- fs/nfsd/nfs4state.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)fs/nfsd/nfs4state.c +0
-1@@ -7967,11 +7967,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (check_lock_length (lock->lk_offset, lock->lk_length))return nfserr_inval; - if ((status = fh_verify(rqstp, &cstate->current_fh,
fs/nfsd/nfs4state.c nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 7976
Quoted 10 lines
fs/nfsd/nfs4state.c +3
-3- S_IFREG, NFSD_MAY_LOCK))) { -dprintk ("NFSD: nfsd4_lock: permission denied!\n" ); + status =fh_verify (rqstp, &cstate->current_fh,S_IFREG , +NFSD_MAY_READ |NFSD_MAY_OWNER_OVERRIDE ); +if (status != nfs_ok)return status; - } sb = cstate->current_fh.fh_dentry->d_sb;if (lock->lk_is_new) {
I would say this warrants a comment as to why you're not using NFSD_MAY_LOCK here, but Neil's renaming patch takes care of that.
Quoted 38 lines · NeilBrown
Quoted 24 lines · On Fri, 11 Oct 2024, [email protected] wrote:
From: Chuck Lever <[email protected]>
NFSv4 LOCK operations should not avoid the set of authorization checks that apply to all other NFSv4 operations. Also, the "
no_auth_nlm" export option should apply only to NLM LOCK requests. It's not necessary or sensible to apply it to NFSv4 LOCK operations.The replacement MAY bit mask,
"NFSD_MAY_READ|NFSD_MAY_OWNER_OVERRIDE", comes from the access bits that are set innfsd_permission()when the caller has setNFSD_MAY_LOCK.Reported-by NeilBrown <[email protected]>Signed-off-by Chuck Lever <[email protected]>--- fs/nfsd/nfs4state.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)fs/nfsd/nfs4state.c +0
-0@@ -7967,11 +7967,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (check_lock_length (lock->lk_offset, lock->lk_length))fs/nfsd/nfs4state.c nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 7974
Quoted 10 lines
fs/nfsd/nfs4state.c +3
-4return nfserr_inval; -if ((status =fh_verify (rqstp, &cstate->current_fh, -S_IFREG ,NFSD_MAY_LOCK ))) { -dprintk ("NFSD: nfsd4_lock: permission denied!\n" ); + status =fh_verify (rqstp, &cstate->current_fh,S_IFREG , +NFSD_MAY_READ |NFSD_MAY_OWNER_OVERRIDE ); +if (status != nfs_ok)return status; - }Reviewed-by NeilBrown <[email protected]>
Quoted 2 lines
though I think we want a follow-on patch which uses
NFSD_MAY_WRITEfor write locks for consistency withcheck_fmode_for_setlk().
I think this patch might introduce a behavior regression, then. Instead of a follow-on, I need a v2 of this patch.
Quoted 5 lines
And I'm wondering about
NFSD_MAY_OWNER_OVERRIDE... that is really an NFSv3 thing. For NFSv4 we should be checking permission at "open" time, recording that in the state (both of which we do) and then performing permission checks against the state rather than against the inode. But that is a whole different can of worms.
I see several sites in NFSv4 land that assert OWNER_OVERRIDE. But point taken on taking the permissions from the state ID instead of using a fixed mask.
Quoted 12 lines
Thanks,
NeilBrownQuoted 7 lines
fs/nfsd/nfs4state.c +0
-0sb = cstate->current_fh.fh_dentry->d_sb;if (lock->lk_is_new) {Signature · 1 line
2.46.2
Signature · 1 line
Chuck Lever
Quoted 39 lines · Chuck Lever
Quoted 38 lines · NeilBrown
Quoted 24 lines · On Fri, 11 Oct 2024, [email protected] wrote:
From: Chuck Lever <[email protected]>
NFSv4 LOCK operations should not avoid the set of authorization checks that apply to all other NFSv4 operations. Also, the "
no_auth_nlm" export option should apply only to NLM LOCK requests. It's not necessary or sensible to apply it to NFSv4 LOCK operations.The replacement MAY bit mask,
"NFSD_MAY_READ|NFSD_MAY_OWNER_OVERRIDE", comes from the access bits that are set innfsd_permission()when the caller has setNFSD_MAY_LOCK.Reported-by NeilBrown <[email protected]>Signed-off-by Chuck Lever <[email protected]>--- fs/nfsd/nfs4state.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)fs/nfsd/nfs4state.c +0
-0@@ -7967,11 +7967,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (check_lock_length (lock->lk_offset, lock->lk_length))fs/nfsd/nfs4state.c nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 7974
Quoted 10 lines
fs/nfsd/nfs4state.c +3
-4return nfserr_inval; -if ((status =fh_verify (rqstp, &cstate->current_fh, -S_IFREG ,NFSD_MAY_LOCK ))) { -dprintk ("NFSD: nfsd4_lock: permission denied!\n" ); + status =fh_verify (rqstp, &cstate->current_fh,S_IFREG , +NFSD_MAY_READ |NFSD_MAY_OWNER_OVERRIDE ); +if (status != nfs_ok)return status; - }Reviewed-by NeilBrown <[email protected]>
Quoted 5 lines
Quoted 2 lines
though I think we want a follow-on patch which uses
NFSD_MAY_WRITEfor write locks for consistency withcheck_fmode_for_setlk().I think this patch might introduce a behavior regression, then. Instead of a follow-on, I need a v2 of this patch.
This is not a regression - it has always been this way (since 2.3.42). And both NLM and v4 suffer - I was wrong about NLM.
If MAY_LOCK is set, then any MAY_READ or MAY_WRITE flag is ignored, and the 'acc' passed to inode_permission() is only MAY_READ | MAY_OWNER_OVERRIDE
So any locking over nfsd currently requires ownership or READ access to the inode. This is slightly different behaviour to local filesystems and it might be nice to fix but I don't think it is an important difference. Importantly your patch doesn't change this behaviour at all.
Thanks,
NeilBrown
Quoted 29 lines
Quoted 7 lines
And I'm wondering about
NFSD_MAY_OWNER_OVERRIDE... that is really an NFSv3 thing. For NFSv4 we should be checking permission at "open" time, recording that in the state (both of which we do) and then performing permission checks against the state rather than against the inode. But that is a whole different can of worms.I see several sites in NFSv4 land that assert
OWNER_OVERRIDE. But point taken on taking the permissions from the state ID instead of using a fixed mask.Quoted 12 lines
Thanks,
NeilBrownQuoted 7 lines
fs/nfsd/nfs4state.c +0
-0sb = cstate->current_fh.fh_dentry->d_sb;if (lock->lk_is_new) {Signature · 1 line
2.46.2Signature · 1 line
Chuck Lever
Quoted 46 lines · NeilBrown
Quoted 39 lines · Chuck Lever
Quoted 38 lines · NeilBrown
Quoted 24 lines · On Fri, 11 Oct 2024, [email protected] wrote:
From: Chuck Lever <[email protected]>
NFSv4 LOCK operations should not avoid the set of authorization checks that apply to all other NFSv4 operations. Also, the "
no_auth_nlm" export option should apply only to NLM LOCK requests. It's not necessary or sensible to apply it to NFSv4 LOCK operations.The replacement MAY bit mask,
"NFSD_MAY_READ|NFSD_MAY_OWNER_OVERRIDE", comes from the access bits that are set innfsd_permission()when the caller has setNFSD_MAY_LOCK.Reported-by NeilBrown <[email protected]>Signed-off-by Chuck Lever <[email protected]>--- fs/nfsd/nfs4state.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)fs/nfsd/nfs4state.c +0
-0@@ -7967,11 +7967,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (check_lock_length (lock->lk_offset, lock->lk_length))fs/nfsd/nfs4state.c nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 7974
Quoted 10 lines
fs/nfsd/nfs4state.c +3
-4return nfserr_inval; -if ((status =fh_verify (rqstp, &cstate->current_fh, -S_IFREG ,NFSD_MAY_LOCK ))) { -dprintk ("NFSD: nfsd4_lock: permission denied!\n" ); + status =fh_verify (rqstp, &cstate->current_fh,S_IFREG , +NFSD_MAY_READ |NFSD_MAY_OWNER_OVERRIDE ); +if (status != nfs_ok)return status; - }Reviewed-by NeilBrown <[email protected]>Quoted 5 lines
Quoted 2 lines
though I think we want a follow-on patch which uses
NFSD_MAY_WRITEfor write locks for consistency withcheck_fmode_for_setlk().I think this patch might introduce a behavior regression, then. Instead of a follow-on, I need a v2 of this patch.
Quoted 6 lines
This is not a regression - it has always been this way (since 2.3.42). And both NLM and v4 suffer - I was wrong about NLM.
If
MAY_LOCKis set, then anyMAY_READorMAY_WRITEflag is ignored, and the 'acc' passed toinode_permission()is onlyMAY_READ|MAY_OWNER_OVERRIDE
That's what I thought when I looked at nfsd_permission() again.
Quoted 4 lines
So any locking over nfsd currently requires ownership or READ access to the inode. This is slightly different behaviour to local filesystems and it might be nice to fix but I don't think it is an important difference. Importantly your patch doesn't change this behaviour at all.
nfsd4_lock(), IIUC, thoroughly examines the stateid just after it does the fh_verify(). Maybe this would be OK:
status = fh_verify( ... , 0);
This is what the other NFSv4 lock-related operations do.
Quoted 29 lines
Quoted 27 lines
Quoted 5 lines
And I'm wondering about
NFSD_MAY_OWNER_OVERRIDE... that is really an NFSv3 thing. For NFSv4 we should be checking permission at "open" time, recording that in the state (both of which we do) and then performing permission checks against the state rather than against the inode. But that is a whole different can of worms.I see several sites in NFSv4 land that assert
OWNER_OVERRIDE. But point taken on taking the permissions from the state ID instead of using a fixed mask.Quoted 12 lines
Thanks,
NeilBrownQuoted 7 lines
fs/nfsd/nfs4state.c +0
-0sb = cstate->current_fh.fh_dentry->d_sb;if (lock->lk_is_new) {Signature · 1 line
2.46.2Signature · 1 line
Chuck Lever
Signature · 1 line
Chuck Lever
Quoted 62 lines · Chuck Lever
Quoted 46 lines · NeilBrown
Quoted 39 lines · Chuck Lever
Quoted 38 lines · NeilBrown
Quoted 24 lines · On Fri, 11 Oct 2024, [email protected] wrote:
From: Chuck Lever <[email protected]>
NFSv4 LOCK operations should not avoid the set of authorization checks that apply to all other NFSv4 operations. Also, the "
no_auth_nlm" export option should apply only to NLM LOCK requests. It's not necessary or sensible to apply it to NFSv4 LOCK operations.The replacement MAY bit mask,
"NFSD_MAY_READ|NFSD_MAY_OWNER_OVERRIDE", comes from the access bits that are set innfsd_permission()when the caller has setNFSD_MAY_LOCK.Reported-by NeilBrown <[email protected]>Signed-off-by Chuck Lever <[email protected]>--- fs/nfsd/nfs4state.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)fs/nfsd/nfs4state.c +0
-0@@ -7967,11 +7967,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (check_lock_length (lock->lk_offset, lock->lk_length))fs/nfsd/nfs4state.c nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 7974
Quoted 10 lines
fs/nfsd/nfs4state.c +3
-4return nfserr_inval; -if ((status =fh_verify (rqstp, &cstate->current_fh, -S_IFREG ,NFSD_MAY_LOCK ))) { -dprintk ("NFSD: nfsd4_lock: permission denied!\n" ); + status =fh_verify (rqstp, &cstate->current_fh,S_IFREG , +NFSD_MAY_READ |NFSD_MAY_OWNER_OVERRIDE ); +if (status != nfs_ok)return status; - }Reviewed-by NeilBrown <[email protected]>Quoted 5 lines
Quoted 2 lines
though I think we want a follow-on patch which uses
NFSD_MAY_WRITEfor write locks for consistency withcheck_fmode_for_setlk().I think this patch might introduce a behavior regression, then. Instead of a follow-on, I need a v2 of this patch.
Quoted 6 lines
This is not a regression - it has always been this way (since 2.3.42). And both NLM and v4 suffer - I was wrong about NLM.
If
MAY_LOCKis set, then anyMAY_READorMAY_WRITEflag is ignored, and the 'acc' passed toinode_permission()is onlyMAY_READ|MAY_OWNER_OVERRIDEThat's what I thought when I looked at
nfsd_permission()again.Quoted 4 lines
So any locking over nfsd currently requires ownership or READ access to the inode. This is slightly different behaviour to local filesystems and it might be nice to fix but I don't think it is an important difference. Importantly your patch doesn't change this behaviour at all.
Quoted 6 lines
nfsd4_lock(), IIUC, thoroughly examines the stateid just after it does thefh_verify(). Maybe this would be OK:status = fh_verify( ... , 0);This is what the other NFSv4 lock-related operations do.
I like that! I haven't looked at the code yet to comment on correctness, but it does seem like the right sort of approach.
Thanks,
NeilBrown