lkml.org 
[lkml]   [2014]   [Sep]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] Fix nasty 32-bit overflow bug in buffer i/o code.
From
Date
Hi Linus,

On 22 Sep 2014, at 16:33, Linus Torvalds <torvalds@linux-foundation.org> wrote:
> On Mon, Sep 22, 2014 at 8:29 AM, Anton Altaparmakov <aia21@cam.ac.uk> wrote:
>>
>> You could do "block & ~(sector_t)(size - 1)" instead of "(sector_t)index << sizebits" if you prefer but not sure that is an improvement!
>
> No, it would be even worse. Something like
>
> block & ~(sector_t)((size >> 9) - 1)
>
> because block is the sector number (ie 512-byte) and size is in bytes.

Oops, sorry. But I think you got it wrong, too as you are ignoring the PAGE_SIZE - as was I but it is what we need to align to in addition to the problem of "size" being in bytes. So I think the correct mask is actually based on sizebits which reflects the number of blocks per page thus:

block & ~(sector_t)((1 << sizebits) - 1)

In any case the shift is the lesser evil I think as it is at least obviously correct whilst getting the right mask has taken us a few iterations of correcting each other! (-:

PS. Thank you for taking my patch and correcting the misleading description!

Best regards,

Anton

> Linus

--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
University of Cambridge Information Services, Roger Needham Building
7 JJ Thomson Avenue, Cambridge, CB3 0RB, UK



\
 
 \ /
  Last update: 2014-09-22 18:21    [W:0.038 / U:0.132 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site