All of lore.kernel.org
 help / color / mirror / Atom feed
From: Theodore Ts'o <tytso@mit.edu>
To: Ext4 Developers List <linux-ext4@vger.kernel.org>
Cc: kernel@kyup.com, bp@alien8.de, Theodore Ts'o <tytso@mit.edu>
Subject: [PATCH 4/4] ext4: add sanity checking to count_overhead()
Date: Fri, 18 Nov 2016 13:38:42 -0500	[thread overview]
Message-ID: <20161118183842.25682-4-tytso@mit.edu> (raw)
In-Reply-To: <20161118183842.25682-1-tytso@mit.edu>

The commit "ext4: sanity check the block and cluster size at mount
time" should prevent any problems, but in case the superblock is
modified while the file system is mounted, add an extra safety check
to make sure we won't overrun the allocated buffer.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
 fs/ext4/super.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 689c02df1af4..2d8a49d74f56 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -3195,10 +3195,15 @@ static int count_overhead(struct super_block *sb, ext4_group_t grp,
 			ext4_set_bit(s++, buf);
 			count++;
 		}
-		for (j = ext4_bg_num_gdb(sb, grp); j > 0; j--) {
-			ext4_set_bit(EXT4_B2C(sbi, s++), buf);
-			count++;
+		j = ext4_bg_num_gdb(sb, grp);
+		if (s + j > EXT4_BLOCKS_PER_GROUP(sb)) {
+			ext4_error(sb, "Invalid number of block group "
+				   "descriptor blocks: %d", j);
+			j = EXT4_BLOCKS_PER_GROUP(sb) - s;
 		}
+		count += j;
+		for (; j > 0; j--)
+			ext4_set_bit(EXT4_B2C(sbi, s++), buf);
 	}
 	if (!count)
 		return 0;
-- 
2.11.0.rc0.7.gbe5a750


  parent reply	other threads:[~2016-11-18 18:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-18 18:38 [PATCH 1/4] ext4: sanity check the block and cluster size at mount time Theodore Ts'o
2016-11-18 18:38 ` [PATCH 2/4] ext4: fix in-superblock mount options processing Theodore Ts'o
2016-11-18 20:27   ` Eric Biggers
2016-11-18 18:38 ` [PATCH 3/4] ext4: use more strict checks for inodes_per_block on mount Theodore Ts'o
2016-11-18 20:30   ` Eric Biggers
2016-11-18 21:56     ` Theodore Ts'o
2016-11-18 18:38 ` Theodore Ts'o [this message]
2016-11-18 20:02 ` [PATCH 1/4] ext4: sanity check the block and cluster size at mount time Eric Biggers
2016-11-18 21:55   ` Theodore Ts'o

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=20161118183842.25682-4-tytso@mit.edu \
    --to=tytso@mit.edu \
    --cc=bp@alien8.de \
    --cc=kernel@kyup.com \
    --cc=linux-ext4@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.