From f1fb769c046b1e665b437ad6da5a38cd51986dcc Mon Sep 17 00:00:00 2001 From: adilger Date: Mon, 6 Feb 2006 20:57:28 +0000 Subject: [PATCH] Branch b_release_1_4_6 Fix unlikely bugs in mballoc found by Coverity: - NULL bh dereferenced in ext3_mb_init_cache() if kmalloc(bh) fails - don't free on-stack bhs in ext3_mb_init_cache() if groups_per_page == 1 - remove unnecessary "if (err)" check in ext3_mb_new_blocks() - remove redundant "if (s == NULL)" check in ext3_mb_seq_history_open() b=10093 --- .../patches/ext3-mballoc2-2.6-suse.patch | 19 +++++++------------ .../kernel_patches/patches/ext3-mballoc2-2.6.12.patch | 19 +++++++------------ .../patches/ext3-mballoc2-2.6.9-rhel4.patch | 19 +++++++------------ .../patches/ext3-mballoc2-2.6-suse.patch | 19 +++++++------------ .../kernel_patches/patches/ext3-mballoc2-2.6.12.patch | 19 +++++++------------ .../patches/ext3-mballoc2-2.6.9-rhel4.patch | 19 +++++++------------ 6 files changed, 42 insertions(+), 72 deletions(-) diff --git a/ldiskfs/kernel_patches/patches/ext3-mballoc2-2.6-suse.patch b/ldiskfs/kernel_patches/patches/ext3-mballoc2-2.6-suse.patch index 3a1ada2..bb9928a 100644 --- a/ldiskfs/kernel_patches/patches/ext3-mballoc2-2.6-suse.patch +++ b/ldiskfs/kernel_patches/patches/ext3-mballoc2-2.6-suse.patch @@ -334,7 +334,7 @@ Index: linux-2.6.5-7.201/fs/ext3/mballoc.c =================================================================== --- linux-2.6.5-7.201.orig/fs/ext3/mballoc.c 2005-12-09 13:08:53.191437750 +0300 +++ linux-2.6.5-7.201/fs/ext3/mballoc.c 2005-12-17 03:15:04.000000000 +0300 -@@ -0,0 +1,2435 @@ +@@ -0,0 +1,2430 @@ +/* + * Copyright (c) 2003-2005, Cluster File Systems, Inc, info@clusterfs.com + * Written by Alex Tomas @@ -899,10 +899,12 @@ Index: linux-2.6.5-7.201/fs/ext3/mballoc.c + SetPageUptodate(page); + +out: -+ for (i = 0; i < groups_per_page && bh[i]; i++) -+ brelse(bh[i]); -+ if (bh && bh != &bhs) -+ kfree(bh); ++ if (bh) { ++ for (i = 0; bh && i < groups_per_page && bh[i]; i++) ++ brelse(bh[i]); ++ if (bh != &bhs) ++ kfree(bh); ++ } + return err; +} + @@ -1664,8 +1666,6 @@ Index: linux-2.6.5-7.201/fs/ext3/mballoc.c + + ext3_mb_release_desc(&e3b); + -+ if (err) -+ goto out_err; + if (ac.ac_status != AC_STATUS_CONTINUE) + break; + } @@ -1944,10 +1944,6 @@ Index: linux-2.6.5-7.201/fs/ext3/mballoc.c + return -EIO; + size = sizeof(struct ext3_mb_history) * sbi->s_mb_history_max; + s->history = kmalloc(size, GFP_KERNEL); -+ if (s == NULL) { -+ kfree(s); -+ return -EIO; -+ } + + spin_lock(&sbi->s_mb_history_lock); + memcpy(s->history, sbi->s_mb_history, size); @@ -2769,7 +2765,6 @@ Index: linux-2.6.5-7.201/fs/ext3/mballoc.c + remove_proc_entry(EXT3_MB_MIN_TO_SCAN_NAME, proc_root_ext3); + remove_proc_entry(EXT3_ROOT, proc_root_fs); +} -+ Index: linux-2.6.5-7.201/fs/ext3/Makefile =================================================================== --- linux-2.6.5-7.201.orig/fs/ext3/Makefile 2005-12-17 02:53:30.000000000 +0300 diff --git a/ldiskfs/kernel_patches/patches/ext3-mballoc2-2.6.12.patch b/ldiskfs/kernel_patches/patches/ext3-mballoc2-2.6.12.patch index 12924a5..a2b9caf 100644 --- a/ldiskfs/kernel_patches/patches/ext3-mballoc2-2.6.12.patch +++ b/ldiskfs/kernel_patches/patches/ext3-mballoc2-2.6.12.patch @@ -329,7 +329,7 @@ Index: linux-2.6.12.6/fs/ext3/mballoc.c =================================================================== --- linux-2.6.12.6.orig/fs/ext3/mballoc.c 2005-12-09 13:08:53.191437750 +0300 +++ linux-2.6.12.6/fs/ext3/mballoc.c 2005-12-17 02:21:21.000000000 +0300 -@@ -0,0 +1,2434 @@ +@@ -0,0 +1,2429 @@ +/* + * Copyright (c) 2003-2005, Cluster File Systems, Inc, info@clusterfs.com + * Written by Alex Tomas @@ -894,10 +894,12 @@ Index: linux-2.6.12.6/fs/ext3/mballoc.c + SetPageUptodate(page); + +out: -+ for (i = 0; i < groups_per_page && bh[i]; i++) -+ brelse(bh[i]); -+ if (bh && bh != &bhs) -+ kfree(bh); ++ if (bh) { ++ for (i = 0; bh && i < groups_per_page && bh[i]; i++) ++ brelse(bh[i]); ++ if (bh != &bhs) ++ kfree(bh); ++ } + return err; +} + @@ -1659,8 +1661,6 @@ Index: linux-2.6.12.6/fs/ext3/mballoc.c + + ext3_mb_release_desc(&e3b); + -+ if (err) -+ goto out_err; + if (ac.ac_status != AC_STATUS_CONTINUE) + break; + } @@ -1939,10 +1939,6 @@ Index: linux-2.6.12.6/fs/ext3/mballoc.c + return -EIO; + size = sizeof(struct ext3_mb_history) * sbi->s_mb_history_max; + s->history = kmalloc(size, GFP_KERNEL); -+ if (s == NULL) { -+ kfree(s); -+ return -EIO; -+ } + + spin_lock(&sbi->s_mb_history_lock); + memcpy(s->history, sbi->s_mb_history, size); @@ -2763,7 +2759,6 @@ Index: linux-2.6.12.6/fs/ext3/mballoc.c + remove_proc_entry(EXT3_MB_MIN_TO_SCAN_NAME, proc_root_ext3); + remove_proc_entry(EXT3_ROOT, proc_root_fs); +} -+ Index: linux-2.6.12.6/fs/ext3/Makefile =================================================================== --- linux-2.6.12.6.orig/fs/ext3/Makefile 2005-12-17 02:17:16.000000000 +0300 diff --git a/ldiskfs/kernel_patches/patches/ext3-mballoc2-2.6.9-rhel4.patch b/ldiskfs/kernel_patches/patches/ext3-mballoc2-2.6.9-rhel4.patch index 980f71a..d12c678 100644 --- a/ldiskfs/kernel_patches/patches/ext3-mballoc2-2.6.9-rhel4.patch +++ b/ldiskfs/kernel_patches/patches/ext3-mballoc2-2.6.9-rhel4.patch @@ -348,7 +348,7 @@ Index: linux-2.6.9-full/fs/ext3/mballoc.c =================================================================== --- linux-2.6.9-full.orig/fs/ext3/mballoc.c 2005-12-16 17:46:19.148560250 +0300 +++ linux-2.6.9-full/fs/ext3/mballoc.c 2005-12-17 00:10:15.000000000 +0300 -@@ -0,0 +1,2434 @@ +@@ -0,0 +1,2429 @@ +/* + * Copyright (c) 2003-2005, Cluster File Systems, Inc, info@clusterfs.com + * Written by Alex Tomas @@ -913,10 +913,12 @@ Index: linux-2.6.9-full/fs/ext3/mballoc.c + SetPageUptodate(page); + +out: -+ for (i = 0; i < groups_per_page && bh[i]; i++) -+ brelse(bh[i]); -+ if (bh && bh != &bhs) -+ kfree(bh); ++ if (bh) { ++ for (i = 0; bh && i < groups_per_page && bh[i]; i++) ++ brelse(bh[i]); ++ if (bh != &bhs) ++ kfree(bh); ++ } + return err; +} + @@ -1678,8 +1680,6 @@ Index: linux-2.6.9-full/fs/ext3/mballoc.c + + ext3_mb_release_desc(&e3b); + -+ if (err) -+ goto out_err; + if (ac.ac_status != AC_STATUS_CONTINUE) + break; + } @@ -1958,10 +1958,6 @@ Index: linux-2.6.9-full/fs/ext3/mballoc.c + return -EIO; + size = sizeof(struct ext3_mb_history) * sbi->s_mb_history_max; + s->history = kmalloc(size, GFP_KERNEL); -+ if (s == NULL) { -+ kfree(s); -+ return -EIO; -+ } + + spin_lock(&sbi->s_mb_history_lock); + memcpy(s->history, sbi->s_mb_history, size); @@ -2782,7 +2778,6 @@ Index: linux-2.6.9-full/fs/ext3/mballoc.c + remove_proc_entry(EXT3_MB_MIN_TO_SCAN_NAME, proc_root_ext3); + remove_proc_entry(EXT3_ROOT, proc_root_fs); +} -+ Index: linux-2.6.9-full/fs/ext3/Makefile =================================================================== --- linux-2.6.9-full.orig/fs/ext3/Makefile 2005-12-16 23:16:41.000000000 +0300 diff --git a/lustre/kernel_patches/patches/ext3-mballoc2-2.6-suse.patch b/lustre/kernel_patches/patches/ext3-mballoc2-2.6-suse.patch index 3a1ada2..bb9928a 100644 --- a/lustre/kernel_patches/patches/ext3-mballoc2-2.6-suse.patch +++ b/lustre/kernel_patches/patches/ext3-mballoc2-2.6-suse.patch @@ -334,7 +334,7 @@ Index: linux-2.6.5-7.201/fs/ext3/mballoc.c =================================================================== --- linux-2.6.5-7.201.orig/fs/ext3/mballoc.c 2005-12-09 13:08:53.191437750 +0300 +++ linux-2.6.5-7.201/fs/ext3/mballoc.c 2005-12-17 03:15:04.000000000 +0300 -@@ -0,0 +1,2435 @@ +@@ -0,0 +1,2430 @@ +/* + * Copyright (c) 2003-2005, Cluster File Systems, Inc, info@clusterfs.com + * Written by Alex Tomas @@ -899,10 +899,12 @@ Index: linux-2.6.5-7.201/fs/ext3/mballoc.c + SetPageUptodate(page); + +out: -+ for (i = 0; i < groups_per_page && bh[i]; i++) -+ brelse(bh[i]); -+ if (bh && bh != &bhs) -+ kfree(bh); ++ if (bh) { ++ for (i = 0; bh && i < groups_per_page && bh[i]; i++) ++ brelse(bh[i]); ++ if (bh != &bhs) ++ kfree(bh); ++ } + return err; +} + @@ -1664,8 +1666,6 @@ Index: linux-2.6.5-7.201/fs/ext3/mballoc.c + + ext3_mb_release_desc(&e3b); + -+ if (err) -+ goto out_err; + if (ac.ac_status != AC_STATUS_CONTINUE) + break; + } @@ -1944,10 +1944,6 @@ Index: linux-2.6.5-7.201/fs/ext3/mballoc.c + return -EIO; + size = sizeof(struct ext3_mb_history) * sbi->s_mb_history_max; + s->history = kmalloc(size, GFP_KERNEL); -+ if (s == NULL) { -+ kfree(s); -+ return -EIO; -+ } + + spin_lock(&sbi->s_mb_history_lock); + memcpy(s->history, sbi->s_mb_history, size); @@ -2769,7 +2765,6 @@ Index: linux-2.6.5-7.201/fs/ext3/mballoc.c + remove_proc_entry(EXT3_MB_MIN_TO_SCAN_NAME, proc_root_ext3); + remove_proc_entry(EXT3_ROOT, proc_root_fs); +} -+ Index: linux-2.6.5-7.201/fs/ext3/Makefile =================================================================== --- linux-2.6.5-7.201.orig/fs/ext3/Makefile 2005-12-17 02:53:30.000000000 +0300 diff --git a/lustre/kernel_patches/patches/ext3-mballoc2-2.6.12.patch b/lustre/kernel_patches/patches/ext3-mballoc2-2.6.12.patch index 12924a5..a2b9caf 100644 --- a/lustre/kernel_patches/patches/ext3-mballoc2-2.6.12.patch +++ b/lustre/kernel_patches/patches/ext3-mballoc2-2.6.12.patch @@ -329,7 +329,7 @@ Index: linux-2.6.12.6/fs/ext3/mballoc.c =================================================================== --- linux-2.6.12.6.orig/fs/ext3/mballoc.c 2005-12-09 13:08:53.191437750 +0300 +++ linux-2.6.12.6/fs/ext3/mballoc.c 2005-12-17 02:21:21.000000000 +0300 -@@ -0,0 +1,2434 @@ +@@ -0,0 +1,2429 @@ +/* + * Copyright (c) 2003-2005, Cluster File Systems, Inc, info@clusterfs.com + * Written by Alex Tomas @@ -894,10 +894,12 @@ Index: linux-2.6.12.6/fs/ext3/mballoc.c + SetPageUptodate(page); + +out: -+ for (i = 0; i < groups_per_page && bh[i]; i++) -+ brelse(bh[i]); -+ if (bh && bh != &bhs) -+ kfree(bh); ++ if (bh) { ++ for (i = 0; bh && i < groups_per_page && bh[i]; i++) ++ brelse(bh[i]); ++ if (bh != &bhs) ++ kfree(bh); ++ } + return err; +} + @@ -1659,8 +1661,6 @@ Index: linux-2.6.12.6/fs/ext3/mballoc.c + + ext3_mb_release_desc(&e3b); + -+ if (err) -+ goto out_err; + if (ac.ac_status != AC_STATUS_CONTINUE) + break; + } @@ -1939,10 +1939,6 @@ Index: linux-2.6.12.6/fs/ext3/mballoc.c + return -EIO; + size = sizeof(struct ext3_mb_history) * sbi->s_mb_history_max; + s->history = kmalloc(size, GFP_KERNEL); -+ if (s == NULL) { -+ kfree(s); -+ return -EIO; -+ } + + spin_lock(&sbi->s_mb_history_lock); + memcpy(s->history, sbi->s_mb_history, size); @@ -2763,7 +2759,6 @@ Index: linux-2.6.12.6/fs/ext3/mballoc.c + remove_proc_entry(EXT3_MB_MIN_TO_SCAN_NAME, proc_root_ext3); + remove_proc_entry(EXT3_ROOT, proc_root_fs); +} -+ Index: linux-2.6.12.6/fs/ext3/Makefile =================================================================== --- linux-2.6.12.6.orig/fs/ext3/Makefile 2005-12-17 02:17:16.000000000 +0300 diff --git a/lustre/kernel_patches/patches/ext3-mballoc2-2.6.9-rhel4.patch b/lustre/kernel_patches/patches/ext3-mballoc2-2.6.9-rhel4.patch index 980f71a..d12c678 100644 --- a/lustre/kernel_patches/patches/ext3-mballoc2-2.6.9-rhel4.patch +++ b/lustre/kernel_patches/patches/ext3-mballoc2-2.6.9-rhel4.patch @@ -348,7 +348,7 @@ Index: linux-2.6.9-full/fs/ext3/mballoc.c =================================================================== --- linux-2.6.9-full.orig/fs/ext3/mballoc.c 2005-12-16 17:46:19.148560250 +0300 +++ linux-2.6.9-full/fs/ext3/mballoc.c 2005-12-17 00:10:15.000000000 +0300 -@@ -0,0 +1,2434 @@ +@@ -0,0 +1,2429 @@ +/* + * Copyright (c) 2003-2005, Cluster File Systems, Inc, info@clusterfs.com + * Written by Alex Tomas @@ -913,10 +913,12 @@ Index: linux-2.6.9-full/fs/ext3/mballoc.c + SetPageUptodate(page); + +out: -+ for (i = 0; i < groups_per_page && bh[i]; i++) -+ brelse(bh[i]); -+ if (bh && bh != &bhs) -+ kfree(bh); ++ if (bh) { ++ for (i = 0; bh && i < groups_per_page && bh[i]; i++) ++ brelse(bh[i]); ++ if (bh != &bhs) ++ kfree(bh); ++ } + return err; +} + @@ -1678,8 +1680,6 @@ Index: linux-2.6.9-full/fs/ext3/mballoc.c + + ext3_mb_release_desc(&e3b); + -+ if (err) -+ goto out_err; + if (ac.ac_status != AC_STATUS_CONTINUE) + break; + } @@ -1958,10 +1958,6 @@ Index: linux-2.6.9-full/fs/ext3/mballoc.c + return -EIO; + size = sizeof(struct ext3_mb_history) * sbi->s_mb_history_max; + s->history = kmalloc(size, GFP_KERNEL); -+ if (s == NULL) { -+ kfree(s); -+ return -EIO; -+ } + + spin_lock(&sbi->s_mb_history_lock); + memcpy(s->history, sbi->s_mb_history, size); @@ -2782,7 +2778,6 @@ Index: linux-2.6.9-full/fs/ext3/mballoc.c + remove_proc_entry(EXT3_MB_MIN_TO_SCAN_NAME, proc_root_ext3); + remove_proc_entry(EXT3_ROOT, proc_root_fs); +} -+ Index: linux-2.6.9-full/fs/ext3/Makefile =================================================================== --- linux-2.6.9-full.orig/fs/ext3/Makefile 2005-12-16 23:16:41.000000000 +0300 -- 1.8.3.1