All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nfs: fix NULL deference in nfs4_get_valid_delegation
@ 2020-05-08 22:19 J. Bruce Fields
  2020-05-11 12:10 ` Masayoshi Mizuma
  0 siblings, 1 reply; 9+ messages in thread
From: J. Bruce Fields @ 2020-05-08 22:19 UTC (permalink / raw)
  To: Trond Myklebust, Anna Schumaker; +Cc: linux-nfs

From: "J. Bruce Fields" <bfields@redhat.com>

We add the new state to the nfsi->open_states list, making it
potentially visible to other threads, before we've finished initializing
it.

That wasn't a problem when all the readers were also taking the i_lock
(as we do here), but since we switched to RCU, there's now a possibility
that a reader could see the partially initialized state.

Symptoms observed were a crash when another thread called
nfs4_get_valid_delegation() on a NULL inode.

Fixes: 9ae075fdd190 "NFSv4: Convert open state lookup to use RCU"
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
---
 fs/nfs/nfs4state.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index ac93715c05a4..a8dc25ce48bb 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -734,9 +734,9 @@ nfs4_get_open_state(struct inode *inode, struct nfs4_state_owner *owner)
 		state = new;
 		state->owner = owner;
 		atomic_inc(&owner->so_count);
-		list_add_rcu(&state->inode_states, &nfsi->open_states);
 		ihold(inode);
 		state->inode = inode;
+		list_add_rcu(&state->inode_states, &nfsi->open_states);
 		spin_unlock(&inode->i_lock);
 		/* Note: The reclaim code dictates that we add stateless
 		 * and read-only stateids to the end of the list */
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-05-11 17:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-08 22:19 [PATCH] nfs: fix NULL deference in nfs4_get_valid_delegation J. Bruce Fields
2020-05-11 12:10 ` Masayoshi Mizuma
2020-05-11 13:16   ` J. Bruce Fields
2020-05-11 13:43     ` Trond Myklebust
2020-05-11 13:57       ` bfields
2020-05-11 14:01         ` bfields
2020-05-11 14:02           ` bfields
2020-05-11 17:37             ` Masayoshi Mizuma
2020-05-11 17:39               ` bfields

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.