linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Ted Tso <tytso@mit.edu>
Cc: linux-ext4@vger.kernel.org, Jan Kara <jack@suse.cz>
Subject: [PATCH 2/4] ext4: Fix overflows in SEEK_HOLE, SEEK_DATA implementations
Date: Wed, 29 May 2013 14:05:31 +0200	[thread overview]
Message-ID: <1369829133-4307-3-git-send-email-jack@suse.cz> (raw)
In-Reply-To: <1369829133-4307-1-git-send-email-jack@suse.cz>

ext4_lblk_t is just u32 so multiplying it by blocksize can easily
overflow for files larger than 4 GB. Fix that by properly typing the
block offsets before shifting.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/ext4/file.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index b1b4d51..b19f0a4 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -312,7 +312,7 @@ static int ext4_find_unwritten_pgoff(struct inode *inode,
 	blkbits = inode->i_sb->s_blocksize_bits;
 	startoff = *offset;
 	lastoff = startoff;
-	endoff = (map->m_lblk + map->m_len) << blkbits;
+	endoff = (loff_t)(map->m_lblk + map->m_len) << blkbits;
 
 	index = startoff >> PAGE_CACHE_SHIFT;
 	end = endoff >> PAGE_CACHE_SHIFT;
@@ -457,7 +457,7 @@ static loff_t ext4_seek_data(struct file *file, loff_t offset, loff_t maxsize)
 		ret = ext4_map_blocks(NULL, inode, &map, 0);
 		if (ret > 0 && !(map.m_flags & EXT4_MAP_UNWRITTEN)) {
 			if (last != start)
-				dataoff = last << blkbits;
+				dataoff = (loff_t)last << blkbits;
 			break;
 		}
 
@@ -468,7 +468,7 @@ static loff_t ext4_seek_data(struct file *file, loff_t offset, loff_t maxsize)
 		ext4_es_find_delayed_extent_range(inode, last, last, &es);
 		if (es.es_len != 0 && in_range(last, es.es_lblk, es.es_len)) {
 			if (last != start)
-				dataoff = last << blkbits;
+				dataoff = (loff_t)last << blkbits;
 			break;
 		}
 
@@ -486,7 +486,7 @@ static loff_t ext4_seek_data(struct file *file, loff_t offset, loff_t maxsize)
 		}
 
 		last++;
-		dataoff = last << blkbits;
+		dataoff = (loff_t)last << blkbits;
 	} while (last <= end);
 
 	mutex_unlock(&inode->i_mutex);
@@ -540,7 +540,7 @@ static loff_t ext4_seek_hole(struct file *file, loff_t offset, loff_t maxsize)
 		ret = ext4_map_blocks(NULL, inode, &map, 0);
 		if (ret > 0 && !(map.m_flags & EXT4_MAP_UNWRITTEN)) {
 			last += ret;
-			holeoff = last << blkbits;
+			holeoff = (loff_t)last << blkbits;
 			continue;
 		}
 
@@ -551,7 +551,7 @@ static loff_t ext4_seek_hole(struct file *file, loff_t offset, loff_t maxsize)
 		ext4_es_find_delayed_extent_range(inode, last, last, &es);
 		if (es.es_len != 0 && in_range(last, es.es_lblk, es.es_len)) {
 			last = es.es_lblk + es.es_len;
-			holeoff = last << blkbits;
+			holeoff = (loff_t)last << blkbits;
 			continue;
 		}
 
@@ -566,7 +566,7 @@ static loff_t ext4_seek_hole(struct file *file, loff_t offset, loff_t maxsize)
 							      &map, &holeoff);
 			if (!unwritten) {
 				last += ret;
-				holeoff = last << blkbits;
+				holeoff = (loff_t)last << blkbits;
 				continue;
 			}
 		}
-- 
1.8.1.4


  parent reply	other threads:[~2013-05-29 12:05 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-29 12:05 [PATCH 0/4] ext4: Fix overflows in ext4 code Jan Kara
2013-05-29 12:05 ` [PATCH 1/4] ext4: Fix data offset overflow on 32-bit archs in ext4_inline_data_fiemap() Jan Kara
2013-05-29 12:05 ` Jan Kara [this message]
2013-05-29 13:51   ` [PATCH 2/4] ext4: Fix overflows in SEEK_HOLE, SEEK_DATA implementations Zheng Liu
2013-05-29 12:05 ` [PATCH 3/4] ext4: Fix data offset overflow in ext4_xattr_fiemap() on 32-bit archs Jan Kara
2013-05-29 12:05 ` [PATCH 4/4] ext4: Fix overflow when counting used blocks on 32-bit architectures Jan Kara
2013-05-31 23:42   ` Theodore Ts'o
2013-07-09 14:14 ` [PATCH 0/4] ext4: Fix overflows in ext4 code Eric Sandeen
2013-07-09 14:38   ` Theodore Ts'o
2013-07-09 14:39     ` [PATCH 1/4] ext4: fix data offset overflow on 32-bit archs in ext4_inline_data_fiemap() Theodore Ts'o
2013-07-09 14:39       ` [PATCH 2/4] ext4: fix overflows in SEEK_HOLE, SEEK_DATA implementations Theodore Ts'o
2013-07-09 14:39       ` [PATCH 3/4] ext4: fix data offset overflow in ext4_xattr_fiemap() on 32-bit archs Theodore Ts'o
2013-07-09 14:39       ` [PATCH 4/4] ext4: fix overflow when counting used blocks on 32-bit architectures Theodore Ts'o
2013-07-09 15:00     ` [PATCH 0/4] ext4: Fix overflows in ext4 code Eric Sandeen
2013-07-10 15:40     ` Luis Henriques
2013-07-12 13:15     ` Josh Boyer
2013-07-12 14:50       ` Greg KH
2013-07-24  4:46     ` Ben Hutchings

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=1369829133-4307-3-git-send-email-jack@suse.cz \
    --to=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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).