Commit b1785427 authored by Yan's avatar Yan Committed by Chris Mason

Fix for btrfs_find_free_objectid

btrfs_find_free_objectid may return a used objectid due to arithmetic
underflow. This bug may happen when parameter 'root' is tree root,  so
it may cause serious problems when creating snapshot or sub-volume.
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent e18e4809
...@@ -62,7 +62,6 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, ...@@ -62,7 +62,6 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
struct btrfs_path *path; struct btrfs_path *path;
struct btrfs_key key; struct btrfs_key key;
int ret; int ret;
u64 hole_size = 0;
int slot = 0; int slot = 0;
u64 last_ino = 0; u64 last_ino = 0;
int start_found; int start_found;
...@@ -109,8 +108,7 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, ...@@ -109,8 +108,7 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
if (start_found) { if (start_found) {
if (last_ino < search_start) if (last_ino < search_start)
last_ino = search_start; last_ino = search_start;
hole_size = key.objectid - last_ino; if (key.objectid > last_ino) {
if (hole_size > 0) {
*objectid = last_ino; *objectid = last_ino;
goto found; goto found;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment