diff options
author | Josef Bacik <jbacik@fusionio.com> | 2012-07-20 16:11:08 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@fusionio.com> | 2012-07-23 16:28:09 -0400 |
commit | 594831c4b232b094d645503ecedec2e35dcebdf3 (patch) | |
tree | 27867ddba8f36d9dc4946c5beee2f18d7be8c861 /fs/btrfs | |
parent | e64860aa05048fa7a8483ca698b17c2caf5625cf (diff) |
Btrfs: fix potential race in extent buffer freeing
This sounds sort of impossible but it is the only thing I can think of and
at the very least it is theoretically possible so here it goes.
If we are in try_release_extent_buffer we will check that the ref count on
the extent buffer is 1 and not under IO, and then go down and clear the tree
ref. If between this check and clearing the tree ref somebody else comes in
and grabs a ref on the eb and the marks it dirty before
try_release_extent_buffer() does it's tree ref clear we can end up with a
dirty eb that will be freed while it is still dirty which will result in a
panic. Thanks,
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/extent_io.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index e6243f787434..e1939a6c7478 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c | |||
@@ -4123,11 +4123,10 @@ static void check_buffer_tree_ref(struct extent_buffer *eb) | |||
4123 | * So bump the ref count first, then set the bit. If someone | 4123 | * So bump the ref count first, then set the bit. If someone |
4124 | * beat us to it, drop the ref we added. | 4124 | * beat us to it, drop the ref we added. |
4125 | */ | 4125 | */ |
4126 | if (!test_bit(EXTENT_BUFFER_TREE_REF, &eb->bflags)) { | 4126 | spin_lock(&eb->refs_lock); |
4127 | if (!test_and_set_bit(EXTENT_BUFFER_TREE_REF, &eb->bflags)) | ||
4127 | atomic_inc(&eb->refs); | 4128 | atomic_inc(&eb->refs); |
4128 | if (test_and_set_bit(EXTENT_BUFFER_TREE_REF, &eb->bflags)) | 4129 | spin_unlock(&eb->refs_lock); |
4129 | atomic_dec(&eb->refs); | ||
4130 | } | ||
4131 | } | 4130 | } |
4132 | 4131 | ||
4133 | static void mark_extent_buffer_accessed(struct extent_buffer *eb) | 4132 | static void mark_extent_buffer_accessed(struct extent_buffer *eb) |
@@ -4239,9 +4238,7 @@ again: | |||
4239 | goto free_eb; | 4238 | goto free_eb; |
4240 | } | 4239 | } |
4241 | /* add one reference for the tree */ | 4240 | /* add one reference for the tree */ |
4242 | spin_lock(&eb->refs_lock); | ||
4243 | check_buffer_tree_ref(eb); | 4241 | check_buffer_tree_ref(eb); |
4244 | spin_unlock(&eb->refs_lock); | ||
4245 | spin_unlock(&tree->buffer_lock); | 4242 | spin_unlock(&tree->buffer_lock); |
4246 | radix_tree_preload_end(); | 4243 | radix_tree_preload_end(); |
4247 | 4244 | ||