diff options
author | Julia Lawall <julia@diku.dk> | 2009-12-23 07:52:31 -0500 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2009-12-23 07:52:31 -0500 |
commit | d3533d72e7478a61a3e1936956fc825289a2acf4 (patch) | |
tree | 5932e890fa8185bd792a94730725665a26a6102a /fs/ext4 | |
parent | a6b43e382568a49cc64291bfaddf896652d44f70 (diff) |
ext4: Eliminate potential double free on error path
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>
Diffstat (limited to 'fs/ext4')
-rw-r--r-- | fs/ext4/xattr.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index 83218bebbc7c..f3a2f7ed45aa 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c | |||
@@ -1332,6 +1332,8 @@ retry: | |||
1332 | goto cleanup; | 1332 | goto cleanup; |
1333 | kfree(b_entry_name); | 1333 | kfree(b_entry_name); |
1334 | kfree(buffer); | 1334 | kfree(buffer); |
1335 | b_entry_name = NULL; | ||
1336 | buffer = NULL; | ||
1335 | brelse(is->iloc.bh); | 1337 | brelse(is->iloc.bh); |
1336 | kfree(is); | 1338 | kfree(is); |
1337 | kfree(bs); | 1339 | kfree(bs); |