Thread (10 messages) 10 messages, 3 authors, 2014-09-22

Re: [PATCH] Fix nasty 32-bit overflow bug in buffer i/o code.

From: Anton Altaparmakov <hidden>
Date: 2014-09-22 15:46:01
Also in: linux-fsdevel, lkml

Hi Linus,

On 22 Sep 2014, at 16:33, Linus Torvalds [off-list ref] wrote:
On Mon, Sep 22, 2014 at 8:29 AM, Anton Altaparmakov [off-list ref] wrote:
quoted
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help