From: Chuck Lever <cel@kernel.org>
To: NeilBrown <neil@brown.name>, Jeff Layton <jlayton@kernel.org>,
Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <dai.ngo@oracle.com>, Tom Talpey <tom@talpey.com>
Cc: <linux-nfs@vger.kernel.org>, Chuck Lever <chuck.lever@oracle.com>
Subject: [PATCH v2 1/2] nfsd: prevent write delegations when client has existing opens
Date: Tue, 2 Dec 2025 17:42:07 -0500 [thread overview]
Message-ID: <20251202224208.4449-1-cel@kernel.org> (raw)
From: Chuck Lever <chuck.lever@oracle.com>
When a client holds an existing OPEN stateid for a file and then
requests a new OPEN that could receive a write delegation, the
server must not grant that delegation. A write delegation promises
the client it can handle "all opens" locally, but this promise is
violated when the server is already tracking open state for that
same client.
Currently, nfsd4_check_conflicting_opens() prevents write
delegations only when other clients have write opens. It does not
check for existing opens from the same client. This creates a
problematic situation:
1. Client opens file O_RDONLY, gets READ delegation (or just OPEN)
2. Client returns READ delegation but keeps the OPEN stateid
3. Client opens same file O_WRONLY
4. Server grants WRITE delegation
5. nfsd4_add_rdaccess_to_wrdeleg() tries to add READ access
6. Finds fp->fi_fds[O_RDONLY] already set from step 1
Seen with generic/750 over NFSv4.1.
Fixes: 1d3dd1d56ce8 ("NFSD: Enable write delegation support")
X-Cc: stable@vger.kernel.org
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
fs/nfsd/nfs4state.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
Changes since v1:
* This patch replaces https://lore.kernel.org/linux-nfs/20251201220955.1949-1-cel@kernel.org/
* 2/2 adds a canary where this bug was caught
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 35004568d43e..1c9802d06de1 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -5947,11 +5947,16 @@ static int nfsd4_check_conflicting_opens(struct nfs4_client *clp,
*/
spin_lock(&fp->fi_lock);
list_for_each_entry(st, &fp->fi_stateids, st_perfile) {
- if (st->st_openstp == NULL /* it's an open */ &&
- access_permit_write(st) &&
- st->st_stid.sc_client != clp) {
- spin_unlock(&fp->fi_lock);
- return -EAGAIN;
+ if (st->st_openstp == NULL /* it's an open */) {
+ if (st->st_stid.sc_client != clp &&
+ access_permit_write(st)) {
+ spin_unlock(&fp->fi_lock);
+ return -EAGAIN;
+ }
+ if (st->st_stid.sc_client == clp) {
+ spin_unlock(&fp->fi_lock);
+ return -EAGAIN;
+ }
}
}
spin_unlock(&fp->fi_lock);
--
2.52.0
next reply other threads:[~2025-12-02 22:42 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-02 22:42 Chuck Lever [this message]
2025-12-02 22:42 ` [PATCH v2 2/2] NFSD: WARN if fi_fds[O_RDONLY] is already populated Chuck Lever
2025-12-03 12:28 ` Jeff Layton
2025-12-02 23:28 ` [PATCH v2 1/2] nfsd: prevent write delegations when client has existing opens NeilBrown
2025-12-03 1:43 ` Chuck Lever
2025-12-03 2:31 ` NeilBrown
2025-12-03 12:26 ` Jeff Layton
2025-12-03 14:54 ` Chuck Lever
2025-12-03 14:56 ` Jeff Layton
2025-12-03 22:45 ` NeilBrown
2025-12-04 1:06 ` Chuck Lever
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251202224208.4449-1-cel@kernel.org \
--to=cel@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=dai.ngo@oracle.com \
--cc=jlayton@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=neil@brown.name \
--cc=okorniev@redhat.com \
--cc=tom@talpey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).