]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ext4: Eliminate potential double free on error path
authorJulia Lawall <julia@diku.dk>
Mon, 31 May 2010 02:49:18 +0000 (22:49 -0400)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 2 Aug 2010 17:21:10 +0000 (10:21 -0700)
commit d3533d72e7478a61a3e1936956fc825289a2acf4 upstream (as of v2.6.33-rc3)

b_entry_name and buffer are initially NULL, are initialized within a loop
to the result of calling kmalloc, and are freed at the bottom of this loop.
The loop contains gotos to cleanup, which also frees b_entry_name and
buffer.  Some of these gotos are before the reinitializations of
b_entry_name and buffer.  To maintain the invariant that b_entry_name and
buffer are NULL at the top of the loop, and thus acceptable arguments to
kfree, these variables are now set to NULL after the kfrees.

This seems to be the simplest solution.  A more complicated solution
would be to introduce more labels in the error handling code at the end of
the function.

A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@r@
identifier E;
expression E1;
iterator I;
statement S;
@@

*kfree(E);
... when != E = E1
    when != I(E,...) S
    when != &E
*kfree(E);
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
fs/ext4/xattr.c

index 025701926f9aed63cee73c530ff718a41bdd3946..a95769ae07a1d15672d01e53403cc6e0e507d9fc 100644 (file)
@@ -1327,6 +1327,8 @@ retry:
                        goto cleanup;
                kfree(b_entry_name);
                kfree(buffer);
+               b_entry_name = NULL;
+               buffer = NULL;
                brelse(is->iloc.bh);
                kfree(is);
                kfree(bs);