* [PATCH 1/3] ext4: verify group number in verify_group_input() before using it
@ 2013-06-06 15:41 Theodore Ts'o
2013-06-06 15:41 ` [PATCH 2/3] ext4: add sanity check to ext4_get_group_info() Theodore Ts'o
2013-06-06 15:41 ` [PATCH 3/3] ext4: optimize test_root() Theodore Ts'o
0 siblings, 2 replies; 3+ messages in thread
From: Theodore Ts'o @ 2013-06-06 15:41 UTC (permalink / raw)
To: Ext4 Developers List; +Cc: Theodore Ts'o
Check the group number for sanity earilier, before calling routines
such as ext4_bg_has_super() or ext4_group_overhead_blocks().
Reported-by: Jonathan Salwan <jonathan.salwan@gmail.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
---
fs/ext4/resize.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index b27c96d..6ed4df2 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -79,12 +79,20 @@ static int verify_group_input(struct super_block *sb,
ext4_fsblk_t end = start + input->blocks_count;
ext4_group_t group = input->group;
ext4_fsblk_t itend = input->inode_table + sbi->s_itb_per_group;
- unsigned overhead = ext4_group_overhead_blocks(sb, group);
- ext4_fsblk_t metaend = start + overhead;
+ unsigned overhead;
+ ext4_fsblk_t metaend;
struct buffer_head *bh = NULL;
ext4_grpblk_t free_blocks_count, offset;
int err = -EINVAL;
+ if (group != sbi->s_groups_count) {
+ ext4_warning(sb, "Cannot add at group %u (only %u groups)",
+ input->group, sbi->s_groups_count);
+ return -EINVAL;
+ }
+
+ overhead = ext4_group_overhead_blocks(sb, group);
+ metaend = start + overhead;
input->free_blocks_count = free_blocks_count =
input->blocks_count - 2 - overhead - sbi->s_itb_per_group;
@@ -96,10 +104,7 @@ static int verify_group_input(struct super_block *sb,
free_blocks_count, input->reserved_blocks);
ext4_get_group_no_and_offset(sb, start, NULL, &offset);
- if (group != sbi->s_groups_count)
- ext4_warning(sb, "Cannot add at group %u (only %u groups)",
- input->group, sbi->s_groups_count);
- else if (offset != 0)
+ if (offset != 0)
ext4_warning(sb, "Last group not full");
else if (input->reserved_blocks > input->blocks_count / 5)
ext4_warning(sb, "Reserved blocks too high (%u)",
--
1.7.12.rc0.22.gcdd159b
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 2/3] ext4: add sanity check to ext4_get_group_info()
2013-06-06 15:41 [PATCH 1/3] ext4: verify group number in verify_group_input() before using it Theodore Ts'o
@ 2013-06-06 15:41 ` Theodore Ts'o
2013-06-06 15:41 ` [PATCH 3/3] ext4: optimize test_root() Theodore Ts'o
1 sibling, 0 replies; 3+ messages in thread
From: Theodore Ts'o @ 2013-06-06 15:41 UTC (permalink / raw)
To: Ext4 Developers List; +Cc: Theodore Ts'o
The group number passed to ext4_get_group_info() should be valid, but
let's add an assert to check this before we start creating a pointer
based on that group number and dereferencing it.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
---
fs/ext4/ext4.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index bd9890f..f85f1fb 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -2313,6 +2313,7 @@ struct ext4_group_info *ext4_get_group_info(struct super_block *sb,
{
struct ext4_group_info ***grp_info;
long indexv, indexh;
+ BUG_ON(group >= EXT4_SB(sb)->s_groups_count);
grp_info = EXT4_SB(sb)->s_group_info;
indexv = group >> (EXT4_DESC_PER_BLOCK_BITS(sb));
indexh = group & ((EXT4_DESC_PER_BLOCK(sb)) - 1);
--
1.7.12.rc0.22.gcdd159b
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 3/3] ext4: optimize test_root()
2013-06-06 15:41 [PATCH 1/3] ext4: verify group number in verify_group_input() before using it Theodore Ts'o
2013-06-06 15:41 ` [PATCH 2/3] ext4: add sanity check to ext4_get_group_info() Theodore Ts'o
@ 2013-06-06 15:41 ` Theodore Ts'o
1 sibling, 0 replies; 3+ messages in thread
From: Theodore Ts'o @ 2013-06-06 15:41 UTC (permalink / raw)
To: Ext4 Developers List; +Cc: Theodore Ts'o
The test_root() function could potentially loop forever due to
overflow issues. So rewrite test_root() to avoid this issue; as a
bonus, it is 38% faster when benchmarked via a test loop:
int main(int argc, char **argv)
{
int i;
for (i = 0; i < 1 << 24; i++) {
if (test_root(i, 7))
printf("%d\n", i);
}
}
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
---
fs/ext4/balloc.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index d0f13ea..5833939 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -682,11 +682,15 @@ ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb)
static inline int test_root(ext4_group_t a, int b)
{
- int num = b;
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-06-06 15:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-06 15:41 [PATCH 1/3] ext4: verify group number in verify_group_input() before using it Theodore Ts'o
2013-06-06 15:41 ` [PATCH 2/3] ext4: add sanity check to ext4_get_group_info() Theodore Ts'o
2013-06-06 15:41 ` [PATCH 3/3] ext4: optimize test_root() Theodore Ts'o
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).