Skip to contentSkip to conversation

Fix compilation and checker errors in zoned series

PATCH In review Johannes Thumshirn 2 participants 4 messages Jan 30, 2021 – Feb 1, 2021 Btrfs file system

lore
Share & tools
lore
#0 lore raw

cover Fix compilation and checker errors in zoned series

Hi David,

The Kbuild Robot and Julia reported two errors in the zoned series which have slipped thorugh.

Here are the fixes.

Johannes Thumshirn (2):
btrfs: fix compilation error for !CONFIG_BLK_DEV_ZONED
btrfs: fix double free in btrfs_get_dev_zone_info

 fs/btrfs/zoned.c | 4 +++-
 fs/btrfs/zoned.h | 3 ++-
 2 files changed, 5 insertions(+), 2 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/2 btrfs: fix compilation error for !CONFIG_BLK_DEV_ZONED

The !CONFIG_BLK_DEV_ZONED case didn't compile correctly because the function btrfs_use_zoned_append() was declared as static inline in zoned.h resulting in multiple definitions of the function.

Fixes 086cd11a1848 ("btrfs: cache if block-group is on a sequential zone")
---
 fs/btrfs/zoned.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/zoned.h +2 -1
index 52789da61fa3..cbd208192ce5 100644
@@ -148,7 +148,8 @@ static inline void btrfs_redirty_list_add(struct btrfs_transaction *trans,
 					  struct extent_buffer *eb) { }
 static inline void btrfs_free_redirty_list(struct btrfs_transaction *trans) { }
 
-bool btrfs_use_zone_append(struct btrfs_inode *inode, struct extent_map *em)
+static inline bool btrfs_use_zone_append(struct btrfs_inode *inode,
+					 struct extent_map *em)
 {
 	return false;
 }
Signature · 1 line
2.26.2
#2 lore raw

PATCH 2/2 btrfs: fix double free in btrfs_get_dev_zone_info

In reply to Johannes Thumshirn

When we end up getting an unsupported zone model in btrfs_get_dev_zone_info() the default error handling case frees all allocated resources, but "zones" was already freed resulting in a double-free and "zone_info" is already assigned to device->zone_info resulting in a potential use-after-free.

For the double free we could also set 'zones = NULL' after freeing, but I think this way is more readable.

Fixes 9e802babe329 ("btrfs: allow zoned mode on non-zoned block devices")
---
 fs/btrfs/zoned.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/btrfs/zoned.c +3 -1
index 362df27040ff..fd953ec848e6 100644
@@ -425,7 +425,7 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device)
 				 bdev_zoned_model(bdev),
 				 rcu_str_deref(device->name));
 		ret = -EOPNOTSUPP;
-		goto out;
+		goto out_free_zone_info;
 	}
 
 	btrfs_info_in_rcu(fs_info,
@@ -437,9 +437,11 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device)
 
 out:
 	kfree(zones);
+out_free_zone_info:
 	bitmap_free(zone_info->empty_zones);
 	bitmap_free(zone_info->seq_zones);
 	kfree(zone_info);
+	device->zone_info = NULL;
 
 	return ret;
 }
Signature · 1 line
2.26.2
#3 lore raw
In reply to Johannes Thumshirn
Quoted 10 lines · Johannes Thumshirn

Hi David,

The Kbuild Robot and Julia reported two errors in the zoned series which have slipped thorugh.

Here are the fixes.

Johannes Thumshirn (2):
btrfs: fix compilation error for !CONFIG_BLK_DEV_ZONED
btrfs: fix double free in btrfs_get_dev_zone_info

Folded, thanks.