]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
fuse: fix pipe buffer lifetime for direct_io
authorMiklos Szeredi <mszeredi@redhat.com>
Mon, 7 Mar 2022 15:30:44 +0000 (16:30 +0100)
committerPaolo Pisati <paolo.pisati@canonical.com>
Wed, 23 Mar 2022 10:49:04 +0000 (11:49 +0100)
commitdfc22d1396c9061aa52df27c3ac596acedc07727
tree1b2194811ac90986ad984cd0575313d874a9217e
parent7a2dda78c7d1a5031cd5d67e8aea76bf0ab0cd96
fuse: fix pipe buffer lifetime for direct_io

BugLink: https://bugs.launchpad.net/bugs/1966056
commit 0c4bcfdecb1ac0967619ee7ff44871d93c08c909 upstream.

In FOPEN_DIRECT_IO mode, fuse_file_write_iter() calls
fuse_direct_write_iter(), which normally calls fuse_direct_io(), which then
imports the write buffer with fuse_get_user_pages(), which uses
iov_iter_get_pages() to grab references to userspace pages instead of
actually copying memory.

On the filesystem device side, these pages can then either be read to
userspace (via fuse_dev_read()), or splice()d over into a pipe using
fuse_dev_splice_read() as pipe buffers with &nosteal_pipe_buf_ops.

This is wrong because after fuse_dev_do_read() unlocks the FUSE request,
the userspace filesystem can mark the request as completed, causing write()
to return. At that point, the userspace filesystem should no longer have
access to the pipe buffer.

Fix by copying pages coming from the user address space to new pipe
buffers.

Reported-by: Jann Horn <jannh@google.com>
Fixes: c3021629a0d8 ("fuse: support splice() reading from fuse device")
Cc: <stable@vger.kernel.org>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
fs/fuse/dev.c
fs/fuse/file.c
fs/fuse/fuse_i.h