* [PATCH v2] NFSD: Support write delegations in LAYOUTGET
@ 2024-06-11 19:36 cel
2024-06-12 5:08 ` Christoph Hellwig
2024-06-12 13:52 ` Jeff Layton
0 siblings, 2 replies; 3+ messages in thread
From: cel @ 2024-06-11 19:36 UTC (permalink / raw)
To: linux-nfs
Cc: Jeff Layton, Neil Brown, Dai Ngo, Olga Kornievskaia, Tom Talpey,
Chuck Lever, Christoph Hellwig
From: Chuck Lever <chuck.lever@oracle.com>
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 <hch@lst.de>
X-Cc: stable@vger.kernel.org # v6.6+
Message-Id: 4E9C0D74-A06D-4DC3-A48A-73034DC40395@oracle.com
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
fs/nfsd/nfs4proc.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index 46bd20fe5c0f..2e39cf2e502a 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -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;
--
2.45.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v2] NFSD: Support write delegations in LAYOUTGET
2024-06-11 19:36 [PATCH v2] NFSD: Support write delegations in LAYOUTGET cel
@ 2024-06-12 5:08 ` Christoph Hellwig
2024-06-12 13:52 ` Jeff Layton
1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2024-06-12 5:08 UTC (permalink / raw)
To: cel
Cc: linux-nfs, Jeff Layton, Neil Brown, Dai Ngo, Olga Kornievskaia,
Tom Talpey, Chuck Lever, Christoph Hellwig
On Tue, Jun 11, 2024 at 03:36:46PM -0400, cel@kernel.org wrote:
> From: Chuck Lever <chuck.lever@oracle.com>
>
> 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.
This looks reasonable to me:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] NFSD: Support write delegations in LAYOUTGET
2024-06-11 19:36 [PATCH v2] NFSD: Support write delegations in LAYOUTGET cel
2024-06-12 5:08 ` Christoph Hellwig
@ 2024-06-12 13:52 ` Jeff Layton
1 sibling, 0 replies; 3+ messages in thread
From: Jeff Layton @ 2024-06-12 13:52 UTC (permalink / raw)
To: cel, linux-nfs
Cc: Neil Brown, Dai Ngo, Olga Kornievskaia, Tom Talpey, Chuck Lever,
Christoph Hellwig
On Tue, 2024-06-11 at 15:36 -0400, cel@kernel.org wrote:
> From: Chuck Lever <chuck.lever@oracle.com>
>
> 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 <hch@lst.de>
> X-Cc: stable@vger.kernel.org # v6.6+
> Message-Id: 4E9C0D74-A06D-4DC3-A48A-73034DC40395@oracle.com
> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
> ---
> fs/nfsd/nfs4proc.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
> index 46bd20fe5c0f..2e39cf2e502a 100644
> --- a/fs/nfsd/nfs4proc.c
> +++ b/fs/nfsd/nfs4proc.c
> @@ -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;
>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-06-12 13:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-11 19:36 [PATCH v2] NFSD: Support write delegations in LAYOUTGET cel
2024-06-12 5:08 ` Christoph Hellwig
2024-06-12 13:52 ` Jeff Layton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox