From: Andrey Ryabinin <aryabinin@virtuozzo.com>
To: Vlastimil Babka <vbabka@suse.cz>, Miklos Szeredi <miklos@szeredi.hu>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v2 1/3] fs/fuse, splice_write: Don't access pipe->buffers without pipe_lock()
Date: Thu, 13 Jun 2019 12:10:19 +0300 [thread overview]
Message-ID: <3fcf7f4f-a9c0-f9c8-f526-ab12e283cd43@virtuozzo.com> (raw)
In-Reply-To: <b7aceb99-9631-cbcf-fdec-3abef72c949d@suse.cz>
On 6/12/19 11:57 AM, Vlastimil Babka wrote:
> On 7/17/18 6:00 PM, Andrey Ryabinin wrote:
>> fuse_dev_splice_write() reads pipe->buffers to determine the size of
>> 'bufs' array before taking the pipe_lock(). This is not safe as
>> another thread might change the 'pipe->buffers' between the allocation
>> and taking the pipe_lock(). So we end up with too small 'bufs' array.
>>
>> Move the bufs allocations inside pipe_lock()/pipe_unlock() to fix this.
>>
>> Fixes: dd3bb14f44a6 ("fuse: support splice() writing to fuse device")
>> Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
>> Cc: <stable@vger.kernel.org>
>
> BTW, why don't we need to do the same in fuse_dev_splice_read()?
>
do_splice() already takes the pipe_lock() before calling ->splice_read()
> Thanks,
> Vlastimil
>
>> ---
>> fs/fuse/dev.c | 7 +++++--
>> 1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
>> index c6b88fa85e2e..702592cce546 100644
>> --- a/fs/fuse/dev.c
>> +++ b/fs/fuse/dev.c
>> @@ -1944,12 +1944,15 @@ static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
>> if (!fud)
>> return -EPERM;
>>
>> + pipe_lock(pipe);
>> +
>> bufs = kmalloc_array(pipe->buffers, sizeof(struct pipe_buffer),
>> GFP_KERNEL);
>> - if (!bufs)
>> + if (!bufs) {
>> + pipe_unlock(pipe);
>> return -ENOMEM;
>> + }
>>
>> - pipe_lock(pipe);
>> nbuf = 0;
>> rem = 0;
>> for (idx = 0; idx < pipe->nrbufs && rem < len; idx++)
>>
>
prev parent reply other threads:[~2019-06-13 15:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-16 16:03 [PATCH 1/2] fs/fuse, splice: use kvmalloc to allocate array of pipe_buffer structs Andrey Ryabinin
2018-07-16 16:03 ` [PATCH 2/2] fs/fuse, splice_write: reduce allocation size Andrey Ryabinin
2018-07-17 14:47 ` Miklos Szeredi
2018-07-17 15:45 ` Andrey Ryabinin
2018-07-17 16:00 ` [PATCH v2 1/3] fs/fuse, splice_write: Don't access pipe->buffers without pipe_lock() Andrey Ryabinin
2018-07-17 16:00 ` [PATCH v2 2/3] fs/fuse, splice: use kvmalloc to allocate array of pipe_buffer structs Andrey Ryabinin
2018-07-17 16:00 ` [PATCH v2 3/3] fs/fuse, splice_write: reduce allocation size Andrey Ryabinin
2019-06-12 8:57 ` [PATCH v2 1/3] fs/fuse, splice_write: Don't access pipe->buffers without pipe_lock() Vlastimil Babka
2019-06-13 9:10 ` Andrey Ryabinin [this message]
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=3fcf7f4f-a9c0-f9c8-f526-ab12e283cd43@virtuozzo.com \
--to=aryabinin@virtuozzo.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=stable@vger.kernel.org \
--cc=vbabka@suse.cz \
/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).