Omar Sandoval 5ca64f45e9 btrfs: fix race on ENOMEM in alloc_extent_buffer
Consider the following interleaving of overlapping calls to
alloc_extent_buffer:

Call 1:

- Successfully allocates a few pages with find_or_create_page
- find_or_create_page fails, goto free_eb
- Unlocks the allocated pages

Call 2:
- Calls find_or_create_page and gets a page in call 1's extent_buffer
- Finds that the page is already associated with an extent_buffer
- Grabs a reference to the half-written extent_buffer and calls
  mark_extent_buffer_accessed on it

mark_extent_buffer_accessed will then try to call mark_page_accessed on
a null page and panic.

The fix is to decrement the reference count on the half-written
extent_buffer before unlocking the pages so call 2 won't use it. We
should also set exists = NULL in the case that we don't use exists to
avoid accidentally returning a freed extent_buffer in an error case.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
Reviewed-by: David Sterba <dsterba@suse.cz>
Reviewed-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: Chris Mason <clm@fb.com>
2015-04-26 06:27:00 -07:00
..
2014-08-08 15:57:24 -07:00
2015-02-16 17:56:03 -08:00
2014-08-07 14:40:09 -04:00
2015-03-18 10:29:48 +01:00
2015-02-15 11:11:47 -08:00
2015-02-05 16:34:25 +01:00
2014-11-19 13:01:20 -05:00
2015-02-20 04:56:44 -05:00
2015-02-16 17:56:04 -08:00
2014-05-06 17:39:42 -04:00
2015-01-29 00:13:13 -05:00
2014-08-26 09:35:56 +02:00
2014-11-19 13:01:26 -05:00