[JFFS2] fix race condition in jffs2_lzo_compress()

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Wed Nov 5 17:59:01 EST 2008


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=dc8a0843a435b2c0891e7eaea64faaf1ebec9b11
Commit:     dc8a0843a435b2c0891e7eaea64faaf1ebec9b11
Parent:     467622ef2acb01986eab37ef96c3632b3ea35999
Author:     Geert Uytterhoeven <Geert.Uytterhoeven at sonycom.com>
AuthorDate: Wed Nov 5 23:21:16 2008 +0100
Committer:  David Woodhouse <David.Woodhouse at intel.com>
CommitDate: Wed Nov 5 23:22:02 2008 +0100

    [JFFS2] fix race condition in jffs2_lzo_compress()
    
    deflate_mutex protects the globals lzo_mem and lzo_compress_buf.  However,
    jffs2_lzo_compress() unlocks deflate_mutex _before_ it has copied out the
    compressed data from lzo_compress_buf.  Correct this by moving the mutex
    unlock after the copy.
    
    In addition, document what deflate_mutex actually protects.
    
    Cc: stable at kernel.org
    Signed-off-by: Geert Uytterhoeven <Geert.Uytterhoeven at sonycom.com>
    Acked-by: Richard Purdie <rpurdie at openedhand.com>
    Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
    Signed-off-by: David Woodhouse <David.Woodhouse at intel.com>
---
 fs/jffs2/compr_lzo.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/fs/jffs2/compr_lzo.c b/fs/jffs2/compr_lzo.c
index 47b0457..90cb60d 100644
--- a/fs/jffs2/compr_lzo.c
+++ b/fs/jffs2/compr_lzo.c
@@ -19,7 +19,7 @@
 
 static void *lzo_mem;
 static void *lzo_compress_buf;
-static DEFINE_MUTEX(deflate_mutex);
+static DEFINE_MUTEX(deflate_mutex);	/* for lzo_mem and lzo_compress_buf */
 
 static void free_workspace(void)
 {
@@ -49,18 +49,21 @@ static int jffs2_lzo_compress(unsigned char *data_in, unsigned char *cpage_out,
 
 	mutex_lock(&deflate_mutex);
 	ret = lzo1x_1_compress(data_in, *sourcelen, lzo_compress_buf, &compress_size, lzo_mem);
-	mutex_unlock(&deflate_mutex);
-
 	if (ret != LZO_E_OK)
-		return -1;
+		goto fail;
 
 	if (compress_size > *dstlen)
-		return -1;
+		goto fail;
 
 	memcpy(cpage_out, lzo_compress_buf, compress_size);
-	*dstlen = compress_size;
+	mutex_unlock(&deflate_mutex);
 
+	*dstlen = compress_size;
 	return 0;
+
+ fail:
+	mutex_unlock(&deflate_mutex);
+	return -1;
 }
 
 static int jffs2_lzo_decompress(unsigned char *data_in, unsigned char *cpage_out,



More information about the linux-mtd-cvs mailing list