提交 e7dfb246 编写于 作者: A Aneesh Kumar K.V 提交者: Theodore Ts'o

ext4: Fix mb_find_next_bit not to return larger than max

Some architectures implement ext4_find_next_bit and
ext4_find_next_zero_bit in such a way that they return
greater than max for some input values. Make sure
mb_find_next_bit and mb_find_next_zero_bit return the
right values.

On 2.6.25 we have include/asm-x86/bitops_32.h
static inline unsigned find_first_bit(const unsigned long *addr, unsigned size)
{
	unsigned x = 0;

	while (x < size) {
		unsigned long val = *addr++;
		if (val)
			return __ffs(val) + x;
		x += (sizeof(*addr)<<3);
	}
	return x;
}

This can return value greater than size.

Reported and fixed here for lustre

https://bugzilla.lustre.org/show_bug.cgi?id=15932
https://bugzilla.lustre.org/attachment.cgi?id=17205Signed-off-by: NAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: NMingming Cao <cmm@us.ibm.com>
Signed-off-by: N"Theodore Ts'o" <tytso@mit.edu>
上级 f3b35f06
...@@ -381,22 +381,28 @@ static inline void mb_clear_bit_atomic(spinlock_t *lock, int bit, void *addr) ...@@ -381,22 +381,28 @@ static inline void mb_clear_bit_atomic(spinlock_t *lock, int bit, void *addr)
static inline int mb_find_next_zero_bit(void *addr, int max, int start) static inline int mb_find_next_zero_bit(void *addr, int max, int start)
{ {
int fix = 0; int fix = 0, ret, tmpmax;
addr = mb_correct_addr_and_bit(&fix, addr); addr = mb_correct_addr_and_bit(&fix, addr);
max += fix; tmpmax = max + fix;
start += fix; start += fix;
return ext4_find_next_zero_bit(addr, max, start) - fix; ret = ext4_find_next_zero_bit(addr, tmpmax, start) - fix;
if (ret > max)
return max;
return ret;
} }
static inline int mb_find_next_bit(void *addr, int max, int start) static inline int mb_find_next_bit(void *addr, int max, int start)
{ {
int fix = 0; int fix = 0, ret, tmpmax;
addr = mb_correct_addr_and_bit(&fix, addr); addr = mb_correct_addr_and_bit(&fix, addr);
max += fix; tmpmax = max + fix;
start += fix; start += fix;
return ext4_find_next_bit(addr, max, start) - fix; ret = ext4_find_next_bit(addr, tmpmax, start) - fix;
if (ret > max)
return max;
return ret;
} }
static void *mb_find_buddy(struct ext4_buddy *e4b, int order, int *max) static void *mb_find_buddy(struct ext4_buddy *e4b, int order, int *max)
...@@ -3473,8 +3479,6 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh, ...@@ -3473,8 +3479,6 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
if (bit >= end) if (bit >= end)
break; break;
next = mb_find_next_bit(bitmap_bh->b_data, end, bit); next = mb_find_next_bit(bitmap_bh->b_data, end, bit);
if (next > end)
next = end;
start = group * EXT4_BLOCKS_PER_GROUP(sb) + bit + start = group * EXT4_BLOCKS_PER_GROUP(sb) + bit +
le32_to_cpu(sbi->s_es->s_first_data_block); le32_to_cpu(sbi->s_es->s_first_data_block);
mb_debug(" free preallocated %u/%u in group %u\n", mb_debug(" free preallocated %u/%u in group %u\n",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册