]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ext4: implement error handling of ext4_mb_new_preallocation()
authorAlexey Khoroshilov <khoroshilov@ispras.ru>
Mon, 17 Jun 2013 13:15:34 +0000 (09:15 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 17 Jun 2013 13:15:34 +0000 (09:15 -0400)
If memory allocation in ext4_mb_new_group_pa() is failed,
it returns error code, ext4_mb_new_preallocation() propages it,
but ext4_mb_new_blocks() ignores it.

An observed result was:

- allocation fail means ext4_mb_new_group_pa() does not update
  ext4_allocation_context;

- ext4_mb_new_blocks() sets ext4_allocation_request->len (ar->len =
  ac->ac_b_ex.fe_len;) to number of blocks preallocated (512) instead
  of number of blocks requested (1);

- that activates update cycle in ext4_splice_branch():
    for (i = 1; i < blks; i++) <-- blks is 512 instead of 1 here
      *(where->p + i) = cpu_to_le32(current_block++);

- it iterates 511 times and corrupts a chunk of memory including inode
  structure;

- page fault happens at EXT4_SB(inode->i_sb) in ext4_mark_inode_dirty();

- system hangs with 'scheduling while atomic' BUG.

The patch implements a check for ext4_mb_new_preallocation() error
code and handles its failure as if ext4_mb_regular_allocator() fails.

Found by Linux File System Verification project (linuxtesting.org).

[ Patch restructed by tytso to make the flow of control easier to follow. ]

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
fs/ext4/mballoc.c

index 1a9c22b45a01ddb25bbe7d3ea82649fe705ebf6b..a9ff5e5137ca85306f408eda2cab09669962f603 100644 (file)
@@ -4406,17 +4406,20 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,
 repeat:
                /* allocate space in core */
                *errp = ext4_mb_regular_allocator(ac);
-               if (*errp) {
-                       ext4_discard_allocated_blocks(ac);
-                       goto errout;
-               }
+               if (*errp)
+                       goto discard_and_exit;
 
                /* as we've just preallocated more space than
-                * user requested orinally, we store allocated
+                * user requested originally, we store allocated
                 * space in a special descriptor */
                if (ac->ac_status == AC_STATUS_FOUND &&
-                               ac->ac_o_ex.fe_len < ac->ac_b_ex.fe_len)
-                       ext4_mb_new_preallocation(ac);
+                   ac->ac_o_ex.fe_len < ac->ac_b_ex.fe_len)
+                       *errp = ext4_mb_new_preallocation(ac);
+               if (*errp) {
+               discard_and_exit:
+                       ext4_discard_allocated_blocks(ac);
+                       goto errout;
+               }
        }
        if (likely(ac->ac_status == AC_STATUS_FOUND)) {
                *errp = ext4_mb_mark_diskspace_used(ac, handle, reserv_clstrs);