Btrfs: avoid crash when overflowing a dir_item
PATCH 1/1 Btrfs: avoid crash when overflowing a dir_item
When attempting to insert a new dir_item, we were calling btrfs_extent_item() without checking if the leaf has enough space to extend the item. This made btrfs_extent_item() crash through a BUG() call.
Therefore do the check and return ENOSPC if the leaf doesn't have enough space.
--- fs/btrfs/dir-item.c | 2 ++ 1 file changed, 2 insertions(+)
fs/btrfs/dir-item.c +2 -0
@@ -53,6 +53,8 @@ static struct btrfs_dir_item *insert_with_overflow(struct btrfs_trans_handle di =btrfs_match_dir_item_name (root, path, name, name_len);if (di)return ERR_PTR (-EEXIST ); +if (btrfs_leaf_free_space (root, path->nodes[0 ]) < data_size) +return ERR_PTR (-ENOSPC );btrfs_extend_item (root, path, data_size); }else if (ret <0 )return ERR_PTR (ret);
Signature · 1 line
1.9.1
Quoted 4 lines · Filipe Manana
When attempting to insert a new
dir_item, we were callingbtrfs_extent_item()without checking if the leaf has enough space to extend the item. This madebtrfs_extent_item()crash through aBUG()call.
Therefore do the check and return ENOSPC if the leaf doesn't have enough space.
Please ignore, this isn't needed, because btrfs_insert_empty_item / btrfs_search_slot gives us a leaf with enough space when they return -eexist / 0 and -eoverflow otherwise.
Quoted 26 lines
Signed-off-by Filipe Manana <[email protected]>--- fs/btrfs/dir-item.c | 2 ++ 1 file changed, 2 insertions(+)fs/btrfs/dir-item.c +2
-1@@ -53,6 +53,8 @@ static struct btrfs_dir_item *insert_with_overflow(struct btrfs_trans_handle di =btrfs_match_dir_item_name (root, path, name, name_len);if (di)return ERR_PTR (-EEXIST ); +if (btrfs_leaf_free_space (root, path->nodes[0 ]) < data_size) +return ERR_PTR (-ENOSPC );btrfs_extend_item (root, path, data_size); }else if (ret <0 )return ERR_PTR (ret); --1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 5 lines
Filipe David Manana, "Reasonable men adapt themselves to the world. Unreasonable men adapt the world to themselves. That's why all progress depends on unreasonable men."