Re: [PATCH] scsi disk: report size without overflow

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2005-10-20 at 20:55 -0700, Randy.Dunlap wrote:
> With CONFIG_LBD=n, 'sz' (32 bits) can overflow when capacity is
> multiplied (even * 2), as seen in a report from Dale Blount
> on lkml.  Also make sure that 'mb' will not overflow.
> 
> Signed-off-by: Randy Dunlap <rdunlap@xxxxxxxxxxxx>

Mathematically, it doesn't look like we need to use 64 bits at all;
what's wrong with the attached?  It looks like the code once allowed 256
byte sectors, but the if statement above now forbids them.

I'm really not terribly sympathetic to anyone trying Terrabyte discs on
a non-LBD 32 bit kernel.  The potential for overflow (and consequent
data loss) is pretty huge. 

James

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1253,14 +1253,13 @@ got_data:
 		 * Jacques Gelinas (Jacques@xxxxxxxxxxxxxx)
 		 */
 		int hard_sector = sector_size;
-		sector_t sz = sdkp->capacity * (hard_sector/256);
+		sector_t sz = sdkp->capacity * (hard_sector/512);
 		request_queue_t *queue = sdp->request_queue;
-		sector_t mb;
+		sector_t mb = sz;
 
 		blk_queue_hardsect_size(queue, hard_sector);
 		/* avoid 64-bit division on 32-bit platforms */
-		mb = sz >> 1;
-		sector_div(sz, 1250);
+		sector_div(sz, 625);
 		mb -= sz - 974;
 		sector_div(mb, 1950);
 


-
: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]
  Powered by Linux