Anton Altaparmakov f2d5a94436 Fix nasty 32-bit overflow bug in buffer i/o code.
On 32-bit architectures, the legacy buffer_head functions are not always
handling the sector number with the proper 64-bit types, and will thus
fail on 4TB+ disks.

Any code that uses __getblk() (and thus bread(), breadahead(),
sb_bread(), sb_breadahead(), sb_getblk()), and calls it using a 64-bit
block on a 32-bit arch (where "long" is 32-bit) causes an inifinite loop
in __getblk_slow() with an infinite stream of errors logged to dmesg
like this:

  __find_get_block_slow() failed. block=6740375944, b_blocknr=2445408648
  b_state=0x00000020, b_size=512
  device sda1 blocksize: 512

Note how in hex block is 0x191C1F988 and b_blocknr is 0x91C1F988 i.e. the
top 32-bits are missing (in this case the 0x1 at the top).

This is because grow_dev_page() is broken and has a 32-bit overflow due
to shifting the page index value (a pgoff_t - which is just 32 bits on
32-bit architectures) left-shifted as the block number.  But the top
bits to get lost as the pgoff_t is not type cast to sector_t / 64-bit
before the shift.

This patch fixes this issue by type casting "index" to sector_t before
doing the left shift.

Note this is not a theoretical bug but has been seen in the field on a
4TiB hard drive with logical sector size 512 bytes.

This patch has been verified to fix the infinite loop problem on 3.17-rc5
kernel using a 4TB disk image mounted using "-o loop".  Without this patch
doing a "find /nt" where /nt is an NTFS volume causes the inifinite loop
100% reproducibly whilst with the patch it works fine as expected.

Signed-off-by: Anton Altaparmakov <aia21@cantab.net>
Cc: stable@vger.kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-09-22 08:41:16 -07:00
..
2014-08-08 15:57:24 -07:00
2014-09-16 06:48:20 -05:00
2014-08-08 15:57:20 -07:00
2014-06-04 16:53:53 -07:00
2014-08-06 18:01:12 -07:00
2014-09-12 20:58:55 +01:00
2014-08-07 14:40:09 -04:00
2014-08-08 18:13:21 -07:00
2014-09-08 12:02:03 -04:00
2014-01-25 03:14:05 -05:00
2014-08-06 18:01:12 -07:00
2014-07-15 22:40:23 +02:00
2014-07-31 15:52:51 +03:00
2014-08-07 14:40:09 -04:00
2013-10-24 23:34:54 -04:00
2014-08-08 15:57:23 -07:00
2014-08-08 15:57:31 -07:00
2014-05-06 17:31:10 -04:00
2013-10-24 23:34:54 -04:00
2014-02-07 16:08:57 -08:00
2014-08-07 14:40:08 -04:00
2014-08-07 14:40:09 -04:00
2014-05-06 17:39:42 -04:00
2014-04-01 23:19:08 -04:00
2013-11-09 00:16:31 -05:00
2014-07-23 10:18:02 -07:00