All of lore.kernel.org
 help / color / mirror / Atom feed
From: Theodore Ts'o <tytso@mit.edu>
To: stable@vger.kernel.org
Cc: Ext4 Developers List <linux-ext4@vger.kernel.org>,
	Jan Kara <jack@suse.cz>, Theodore Ts'o <tytso@mit.edu>
Subject: [PATCH 4/4] ext4: fix overflow when counting used blocks on 32-bit architectures
Date: Tue,  9 Jul 2013 10:39:32 -0400	[thread overview]
Message-ID: <1373380772-16803-4-git-send-email-tytso@mit.edu> (raw)
In-Reply-To: <1373380772-16803-1-git-send-email-tytso@mit.edu>

From: Jan Kara <jack@suse.cz>

The arithmetics adding delalloc blocks to the number of used blocks in
ext4_getattr() can easily overflow on 32-bit archs as we first multiply
number of blocks by blocksize and then divide back by 512. Make the
arithmetics more clever and also use proper type (unsigned long long
instead of unsigned long).

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
 fs/ext4/inode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 0fca5a8..38f03dc 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -4702,7 +4702,7 @@ int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
 		 struct kstat *stat)
 {
 	struct inode *inode;
-	unsigned long delalloc_blocks;
+	unsigned long long delalloc_blocks;
 
 	inode = dentry->d_inode;
 	generic_fillattr(inode, stat);
@@ -4720,7 +4720,7 @@ int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
 	delalloc_blocks = EXT4_C2B(EXT4_SB(inode->i_sb),
 				EXT4_I(inode)->i_reserved_data_blocks);
 
-	stat->blocks += (delalloc_blocks << inode->i_sb->s_blocksize_bits)>>9;
+	stat->blocks += delalloc_blocks << (inode->i_sb->s_blocksize_bits-9);
 	return 0;
 }
 
-- 
1.7.12.rc0.22.gcdd159b


  parent reply	other threads:[~2013-07-09 14:39 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 ` [PATCH 2/4] ext4: Fix overflows in SEEK_HOLE, SEEK_DATA implementations Jan Kara
2013-05-29 13:51   ` 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       ` Theodore Ts'o [this message]
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=1373380772-16803-4-git-send-email-tytso@mit.edu \
    --to=tytso@mit.edu \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /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.