WSL2-Linux-Kernel/fs/fuse
Kirill Smelkov 1e0a2528fb fuse: retrieve: cap requested size to negotiated max_write
[ Upstream commit 7640682e67 ]

FUSE filesystem server and kernel client negotiate during initialization
phase, what should be the maximum write size the client will ever issue.
Correspondingly the filesystem server then queues sys_read calls to read
requests with buffer capacity large enough to carry request header + that
max_write bytes. A filesystem server is free to set its max_write in
anywhere in the range between [1*page, fc->max_pages*page]. In particular
go-fuse[2] sets max_write by default as 64K, wheres default fc->max_pages
corresponds to 128K. Libfuse also allows users to configure max_write, but
by default presets it to possible maximum.

If max_write is < fc->max_pages*page, and in NOTIFY_RETRIEVE handler we
allow to retrieve more than max_write bytes, corresponding prepared
NOTIFY_REPLY will be thrown away by fuse_dev_do_read, because the
filesystem server, in full correspondence with server/client contract, will
be only queuing sys_read with ~max_write buffer capacity, and
fuse_dev_do_read throws away requests that cannot fit into server request
buffer. In turn the filesystem server could get stuck waiting indefinitely
for NOTIFY_REPLY since NOTIFY_RETRIEVE handler returned OK which is
understood by clients as that NOTIFY_REPLY was queued and will be sent
back.

Cap requested size to negotiate max_write to avoid the problem.  This
aligns with the way NOTIFY_RETRIEVE handler works, which already
unconditionally caps requested retrieve size to fuse_conn->max_pages.  This
way it should not hurt NOTIFY_RETRIEVE semantic if we return less data than
was originally requested.

Please see [1] for context where the problem of stuck filesystem was hit
for real, how the situation was traced and for more involving patch that
did not make it into the tree.

[1] https://marc.info/?l=linux-fsdevel&m=155057023600853&w=2
[2] https://github.com/hanwen/go-fuse

Signed-off-by: Kirill Smelkov <kirr@nexedi.com>
Cc: Han-Wen Nienhuys <hanwen@google.com>
Cc: Jakob Unterwurzacher <jakobunt@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-06-15 11:54:54 +02:00
..
Kconfig fuse: Add posix ACL support 2016-10-01 07:32:32 +02:00
Makefile fuse: Use generic xattr ops 2016-10-01 07:32:32 +02:00
acl.c fuse: Add posix ACL support 2016-10-01 07:32:32 +02:00
control.c fuse: fix control dir setup and teardown 2018-07-03 11:24:49 +02:00
cuse.c fuse: honor iocb sync flags on write 2017-09-12 16:57:53 +02:00
dev.c fuse: retrieve: cap requested size to negotiated max_write 2019-06-15 11:54:54 +02:00
dir.c fuse: continue to send FUSE_RELEASEDIR when FUSE_OPEN returns ENOSYS 2018-12-21 14:13:05 +01:00
file.c fuse: Add FOPEN_STREAM to use stream_open() 2019-06-11 12:21:51 +02:00
fuse_i.h fuse: continue to send FUSE_RELEASEDIR when FUSE_OPEN returns ENOSYS 2018-12-21 14:13:05 +01:00
inode.c fuse: Fix oops at process_init_reply() 2018-09-05 09:26:38 +02:00
xattr.c fuse: limit xattr returned size 2016-10-03 11:06:05 +02:00