Skip to content

Commit

Permalink
libfs: Fix shift bug in generic_check_addressable()
Browse files Browse the repository at this point in the history
generic_check_addressable() erroneously shifts pages down by a block
factor when it should be shifting up.  To prevent overflow, we shift
blocks down to pages.

Signed-off-by: Joel Becker <joel.becker@oracle.com>
  • Loading branch information
Joel Becker committed Sep 10, 2010
1 parent 3bdb8ef commit a33f13e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions fs/libfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -925,17 +925,17 @@ EXPORT_SYMBOL(generic_file_fsync);
int generic_check_addressable(unsigned blocksize_bits, u64 num_blocks)
{
u64 last_fs_block = num_blocks - 1;
u64 last_fs_page =
last_fs_block >> (PAGE_CACHE_SHIFT - blocksize_bits);

if (unlikely(num_blocks == 0))
return 0;

if ((blocksize_bits < 9) || (blocksize_bits > PAGE_CACHE_SHIFT))
return -EINVAL;

if ((last_fs_block >
(sector_t)(~0ULL) >> (blocksize_bits - 9)) ||
(last_fs_block >
(pgoff_t)(~0ULL) >> (PAGE_CACHE_SHIFT - blocksize_bits))) {
if ((last_fs_block > (sector_t)(~0ULL) >> (blocksize_bits - 9)) ||
(last_fs_page > (pgoff_t)(~0ULL))) {
return -EFBIG;
}
return 0;
Expand Down

0 comments on commit a33f13e

Please sign in to comment.