From: Zhihao Cheng <chengzhihao1@huawei.com>
To: Jan Kara <jack@suse.cz>
Cc: <tytso@mit.edu>, <adilger.kernel@dilger.ca>, <jack@suse.com>,
<tudor.ambarus@linaro.org>, <linux-ext4@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <yi.zhang@huawei.com>
Subject: Re: [PATCH] ext4: Fix i_disksize exceeding i_size problem in paritally written case
Date: Sat, 18 Mar 2023 15:03:30 +0800 [thread overview]
Message-ID: <884950ac-e60a-d331-9f68-310ab81ee595@huawei.com> (raw)
In-Reply-To: <20230317124513.drx3wywcjnap5jme@quack3>
Hi, Jan
> On Fri 17-03-23 09:35:53, Zhihao Cheng wrote:
>> Following process makes i_disksize exceed i_size:
>>
>> generic_perform_write
>> copied = iov_iter_copy_from_user_atomic(len) // copied < len
>> ext4_da_write_end
>> | ext4_update_i_disksize
>> | new_i_size = pos + copied;
>> | WRITE_ONCE(EXT4_I(inode)->i_disksize, newsize) // update i_disksize
>> | generic_write_end
>> | copied = block_write_end(copied, len) // copied = 0
>> | if (unlikely(copied < len))
>> | if (!PageUptodate(page))
>> | copied = 0;
>> | if (pos + copied > inode->i_size) // return false
>> if (unlikely(copied == 0))
>> goto again;
>> if (unlikely(iov_iter_fault_in_readable(i, bytes))) {
>> status = -EFAULT;
>> break;
>> }
>>
>> We get i_disksize greater than i_size here, which could trigger WARNING
>> check 'i_size_read(inode) < EXT4_I(inode)->i_disksize' while doing dio:
>>
>> ext4_dio_write_iter
>> iomap_dio_rw
>> __iomap_dio_rw // return err, length is not aligned to 512
>> ext4_handle_inode_extension
>> WARN_ON_ONCE(i_size_read(inode) < EXT4_I(inode)->i_disksize) // Oops
>>
>> WARNING: CPU: 2 PID: 2609 at fs/ext4/file.c:319
>> CPU: 2 PID: 2609 Comm: aa Not tainted 6.3.0-rc2
>> RIP: 0010:ext4_file_write_iter+0xbc7
>> Call Trace:
>> vfs_write+0x3b1
>> ksys_write+0x77
>> do_syscall_64+0x39
>>
>> Fix it by putting block_write_end() before i_disksize updating just
>> like ext4_write_end() does.
>>
>> Fetch a reproducer in [Link].
>>
>> Link: https://bugzilla.kernel.org/show_bug.cgi?id=217209
>> Fixes: 64769240bd07f ("ext4: Add delayed allocation support in data=writeback mode")
>> Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
>
> Good catch (although practically this will hardly have any negative
> effect). But rather than opencoding generic_write_end() I'd do:
>
> if (unlikely(copied < len) && !PageUptodate(page))
> copied = 0;
>
> at the beginning of ext4_da_write_end() and that should solve these
> problems as well?
>
Yes, your suggestion looks good, and I think we can put the checking
just after ext4_write_inline_data_end(Line 3150)? On the one hand, we
can pass original 'copied' value in trace_ext4_da_write_end(), one the
other hand, ext4_write_inline_data_end() already has this checking.
next prev parent reply other threads:[~2023-03-18 7:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-17 1:35 [PATCH] ext4: Fix i_disksize exceeding i_size problem in paritally written case Zhihao Cheng
2023-03-17 12:45 ` Jan Kara
2023-03-18 7:03 ` Zhihao Cheng [this message]
2023-03-18 8:51 ` Zhihao Cheng
2023-03-20 11:20 ` Jan Kara
2023-03-20 12:49 ` Zhihao Cheng
2023-03-20 16:24 ` Jan Kara
2023-03-21 1:29 ` Zhihao Cheng
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=884950ac-e60a-d331-9f68-310ab81ee595@huawei.com \
--to=chengzhihao1@huawei.com \
--cc=adilger.kernel@dilger.ca \
--cc=jack@suse.com \
--cc=jack@suse.cz \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tudor.ambarus@linaro.org \
--cc=tytso@mit.edu \
--cc=yi.zhang@huawei.com \
/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