From: Phillip Lougher Subject: [PATCH 5/7] Squashfs: fix block size use in LZO decompressor Date: Fri, 06 Aug 2010 01:30:08 +0100 Message-ID: <4C5B5790.7050506@lougher.demon.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit To: linux-fsdevel@vger.kernel.org Return-path: Received: from lon1-post-3.mail.demon.net ([195.173.77.150]:47352 "EHLO lon1-post-3.mail.demon.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754603Ab0HFBAj (ORCPT ); Thu, 5 Aug 2010 21:00:39 -0400 Received: from lougher.demon.co.uk ([80.177.127.218] helo=[10.0.1.3]) by lon1-post-3.mail.demon.net with esmtp (Exim 4.69) id 1OhAqd-0006Ha-ci for linux-fsdevel@vger.kernel.org; Fri, 06 Aug 2010 00:31:43 +0000 Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Sizing the buffer using block size alone is incorrect leading to a potential buffer over-run on 4K block size file systems (because the metadata block size is always 8K). Srclength is set to the maximum expected size of the decompressed block and it is block_size or 8K depending on whether a data or metadata block is being decompressed. Signed-off-by: Phillip Lougher --- fs/squashfs/lzo_wrapper.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/squashfs/lzo_wrapper.c b/fs/squashfs/lzo_wrapper.c index e1f86de..5d87789 100644 --- a/fs/squashfs/lzo_wrapper.c +++ b/fs/squashfs/lzo_wrapper.c @@ -40,13 +40,15 @@ struct squashfs_lzo { static void *lzo_init(struct squashfs_sb_info *msblk) { + int block_size = max_t(int, msblk->block_size, SQUASHFS_METADATA_SIZE); + struct squashfs_lzo *stream = kzalloc(sizeof(*stream), GFP_KERNEL); if (stream == NULL) goto failed; - stream->input = vmalloc(msblk->block_size); + stream->input = vmalloc(block_size); if (stream->input == NULL) goto failed; - stream->output = vmalloc(msblk->block_size); + stream->output = vmalloc(block_size); if (stream->output == NULL) goto failed2; @@ -80,7 +82,7 @@ static int lzo_uncompress(struct squashfs_sb_info *msblk, void **buffer, struct squashfs_lzo *stream = msblk->stream; void *buff = stream->input; int avail, i, bytes = length, res; - size_t out_len = msblk->block_size; + size_t out_len = srclength; mutex_lock(&msblk->read_data_mutex); -- 1.6.3.3