NFSD: Support write delegations in LAYOUTGET
Subsystems (2)
[email protected]
maintainerPATCH v2 1/1 NFSD: Support write delegations in LAYOUTGET
From: Chuck Lever <[email protected]>
I noticed LAYOUTGET(LAYOUTIOMODE4_RW) returning NFS4ERR_ACCESS unexpectedly. The NFS client had created a file with mode 0444, and the server had returned a write delegation on the OPEN(CREATE). The client was requesting a RW layout using the write delegation stateid so that it could flush file modifications.
Creating a read-only file does not seem to be problematic for NFSv4.1 without pNFS, so I began looking at NFSD's implementation of LAYOUTGET.
The failure was because fh_verify() was doing a permission check as part of verifying the FH presented during the LAYOUTGET. It uses the loga_iomode value to specify the @accmode argument to fh_verify(). fh_verify(MAY_WRITE) on a file whose mode is 0444 fails with -EACCES.
To permit LAYOUT* operations in this case, add OWNER_OVERRIDE when checking the access permission of the incoming file handle for LAYOUTGET and LAYOUTCOMMIT.
Cc: Christoph Hellwig <[email protected]>
X-Cc: [email protected] # v6.6+
Message-Id: [email protected]
--- fs/nfsd/nfs4proc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/nfsd/nfs4proc.c +3 -2
@@ -2269,7 +2269,7 @@ nfsd4_layoutget(struct svc_rqst *rqstp,const struct nfsd4_layout_ops *ops;struct nfs4_layout_stateid *ls;__be32 nfserr; -int accmode =NFSD_MAY_READ_IF_EXEC ; +int accmode =NFSD_MAY_READ_IF_EXEC |NFSD_MAY_OWNER_OVERRIDE ;switch (lgp->lg_seg.iomode) {case IOMODE_READ :
@@ -2359,7 +2359,8 @@ nfsd4_layoutcommit(struct svc_rqst *rqstp,struct nfs4_layout_stateid *ls;__be32 nfserr; - nfserr =fh_verify (rqstp, current_fh,0 ,NFSD_MAY_WRITE ); + nfserr =fh_verify (rqstp, current_fh,0 , +NFSD_MAY_WRITE |NFSD_MAY_OWNER_OVERRIDE );if (nfserr) goto out;
Signature · 1 line
2.45.1
Quoted 12 lines · On Tue, Jun 11, 2024 at 03:36:46PM -0400, [email protected] wrote:
From: Chuck Lever <[email protected]>
I noticed
LAYOUTGET(LAYOUTIOMODE4_RW)returningNFS4ERR_ACCESSunexpectedly. The NFS client had created a file with mode 0444, and the server had returned a write delegation on the OPEN(CREATE). The client was requesting a RW layout using the write delegation stateid so that it could flush file modifications.Creating a read-only file does not seem to be problematic for NFSv4.1 without pNFS, so I began looking at NFSD's implementation of LAYOUTGET.
Quoted 8 lines
The failure was because
fh_verify()was doing a permission check as part of verifying the FH presented during the LAYOUTGET. It uses theloga_iomodevalue to specify the @accmode argument tofh_verify().fh_verify(MAY_WRITE)on a file whose mode is 0444 fails with-EACCES.To permit LAYOUT* operations in this case, add
OWNER_OVERRIDEwhen checking the access permission of the incoming file handle for LAYOUTGET and LAYOUTCOMMIT.
This looks reasonable to me:
Quoted 50 lines · On Tue, 2024-06-11 at 15:36 -0400, [email protected] wrote:
From: Chuck Lever <[email protected]>
I noticed
LAYOUTGET(LAYOUTIOMODE4_RW)returningNFS4ERR_ACCESSunexpectedly. The NFS client had created a file with mode 0444, and the server had returned a write delegation on the OPEN(CREATE). The client was requesting a RW layout using the write delegation stateid so that it could flush file modifications.Creating a read-only file does not seem to be problematic for NFSv4.1 without pNFS, so I began looking at NFSD's implementation of LAYOUTGET.
The failure was because
fh_verify()was doing a permission check as part of verifying the FH presented during the LAYOUTGET. It uses theloga_iomodevalue to specify the @accmode argument tofh_verify().fh_verify(MAY_WRITE)on a file whose mode is 0444 fails with-EACCES.To permit LAYOUT* operations in this case, add
OWNER_OVERRIDEwhen checking the access permission of the incoming file handle for LAYOUTGET and LAYOUTCOMMIT.Cc: Christoph Hellwig <[email protected]>
X-Cc: [email protected] # v6.6+
Message-Id: [email protected]Signed-off-by Chuck Lever <[email protected]>---
fs/nfsd/nfs4proc.c | 5 +++--1 file changed, 3 insertions(+), 2 deletions(-)fs/nfsd/nfs4proc.c +1
-1@@ -2269,7 +2269,7 @@ nfsd4_layoutget(struct svc_rqst *rqstp, const struct nfsd4_layout_ops *ops; struct nfs4_layout_stateid *ls; __be32 nfserr; -int accmode =NFSD_MAY_READ_IF_EXEC ; +int accmode =NFSD_MAY_READ_IF_EXEC |NFSD_MAY_OWNER_OVERRIDE ;
switch (lgp->lg_seg.iomode) {
caseIOMODE_READ:fs/nfsd/nfs4proc.c +0
-0@@ -2359,7 +2359,8 @@ nfsd4_layoutcommit(struct svc_rqst *rqstp, struct nfs4_layout_stateid *ls; __be32 nfserr;fs/nfsd/nfs4proc.c +2
-1- nfserr =fh_verify (rqstp, current_fh,0 ,NFSD_MAY_WRITE ); + nfserr = fh_verify(rqstp, current_fh, 0, + NFSD_MAY_WRITE |
Quoted 4 lines
NFSD_MAY_OWNER_OVERRIDE);
if (nfserr)
goto out;