* [PATCH] fs/buffer.c: grow_buffers: fix the uncorrect check
@ 2014-05-31 18:12 mnipxh
2014-05-31 19:39 ` Linus Torvalds
0 siblings, 1 reply; 2+ messages in thread
From: mnipxh @ 2014-05-31 18:12 UTC (permalink / raw)
To: linux-kernel, linux-fsdevel, viro; +Cc: torvalds, akpm, yanmin_zhang, shuox.liu
When pgoff_t index is 32bit, sector_t block is 64bit, need check if block number is too big.
If block is bigger than (4Gb * PAGE_SIZE), index becomes a wrong value.
Commit e5657933863f43cc6bb76a54d659303dafaa9e58 wants to do this. But it gives an uncorrect check.
I think block != index << sizebits is correct. And it can detect such issue above.
Signed-off-by: xinhui.pan <xinhuix.pan@intel.com>
---
fs/buffer.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/buffer.c b/fs/buffer.c
index 9ddb9fc..1a674a6 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -1081,7 +1081,7 @@ grow_buffers(struct block_device *bdev, sector_t block, int size)
* Check for a block which wants to lie outside our maximum possible
* pagecache index. (this comparison is done using sector_t types).
*/
- if (unlikely(index != block >> sizebits)) {
+ if (unlikely(block != index << sizebits)) {
char b[BDEVNAME_SIZE];
printk(KERN_ERR "%s: requested out-of-range block %llu for "
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] fs/buffer.c: grow_buffers: fix the uncorrect check
2014-05-31 18:12 [PATCH] fs/buffer.c: grow_buffers: fix the uncorrect check mnipxh
@ 2014-05-31 19:39 ` Linus Torvalds
0 siblings, 0 replies; 2+ messages in thread
From: Linus Torvalds @ 2014-05-31 19:39 UTC (permalink / raw)
To: mnipxh
Cc: Linux Kernel Mailing List, linux-fsdevel, Al Viro, Andrew Morton,
Yanmin Zhang, shuox.liu
On Sat, May 31, 2014 at 11:12 AM, mnipxh <mnipxh@gmail.com> wrote:
> When pgoff_t index is 32bit, sector_t block is 64bit, need check if block number is too big.
> If block is bigger than (4Gb * PAGE_SIZE), index becomes a wrong value.
> Commit e5657933863f43cc6bb76a54d659303dafaa9e58 wants to do this. But it gives an uncorrect check.
> I think block != index << sizebits is correct. And it can detect such issue above.
I don't understand why you think the current check is incorrect.
It is testing that the calculation hasn't overflowed. It is correct.
It *should* use the same calculation, to (a) make it more obvious that
it's double-checking the earlier calculation in a different type, and
(b) to make it easier for the compiler to optimize it away if sector_t
and pgoff_t are the same size.
So the current code is correct, afaik. Note that "index" is "pgoff_t",
but "block >> sizebits" is "sector_t".
Linus
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-05-31 19:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-31 18:12 [PATCH] fs/buffer.c: grow_buffers: fix the uncorrect check mnipxh
2014-05-31 19:39 ` Linus Torvalds
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).