Skip to contentSkip to conversation

sunrpc: instantiate rpc_pipefs dentry before publishing it

PATCH In review Avi Weiss 2 participants 4 messages Oct 19

Subsystems (3)
lore
Share & tools
lore

Avi Weiss

author
#0 lore raw

PATCH 1/1 sunrpc: instantiate rpc_pipefs dentry before publishing it

rpc_mkpipe_dentry() publishes pipe->dentry before d_make_persistent() attaches its inode. A concurrent rpc_queue_upcall() or rpc_timeout_upcall_queue() can conceivably dereference the dentry while d_inode() is NULL.

Attach the inode before publishing the dentry, restoring the ordering used before the rpc_pipefs conversion refactor.

Fixes 946e2256775e ("convert rpc_pipefs")

---

Build-tested with x86 defconfig, CONFIG_SUNRPC=y, and W=1 using the net/sunrpc/rpc_pipe.o target.
Runtime concurrency reproducer: not run.

 net/sunrpc/rpc_pipe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sunrpc/rpc_pipe.c +1 -1
index 9d349cfbc4831..6d005231bc334 100644
@@ -665,8 +665,8 @@ int rpc_mkpipe_dentry(struct dentry *parent, const char *name,
 	rpci->private = private;
 	rpci->pipe = pipe;
 	rpc_inode_setowner(inode, private);
-	pipe->dentry = dentry; // borrowed
 	d_make_persistent(dentry, inode);
+	pipe->dentry = dentry; // borrowed
 	fsnotify_create(dir, dentry);
 	simple_done_creating(dentry);
 	return 0;

base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222

Signature · 1 line
2.43.0
#1 lore raw
Quoted 4 lines · Avi Weiss

rpc_mkpipe_dentry() publishes pipe->dentry before d_make_persistent() attaches its inode. A concurrent rpc_queue_upcall() or rpc_timeout_upcall_queue() can conceivably dereference the dentry while d_inode() is NULL.

Details, please... I have no objections against the reordering per se, but I would like to understand the scenario leading to such a concurrent call.

author
#2 lore raw

I was thinking of, for example, an existing NFSv4 client when rpc_pipefs is mounted later. The mount creates the dentry for it's idmap pipe, while an owner/group lookup could queue a legacy idmap upcall on the same pipe.

The upcall doesn't take pipefs_sb_lock, and rpc_queue_upcall() uses d_inode() once pipe->dentry is non-NULL, even with no readers. That seems like it could leave a window before d_make_persistent() completes.

I think there are other ways possible as well.

Quoted 10 lines · Al Viro
Quoted 4 lines · Avi Weiss

rpc_mkpipe_dentry() publishes pipe->dentry before d_make_persistent() attaches its inode. A concurrent rpc_queue_upcall() or rpc_timeout_upcall_queue() can conceivably dereference the dentry while d_inode() is NULL.

Details, please... I have no objections against the reordering per se, but I would like to understand the scenario leading to such a concurrent call.

author
#3 lore raw
In reply to Al Viro

I was thinking of, for example, an existing NFSv4 client when rpc_pipefs is mounted later. The mount creates the dentry for it's idmap pipe, while an owner/group lookup could queue a legacy idmap upcall on the same pipe.

The upcall doesn't take pipefs_sb_lock, and rpc_queue_upcall() uses d_inode() once pipe->dentry is non-NULL, even with no readers. That seems like it could leave a window before d_make_persistent() completes.

I think there are other ways possible as well.

Quoted 10 lines · Al Viro
Quoted 4 lines · Avi Weiss

rpc_mkpipe_dentry() publishes pipe->dentry before d_make_persistent() attaches its inode. A concurrent rpc_queue_upcall() or rpc_timeout_upcall_queue() can conceivably dereference the dentry while d_inode() is NULL.

Details, please... I have no objections against the reordering per se, but I would like to understand the scenario leading to such a concurrent call.