From 5f50cce9fce62c24f0d7bb911860b1e59e9c0349 Mon Sep 17 00:00:00 2001 From: Chris Mason Date: Mon, 18 Oct 2004 08:55:00 -0700 Subject: [PATCH] [PATCH] reiserfs: small filesystem fix On small filesystems (<128M), make sure not to reference bitmap blocks that don't exist. Thanks to Jan Kara for finding this bug. Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- fs/reiserfs/bitmap.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fs/reiserfs/bitmap.c b/fs/reiserfs/bitmap.c index b5e4498fcfebf..1dae6c8270adf 100644 --- a/fs/reiserfs/bitmap.c +++ b/fs/reiserfs/bitmap.c @@ -236,6 +236,9 @@ static int bmap_hash_id(struct super_block *s, u32 id) { if (!bm) bm = 1; } + /* this can only be true when SB_BMAP_NR = 1 */ + if (bm >= SB_BMAP_NR(s)) + bm = 0; return bm; } @@ -293,6 +296,10 @@ static int scan_bitmap (struct reiserfs_transaction_handle *th, get_bit_address (s, *start, &bm, &off); get_bit_address (s, finish, &end_bm, &end_off); + if (bm > SB_BMAP_NR(s)) + return 0; + if (end_bm > SB_BMAP_NR(s)) + end_bm = SB_BMAP_NR(s); /* When the bitmap is more than 10% free, anyone can allocate. * When it's less than 10% free, only files that already use the @@ -313,6 +320,7 @@ static int scan_bitmap (struct reiserfs_transaction_handle *th, if (nr_allocated) goto ret; } + /* we know from above that start is a reasonable number */ get_bit_address (s, *start, &bm, &off); } @@ -1050,9 +1058,10 @@ int reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t *hint, { int initial_amount_needed = amount_needed; int ret; + struct super_block *s = hint->th->t_super; /* Check if there is enough space, taking into account reserved space */ - if ( SB_FREE_BLOCKS(hint->th->t_super) - REISERFS_SB(hint->th->t_super)->reserved_blocks < + if ( SB_FREE_BLOCKS(s) - REISERFS_SB(s)->reserved_blocks < amount_needed - reserved_by_us) return NO_DISK_SPACE; /* should this be if !hint->inode && hint->preallocate? */ @@ -1072,6 +1081,8 @@ int reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t *hint, /* find search start and save it in hint structure */ determine_search_start(hint, amount_needed); + if (hint->search_start >= SB_BLOCK_COUNT(s)) + hint->search_start = SB_BLOCK_COUNT(s) - 1; /* allocation itself; fill new_blocknrs and preallocation arrays */ ret = blocknrs_and_prealloc_arrays_from_search_start -- 2.53.0