From: Greg Kroah-Hartman Date: Fri, 1 Mar 2013 01:03:26 +0000 (-0800) Subject: 3.4-stable patches X-Git-Tag: v3.8.2~19 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5f6bf6a65184b3c17a9612b4d0368cdbbfab2a98;p=thirdparty%2Fkernel%2Fstable-queue.git 3.4-stable patches added patches: ext4-check-bh-in-ext4_read_block_bitmap.patch ext4-fix-free-clusters-calculation-in-bigalloc-filesystem.patch ext4-fix-race-in-ext4_mb_add_n_trim.patch ext4-fix-xattr-block-allocation-release-with-bigalloc.patch --- diff --git a/queue-3.4/ext4-check-bh-in-ext4_read_block_bitmap.patch b/queue-3.4/ext4-check-bh-in-ext4_read_block_bitmap.patch new file mode 100644 index 00000000000..6faacdb1c82 --- /dev/null +++ b/queue-3.4/ext4-check-bh-in-ext4_read_block_bitmap.patch @@ -0,0 +1,76 @@ +From 15b49132fc972c63894592f218ea5a9a61b1a18f Mon Sep 17 00:00:00 2001 +From: Eryu Guan +Date: Sat, 12 Jan 2013 16:33:25 -0500 +Subject: ext4: check bh in ext4_read_block_bitmap() + +From: Eryu Guan + +commit 15b49132fc972c63894592f218ea5a9a61b1a18f upstream. + +Validate the bh pointer before using it, since +ext4_read_block_bitmap_nowait() might return NULL. + +I've seen this in fsfuzz testing. + + EXT4-fs error (device loop0): ext4_read_block_bitmap_nowait:385: comm touch: Cannot get buffer for block bitmap - block_group = 0, block_bitmap = 3925999616 + BUG: unable to handle kernel NULL pointer dereference at (null) + IP: [] ext4_wait_block_bitmap+0x25/0xe0 + ... + Call Trace: + [] ext4_read_block_bitmap+0x35/0x60 + [] ext4_free_blocks+0x236/0xb80 + [] ? __getblk+0x36/0x70 + [] ? __find_get_block+0x8f/0x210 + [] ? kmem_cache_free+0x33/0x140 + [] ext4_xattr_release_block+0x1b5/0x1d0 + [] ext4_xattr_delete_inode+0xbe/0x100 + [] ext4_free_inode+0x7c/0x4d0 + [] ? ext4_mark_inode_dirty+0x88/0x230 + [] ext4_evict_inode+0x32c/0x490 + [] evict+0xa7/0x1c0 + [] iput_final+0xe3/0x170 + [] iput+0x3e/0x50 + [] ext4_add_nondir+0x4d/0x90 + [] ext4_create+0xeb/0x170 + [] vfs_create+0xac/0xd0 + [] lookup_open+0x185/0x1c0 + [] ? selinux_inode_permission+0xa9/0x170 + [] do_last+0x2d4/0x7a0 + [] path_openat+0xb3/0x480 + [] ? handle_mm_fault+0x251/0x3b0 + [] do_filp_open+0x49/0xa0 + [] ? __alloc_fd+0xdd/0x150 + [] do_sys_open+0x108/0x1f0 + [] sys_open+0x21/0x30 + [] system_call_fastpath+0x16/0x1b + +Also fix comment for ext4_read_block_bitmap_nowait() + +Signed-off-by: Eryu Guan +Signed-off-by: "Theodore Ts'o" +Signed-off-by: Greg Kroah-Hartman + +--- + fs/ext4/balloc.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +--- a/fs/ext4/balloc.c ++++ b/fs/ext4/balloc.c +@@ -326,7 +326,7 @@ err_out: + return 0; + } + /** +- * ext4_read_block_bitmap() ++ * ext4_read_block_bitmap_nowait() + * @sb: super block + * @block_group: given block group + * +@@ -422,6 +422,8 @@ ext4_read_block_bitmap(struct super_bloc + struct buffer_head *bh; + + bh = ext4_read_block_bitmap_nowait(sb, block_group); ++ if (!bh) ++ return NULL; + if (ext4_wait_block_bitmap(sb, block_group, bh)) { + put_bh(bh); + return NULL; diff --git a/queue-3.4/ext4-fix-free-clusters-calculation-in-bigalloc-filesystem.patch b/queue-3.4/ext4-fix-free-clusters-calculation-in-bigalloc-filesystem.patch new file mode 100644 index 00000000000..e9764103f5a --- /dev/null +++ b/queue-3.4/ext4-fix-free-clusters-calculation-in-bigalloc-filesystem.patch @@ -0,0 +1,61 @@ +From 304e220f0879198b1f5309ad6f0be862b4009491 Mon Sep 17 00:00:00 2001 +From: Lukas Czerner +Date: Fri, 22 Feb 2013 15:27:52 -0500 +Subject: ext4: fix free clusters calculation in bigalloc filesystem + +From: Lukas Czerner + +commit 304e220f0879198b1f5309ad6f0be862b4009491 upstream. + +ext4_has_free_clusters() should tell us whether there is enough free +clusters to allocate, however number of free clusters in the file system +is converted to blocks using EXT4_C2B() which is not only wrong use of +the macro (we should have used EXT4_NUM_B2C) but it's also completely +wrong concept since everything else is in cluster units. + +Moreover when calculating number of root clusters we should be using +macro EXT4_NUM_B2C() instead of EXT4_B2C() otherwise the result might be +off by one. However r_blocks_count should always be a multiple of the +cluster ratio so doing a plain bit shift should be enough here. We +avoid using EXT4_B2C() because it's confusing. + +As a result of the first problem number of free clusters is much bigger +than it should have been and ext4_has_free_clusters() would return 1 even +if there is really not enough free clusters available. + +Fix this by removing the EXT4_C2B() conversion of free clusters and +using bit shift when calculating number of root clusters. This bug +affects number of xfstests tests covering file system ENOSPC situation +handling. With this patch most of the ENOSPC problems with bigalloc file +system disappear, especially the errors caused by delayed allocation not +having enough space when the actual allocation is finally requested. + +Signed-off-by: Lukas Czerner +Signed-off-by: "Theodore Ts'o" +Signed-off-by: Greg Kroah-Hartman + +--- + fs/ext4/balloc.c | 9 +++++++-- + 1 file changed, 7 insertions(+), 2 deletions(-) + +--- a/fs/ext4/balloc.c ++++ b/fs/ext4/balloc.c +@@ -449,11 +449,16 @@ static int ext4_has_free_clusters(struct + + free_clusters = percpu_counter_read_positive(fcc); + dirty_clusters = percpu_counter_read_positive(dcc); +- root_clusters = EXT4_B2C(sbi, ext4_r_blocks_count(sbi->s_es)); ++ ++ /* ++ * r_blocks_count should always be multiple of the cluster ratio so ++ * we are safe to do a plane bit shift only. ++ */ ++ root_clusters = ext4_r_blocks_count(sbi->s_es) >> sbi->s_cluster_bits; + + if (free_clusters - (nclusters + root_clusters + dirty_clusters) < + EXT4_FREECLUSTERS_WATERMARK) { +- free_clusters = EXT4_C2B(sbi, percpu_counter_sum_positive(fcc)); ++ free_clusters = percpu_counter_sum_positive(fcc); + dirty_clusters = percpu_counter_sum_positive(dcc); + } + /* Check whether we have space after accounting for current diff --git a/queue-3.4/ext4-fix-race-in-ext4_mb_add_n_trim.patch b/queue-3.4/ext4-fix-race-in-ext4_mb_add_n_trim.patch new file mode 100644 index 00000000000..331652807d1 --- /dev/null +++ b/queue-3.4/ext4-fix-race-in-ext4_mb_add_n_trim.patch @@ -0,0 +1,46 @@ +From f1167009711032b0d747ec89a632a626c901a1ad Mon Sep 17 00:00:00 2001 +From: Niu Yawei +Date: Fri, 1 Feb 2013 21:31:27 -0500 +Subject: ext4: fix race in ext4_mb_add_n_trim() + +From: Niu Yawei + +commit f1167009711032b0d747ec89a632a626c901a1ad upstream. + +In ext4_mb_add_n_trim(), lg_prealloc_lock should be taken when +changing the lg_prealloc_list. + +Signed-off-by: Niu Yawei +Signed-off-by: "Theodore Ts'o" +Signed-off-by: Greg Kroah-Hartman + +--- + fs/ext4/mballoc.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +--- a/fs/ext4/mballoc.c ++++ b/fs/ext4/mballoc.c +@@ -4126,7 +4126,7 @@ static void ext4_mb_add_n_trim(struct ex + /* The max size of hash table is PREALLOC_TB_SIZE */ + order = PREALLOC_TB_SIZE - 1; + /* Add the prealloc space to lg */ +- rcu_read_lock(); ++ spin_lock(&lg->lg_prealloc_lock); + list_for_each_entry_rcu(tmp_pa, &lg->lg_prealloc_list[order], + pa_inode_list) { + spin_lock(&tmp_pa->pa_lock); +@@ -4150,12 +4150,12 @@ static void ext4_mb_add_n_trim(struct ex + if (!added) + list_add_tail_rcu(&pa->pa_inode_list, + &lg->lg_prealloc_list[order]); +- rcu_read_unlock(); ++ spin_unlock(&lg->lg_prealloc_lock); + + /* Now trim the list to be not more than 8 elements */ + if (lg_prealloc_count > 8) { + ext4_mb_discard_lg_preallocations(sb, lg, +- order, lg_prealloc_count); ++ order, lg_prealloc_count); + return; + } + return ; diff --git a/queue-3.4/ext4-fix-xattr-block-allocation-release-with-bigalloc.patch b/queue-3.4/ext4-fix-xattr-block-allocation-release-with-bigalloc.patch new file mode 100644 index 00000000000..7d5e0cc2522 --- /dev/null +++ b/queue-3.4/ext4-fix-xattr-block-allocation-release-with-bigalloc.patch @@ -0,0 +1,62 @@ +From 1231b3a1eb5740192aeebf5344dd6d6da000febf Mon Sep 17 00:00:00 2001 +From: Lukas Czerner +Date: Mon, 18 Feb 2013 12:12:07 -0500 +Subject: ext4: fix xattr block allocation/release with bigalloc + +From: Lukas Czerner + +commit 1231b3a1eb5740192aeebf5344dd6d6da000febf upstream. + +Currently when new xattr block is created or released we we would call +dquot_free_block() or dquot_alloc_block() respectively, among the else +decrementing or incrementing the number of blocks assigned to the +inode by one block. + +This however does not work for bigalloc file system because we always +allocate/free the whole cluster so we have to count with that in +dquot_free_block() and dquot_alloc_block() as well. + +Use the clusters-to-blocks conversion EXT4_C2B() when passing number of +blocks to the dquot_alloc/free functions to fix the problem. + +The problem has been revealed by xfstests #117 (and possibly others). + +Signed-off-by: Lukas Czerner +Signed-off-by: "Theodore Ts'o" +Reviewed-by: Eric Sandeen +Signed-off-by: Greg Kroah-Hartman + +--- + fs/ext4/xattr.c | 7 ++++--- + 1 file changed, 4 insertions(+), 3 deletions(-) + +--- a/fs/ext4/xattr.c ++++ b/fs/ext4/xattr.c +@@ -495,7 +495,7 @@ ext4_xattr_release_block(handle_t *handl + error = ext4_handle_dirty_metadata(handle, inode, bh); + if (IS_SYNC(inode)) + ext4_handle_sync(handle); +- dquot_free_block(inode, 1); ++ dquot_free_block(inode, EXT4_C2B(EXT4_SB(inode->i_sb), 1)); + ea_bdebug(bh, "refcount now=%d; releasing", + le32_to_cpu(BHDR(bh)->h_refcount)); + } +@@ -784,7 +784,8 @@ inserted: + else { + /* The old block is released after updating + the inode. */ +- error = dquot_alloc_block(inode, 1); ++ error = dquot_alloc_block(inode, ++ EXT4_C2B(EXT4_SB(sb), 1)); + if (error) + goto cleanup; + error = ext4_journal_get_write_access(handle, +@@ -880,7 +881,7 @@ cleanup: + return error; + + cleanup_dquot: +- dquot_free_block(inode, 1); ++ dquot_free_block(inode, EXT4_C2B(EXT4_SB(sb), 1)); + goto cleanup; + + bad_block: diff --git a/queue-3.4/series b/queue-3.4/series index 67b1408e554..280a61e2ca1 100644 --- a/queue-3.4/series +++ b/queue-3.4/series @@ -21,3 +21,7 @@ firewire-add-minor-number-range-check-to-fw_device_init.patch sysctl-fix-null-checking-in-bin_dn_node_address.patch fs-fix-possible-use-after-free-with-aio.patch media-rc-unlock-on-error-in-show_protocols.patch +ext4-check-bh-in-ext4_read_block_bitmap.patch +ext4-fix-race-in-ext4_mb_add_n_trim.patch +ext4-fix-xattr-block-allocation-release-with-bigalloc.patch +ext4-fix-free-clusters-calculation-in-bigalloc-filesystem.patch