From: majianpeng <majianpeng@gmail.com>
To: "Andrew Morton" <akpm@linux-foundation.org>,
"viro@ZenIV.linux.org.uk" <viro@ZenIV.linux.org.uk>
Cc: linux-fsdevel <linux-fsdevel@vger.kernel.org>,
linux-mm <linux-mm@kvack.org>
Subject: Re: [RFC] block_dev:Fix bug when read/write block-device which is larger than 16TB in 32bit-OS.
Date: Tue, 24 Jul 2012 20:44:27 +0800 [thread overview]
Message-ID: <201207242044249532601@gmail.com> (raw)
In-Reply-To: 201205291656322966937@gmail.com
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="gb2312", Size: 3822 bytes --]
On 2012-05-29 16:56 majianpeng <majianpeng@gmail.com> Wrote:
>The size of block-device is larger than 16TB, and the os is 32bit.
>If the offset of read/write is larger then 16TB. The index of address_space will
>overflow and supply data from low offset instead.
>
>when read-operation, in function do_generic_file_read():
>>index = *ppos >> PAGE_CACHE_SHIFT;
>Because the *ppos is larger than 16TB and the index is the type pgoff_t which 32bit
>in 32bit-OS. So index will overflow.
>
>When write-operation, in function generic_write_checks():
>>if (likely(!isblk)) {
>> .....
>> } else {
>>#ifdef CONFIG_BLOCK
>> loff_t isize;
>> if (bdev_read_only(I_BDEV(inode)))
> return -EPERM;
>> isize = i_size_read(inode);
>> if (*pos >= isize) {
>> if (*count || *pos > isize)
>> return -ENOSPC;
>> }
>>
>> if (*pos + *count > isize)
>> *count = isize - *pos;
>The code only check size.But continue code:
>generic_file_buffered_write-->generic_perform_write-->blkdev_write_begin
>--->block_write_begin()
>> pgoff_t index = pos >> PAGE_CACHE_SHIFT;
>The index will overflow again.
>
>Although filesystem has a attribute s_maxbytes, the block-device was not create so no affect.
>
>
>Signed-off-by: majianpeng <majianpeng@gmail.com>
>---
> fs/block_dev.c | 4 +++-
> mm/filemap.c | 28 ++++++++++++++++++++++++++++
> 2 files changed, 31 insertions(+), 1 deletion(-)
>
>diff --git a/fs/block_dev.c b/fs/block_dev.c
>index c2bbe1f..1752c0e 100644
>--- a/fs/block_dev.c
>+++ b/fs/block_dev.c
>@@ -382,7 +382,9 @@ static loff_t block_llseek(struct file *file, loff_t offset, int origin)
>
> mutex_lock(&bd_inode->i_mutex);
> size = i_size_read(bd_inode);
>-
>+#if BITS_PER_LONG == 32
>+ size = min_t(loff_t, size, (loff_t)0xFFFFFFFF * PAGE_CACHE_SIZE - 1);
>+#endif
> retval = -EINVAL;
> switch (origin) {
> case SEEK_END:
>diff --git a/mm/filemap.c b/mm/filemap.c
>index 79c4b2b..34a15bf 100644
>--- a/mm/filemap.c
>+++ b/mm/filemap.c
>@@ -1373,6 +1373,25 @@ int generic_segment_checks(const struct iovec *iov,
> }
> EXPORT_SYMBOL(generic_segment_checks);
>
>+static inline
>+int generic_read_block_checks(struct file *file, loff_t *pos, size_t *count)
>+{
>+ struct inode *inode = file->f_mapping->host;
>+ loff_t isize = 0;
>+#if BITS_PER_LONG == 32 && defined(CONFIG_BLOCK)
>+ isize = min_t(loff_t, i_size_read(inode),
>+ (loff_t)0xFFFFFFFF * PAGE_CACHE_SIZE - 1);
>+ if (*pos >= isize) {
>+ if (*count || *pos > isize)
>+ return -ENOSPC;
>+ }
>+
>+ if (*pos + *count > isize)
>+ *count = isize - *pos;
>+#endif
>+ return 0;
>+}
>+
> /**
> * generic_file_aio_read - generic filesystem read routine
> * @iocb: kernel I/O control block
>@@ -1398,6 +1417,11 @@ generic_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
> if (retval)
> return retval;
>
>+ if (S_ISBLK(filp->f_mapping->host->i_mode)) {
>+ retval = generic_read_block_checks(filp, &pos, &count);
>+ if (retval)
>+ return retval;
>+ }
> /* coalesce the iovecs and go direct-to-BIO for O_DIRECT */
> if (filp->f_flags & O_DIRECT) {
> loff_t size;
>@@ -2214,6 +2238,10 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
> if (bdev_read_only(I_BDEV(inode)))
> return -EPERM;
> isize = i_size_read(inode);
>+#if BITS_PER_LONG == 32
>+ isize = min_t(loff_t, isize,
>+ (loff_t)0xFFFFFFFF * PAGE_CACHE_SIZE - 1);
>+#endif
> if (*pos >= isize) {
> if (*count || *pos > isize)
> return -ENOSPC;
>--
>1.7.9.5
How about this patch? ok or error ?
No one to reply? Maybe the patch did no sense.
Thansk!
>
>
>--------------
>majianpeng
>2012-05-29N§²æìr¸zǧu©²Æ {\béì¹»\x1c®&Þ)îÆi¢Ø^nr¶Ý¢j$½§$¢¸\x05¢¹¨è§~'.)îÄÃ,yèm¶ÿÃ\f%{±j+ðèצj)Z·
next prev parent reply other threads:[~2012-07-24 12:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-29 8:56 [RFC] block_dev:Fix bug when read/write block-device which is larger than 16TB in 32bit-OS majianpeng
2012-07-24 12:44 ` majianpeng [this message]
2012-07-24 13:48 ` Christoph Hellwig
2012-07-26 5:22 ` majianpeng
2012-07-27 5:38 ` majianpeng
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=201207242044249532601@gmail.com \
--to=majianpeng@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=viro@ZenIV.linux.org.uk \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.