Skip to contentSkip to conversation

btrfs: oops in device_list_add()

PATCH In review Al Viro 4 participants 4 messages Jan 27, 2019 – Jan 28, 2019 Btrfs file system

lore
Share & tools
lore

Al Viro

author
#0 lore raw

PATCH 1/1 btrfs: oops in device_list_add()

alloc_fs_devices() can return ERR_PTR(-ENOMEM), so
dereferencing its result before the check for IS_ERR() is a bad idea...

Fixes d1a63002829a4

---

fs/btrfs/volumes.c +2 -2
index 85149f27644d..72adc5643bde 100644
@@ -955,11 +955,11 @@ static noinline struct btrfs_device *device_list_add(const char *path,
 		else
 			fs_devices = alloc_fs_devices(disk_super->fsid, NULL);
 
-		fs_devices->fsid_change = fsid_change_in_progress;
-
 		if (IS_ERR(fs_devices))
 			return ERR_CAST(fs_devices);
 
+		fs_devices->fsid_change = fsid_change_in_progress;
+
 		mutex_lock(&fs_devices->device_list_mutex);
 		list_add(&fs_devices->fs_list, &fs_uuids);
 
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Al Viro

alloc_fs_devices() can return ERR_PTR(-ENOMEM), so
dereferencing its result before the check for IS_ERR() is a bad idea...

Fixes d1a63002829a4

Thought this was already fixed, doh...

Quoted 20 lines

---

fs/btrfs/volumes.c +2 -2
index 85149f27644d..72adc5643bde 100644
@@ -955,11 +955,11 @@ static noinline struct btrfs_device *device_list_add(const char *path,
 		else
 			fs_devices = alloc_fs_devices(disk_super->fsid, NULL);
 
-		fs_devices->fsid_change = fsid_change_in_progress;
-
 		if (IS_ERR(fs_devices))
 			return ERR_CAST(fs_devices);
 
+		fs_devices->fsid_change = fsid_change_in_progress;
+
 		mutex_lock(&fs_devices->device_list_mutex);
 		list_add(&fs_devices->fs_list, &fs_uuids);
 
Reviewed-by on v1 1/1
#2 lore raw
In reply to Al Viro
Quoted 6 lines · Al Viro

alloc_fs_devices() can return ERR_PTR(-ENOMEM), so
dereferencing its result before the check for IS_ERR() is a bad idea...

Fixes d1a63002829a4

nice catch.

Quoted 20 lines

---

fs/btrfs/volumes.c +2 -2
index 85149f27644d..72adc5643bde 100644
@@ -955,11 +955,11 @@ static noinline struct btrfs_device *device_list_add(const char *path,
  		else
  			fs_devices = alloc_fs_devices(disk_super->fsid, NULL);
 
-		fs_devices->fsid_change = fsid_change_in_progress;
-
  		if (IS_ERR(fs_devices))
  			return ERR_CAST(fs_devices);
 
+		fs_devices->fsid_change = fsid_change_in_progress;
+
  		mutex_lock(&fs_devices->device_list_mutex);
  		list_add(&fs_devices->fs_list, &fs_uuids);