mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andreas Dilger <adilger@clusterfs.com>
To: Anton Altaparmakov <aia21@cam.ac.uk>
Cc: Linus Torvalds <torvalds@osdl.org>,
	"Stephen C. Tweedie" <sct@redhat.com>,
	"ext2-devel@lists.sourceforge.net"
	<ext2-devel@lists.sourceforge.net>, Andrew Morton <akpm@osdl.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] sector_t overflow in block layer
Date: Thu, 18 May 2006 16:43:06 -0600	[thread overview]
Message-ID: <20060518224306.GT5964@schatzie.adilger.int> (raw)
In-Reply-To: <Pine.LNX.4.64.0605182307540.16178@hermes-1.csi.cam.ac.uk>

On May 18, 2006  23:12 +0100, Anton Altaparmakov wrote:
> On Thu, 18 May 2006, Linus Torvalds wrote:
> > On Thu, 18 May 2006, Andreas Dilger wrote:
> > > +	/* Check if we overflow sector_t when computing the sector offset.  */
> > > +	sector = (unsigned long long)bh->b_blocknr * (bh->b_size >> 9);
> > 
> > Ok so far, looks fine.
> > 
> > But what the heck is this:
> > 
> > > +#if !defined(CONFIG_LBD) && BITS_PER_LONG == 32
> > > +	if (unlikely(sector != (sector_t)sector))
> > > +#else
> > > +	if (unlikely(((bh->b_blocknr >> 32) * (bh->b_size >> 9)) >=
> > > +		     0xffffffff00000000ULL))
> > > +#endif
> > 
> > I don't understand the #ifdef at all.
> > 
> > Why isn't that just a 
> > 
> > 	if (unlikely(sector != (sector_t)sector))
> >
> > and that's it? What does this have to do with CONFIG_LBD or BITS_PER_LONG, 
> > or anything at all?
> > 
> > If the sector number fits in a sector_t, we're all good.
> 
> I think you missed that Andreas said he is worried about 64-bit overflows 
> as well.  And you would not catch those with the sector != 
> (sector_t)sector test because you would be comparing two 64-bit values 
> together so they always match...
> 
> Hence why he shifts the value right by 32 bits then multiplies and tests 
> the result for overflowing 32-bits which if it does it means it would 
> overflow the 64-bit multiplication, too therefor your "sector" is 
> truncated.

Yes, this is exactly correct.  At various times while writing this I had 
more comments to explain everything, but then removed them as too wordy.
The actual implementation isn't what I care about - the resulting corruption
is more important and I thought it better to at least get some attention
on it instead of worrying over the details.

Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.


  parent reply	other threads:[~2006-05-18 22:43 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1147849273.16827.27.camel@localhost.localdomain>
     [not found] ` <m3odxxukcp.fsf@bzzz.home.net>
     [not found]   ` <1147884610.16827.44.camel@localhost.localdomain>
     [not found]     ` <m34pzo36d4.fsf@bzzz.home.net>
     [not found]       ` <1147888715.12067.38.camel@dyn9047017100.beaverton.ibm.com>
     [not found]         ` <m364k4zfor.fsf@bzzz.home.net>
     [not found]           ` <20060517235804.GA5731@schatzie.adilger.int>
     [not found]             ` <1147947803.5464.19.camel@sisko.sctweedie.blueyonder.co.uk>
2006-05-18 18:59               ` Andreas Dilger
2006-05-18 20:58                 ` Alexey Dobriyan
2006-05-18 21:06                 ` Linus Torvalds
2006-05-18 22:12                   ` Anton Altaparmakov
2006-05-18 22:41                     ` Linus Torvalds
2006-05-18 23:23                       ` Andreas Dilger
2006-05-19 19:36                         ` Stephen C. Tweedie
2006-05-19 20:11                           ` Andrew Morton
2006-05-19 20:55                             ` Andreas Dilger
2006-05-19 21:15                               ` Andrew Morton
2006-05-19 21:05                             ` Stephen C. Tweedie
2006-05-18 22:43                     ` Andreas Dilger [this message]
2006-05-22  0:14                     ` Pavel Machek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060518224306.GT5964@schatzie.adilger.int \
    --to=adilger@clusterfs.com \
    --cc=aia21@cam.ac.uk \
    --cc=akpm@osdl.org \
    --cc=ext2-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sct@redhat.com \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®