Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=f49d5e62d9352d33b30c9befbaf0fd9c88265ec1
Commit:     f49d5e62d9352d33b30c9befbaf0fd9c88265ec1
Parent:     1031be7a5fafd3a858dfaabb74d98f9ca20744a8
Author:     NeilBrown <[EMAIL PROTECTED]>
AuthorDate: Fri Jan 26 00:57:03 2007 -0800
Committer:  Linus Torvalds <[EMAIL PROTECTED]>
CommitDate: Fri Jan 26 13:50:59 2007 -0800

    [PATCH] md: avoid reading past the end of a bitmap file
    
    In most cases we check the size of the bitmap file before reading data from
    it.  However when reading the superblock, we always read the first PAGE_SIZE
    bytes, which might not always be appropriate.  So limit that read to the 
size
    of the file if appropriate.
    
    Also, we get the count of available bytes wrong in one place, so that too 
can
    read past the end of the file.
    
    Cc: "yang yin" <[EMAIL PROTECTED]>
    Signed-off-by: Neil Brown <[EMAIL PROTECTED]>
    Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
    Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>
---
 drivers/md/bitmap.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 5432d07..1110816 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -479,9 +479,12 @@ static int bitmap_read_sb(struct bitmap *bitmap)
        int err = -EINVAL;
 
        /* page 0 is the superblock, read it... */
-       if (bitmap->file)
-               bitmap->sb_page = read_page(bitmap->file, 0, bitmap, PAGE_SIZE);
-       else {
+       if (bitmap->file) {
+               loff_t isize = i_size_read(bitmap->file->f_mapping->host);
+               int bytes = isize > PAGE_SIZE ? PAGE_SIZE : isize;
+
+               bitmap->sb_page = read_page(bitmap->file, 0, bitmap, bytes);
+       } else {
                bitmap->sb_page = read_sb_page(bitmap->mddev, bitmap->offset, 
0);
        }
        if (IS_ERR(bitmap->sb_page)) {
@@ -877,7 +880,8 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, 
sector_t start)
                        int count;
                        /* unmap the old page, we're done with it */
                        if (index == num_pages-1)
-                               count = bytes - index * PAGE_SIZE;
+                               count = bytes + sizeof(bitmap_super_t)
+                                       - index * PAGE_SIZE;
                        else
                                count = PAGE_SIZE;
                        if (index == 0) {
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to