[PATCH] Check input buffer size in zisofs
authorLinus Torvalds <torvalds@osdl.org>
Sat, 6 Aug 2005 18:33:11 +0000 (11:33 -0700)
committerChris Wright <chrisw@osdl.org>
Mon, 15 Aug 2005 00:20:09 +0000 (17:20 -0700)
Add fakey 'deflateBound()' function to the in-kernel zlib routines

It's not the real deflateBound() in newer zlib libraries, partly because
the upcoming usage of it won't have the "stream" available, so we can't
have the same interfaces anyway.

This uses the new deflateBound() thing to sanity-check the input to the
zlib decompressor before we even bother to start reading in the blocks.

Problem noted by Tim Yamin <plasmaroo@gentoo.org>

Signed-off-by: Chris Wright <chrisw@osdl.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
fs/isofs/compress.c
include/linux/zlib.h

index 34a44e451689afd59aa30449b56f938bd0109f60..4917315db732e881cecbd50e89573333205d9959 100644 (file)
@@ -129,8 +129,14 @@ static int zisofs_readpage(struct file *file, struct page *page)
        cend = le32_to_cpu(*(__le32 *)(bh->b_data + (blockendptr & bufmask)));
        brelse(bh);
 
+       if (cstart > cend)
+               goto eio;
+               
        csize = cend-cstart;
 
+       if (csize > deflateBound(1UL << zisofs_block_shift))
+               goto eio;
+
        /* Now page[] contains an array of pages, any of which can be NULL,
           and the locks on which we hold.  We should now read the data and
           release the pages.  If the pages are NULL the decompressed data
index 850076ea14d318d43418a98d47876ec9ddee36c0..74f7b78c22d2fb46136999370edd154290a2f745 100644 (file)
@@ -506,6 +506,11 @@ extern int zlib_deflateReset (z_streamp strm);
    stream state was inconsistent (such as zalloc or state being NULL).
 */
 
+static inline unsigned long deflateBound(unsigned long s)
+{
+       return s + ((s + 7) >> 3) + ((s + 63) >> 6) + 11;
+}
+
 extern int zlib_deflateParams (z_streamp strm, int level, int strategy);
 /*
      Dynamically update the compression level and compression strategy.  The