lkml.org 
[lkml]   [1999]   [Feb]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subjectbug in make_request() when accessing last sector
Hi Linus,

I've stumbled upon an error in the make_request() function in
drivers/block/ll_rw_blk.c.
To my knowledge it applies to all versions of Linux, up to and including
2.2.x. It is the
comparison that tests whether a given block is past the end of the
device.

-------- original code ---------
if (blk_size[major][MINOR(bh->b_rdev)] < (sector + count)>>1) {
--------------------------------

this comparison is not correct as it fails to recognize the last block
as a valid block within the device.

For example consider:

device length = 2797060 bytes.
blk_size[][] would be 2797060/1024 = 2731

the last valid sector is 2797060/512 = 5463

but the above comparison erroneously fails to recognize this (2731 <
(5463+1)>>1).

the line should read:

----------- proposed code -----------
if (((blk_size[major][MINOR(bh->b_rdev)]<<1)+count) < sector) {
-------------------------------------

which should fix the problem.

The error would only show up when requesting the last sector, which
explains why we have not seen it in action before. I've been working
with a custom filesystem mounted on a loop device, so I have seen it a
lot :)

I enclose a patch for 2.0.36, but as I believe it affects all versions
of Linux, someone will have to make patches for the other kernel
versions also.

--- linux-2.0.36/drivers/block/ll_rw_blk.c.orig Fri Feb 26 13:13:12 1999

+++ linux-2.0.36/drivers/block/ll_rw_blk.c Fri Feb 26 13:08:28 1999

@@ -324,7 +324,7 @@
lock_buffer(bh);

if (blk_size[major])
- if (blk_size[major][MINOR(bh->b_rdev)] < (sector +
count)>>1) {
+ if (((blk_size[major][MINOR(bh->b_rdev)]<<1)+count) <
sector) {
bh->b_state &= (1 << BH_Lock) | (1 <<
BH_FreeOnIO);
/* This may well happen - the kernel calls
bread()
without checking the size of the device,
e.g.,

I'm new to releasing kernel patches so be gentle :)


- Rune


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:50    [W:0.024 / U:0.252 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site