Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH for-next 0/2] Fix compilation and checker errors in zoned series
@ 2021-01-30 11:26 Johannes Thumshirn
  2021-01-30 11:26 ` [PATCH for-next 1/2] btrfs: fix compilation error for !CONFIG_BLK_DEV_ZONED Johannes Thumshirn
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Johannes Thumshirn @ 2021-01-30 11:26 UTC (permalink / raw)
  To: David Sterba
  Cc: Johannes Thumshirn, Naohiro Aota, Josef Bacik, Julia Lawall,
	linux-btrfs

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(-)

-- 
2.26.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH for-next 1/2] btrfs: fix compilation error for !CONFIG_BLK_DEV_ZONED
  2021-01-30 11:26 [PATCH for-next 0/2] Fix compilation and checker errors in zoned series Johannes Thumshirn
@ 2021-01-30 11:26 ` Johannes Thumshirn
  2021-01-30 11:26 ` [PATCH for-next 2/2] btrfs: fix double free in btrfs_get_dev_zone_info Johannes Thumshirn
  2021-02-01 17:42 ` [PATCH for-next 0/2] Fix compilation and checker errors in zoned series David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Johannes Thumshirn @ 2021-01-30 11:26 UTC (permalink / raw)
  To: David Sterba
  Cc: Johannes Thumshirn, Naohiro Aota, Josef Bacik, Julia Lawall,
	linux-btrfs, kernel test robot

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.

Reported-by: kernel test robot <lkp@intel.com>
Fixes: 086cd11a1848 ("btrfs: cache if block-group is on a sequential zone")
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 fs/btrfs/zoned.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h
index 52789da61fa3..cbd208192ce5 100644
--- a/fs/btrfs/zoned.h
+++ b/fs/btrfs/zoned.h
@@ -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;
 }
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH for-next 2/2] btrfs: fix double free in btrfs_get_dev_zone_info
  2021-01-30 11:26 [PATCH for-next 0/2] Fix compilation and checker errors in zoned series Johannes Thumshirn
  2021-01-30 11:26 ` [PATCH for-next 1/2] btrfs: fix compilation error for !CONFIG_BLK_DEV_ZONED Johannes Thumshirn
@ 2021-01-30 11:26 ` Johannes Thumshirn
  2021-02-01 17:42 ` [PATCH for-next 0/2] Fix compilation and checker errors in zoned series David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Johannes Thumshirn @ 2021-01-30 11:26 UTC (permalink / raw)
  To: David Sterba
  Cc: Johannes Thumshirn, Naohiro Aota, Josef Bacik, Julia Lawall,
	linux-btrfs, kernel test robot, Julia Lawall

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.

Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Julia Lawall <julia.lawall@lip6.fr>
Fixes: 9e802babe329 ("btrfs: allow zoned mode on non-zoned block devices")
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 fs/btrfs/zoned.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 362df27040ff..fd953ec848e6 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -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;
 }
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH for-next 0/2] Fix compilation and checker errors in zoned series
  2021-01-30 11:26 [PATCH for-next 0/2] Fix compilation and checker errors in zoned series Johannes Thumshirn
  2021-01-30 11:26 ` [PATCH for-next 1/2] btrfs: fix compilation error for !CONFIG_BLK_DEV_ZONED Johannes Thumshirn
  2021-01-30 11:26 ` [PATCH for-next 2/2] btrfs: fix double free in btrfs_get_dev_zone_info Johannes Thumshirn
@ 2021-02-01 17:42 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2021-02-01 17:42 UTC (permalink / raw)
  To: Johannes Thumshirn
  Cc: David Sterba, Naohiro Aota, Josef Bacik, Julia Lawall,
	linux-btrfs

On Sat, Jan 30, 2021 at 08:26:42PM +0900, Johannes Thumshirn wrote:
> 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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-02-01 17:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-30 11:26 [PATCH for-next 0/2] Fix compilation and checker errors in zoned series Johannes Thumshirn
2021-01-30 11:26 ` [PATCH for-next 1/2] btrfs: fix compilation error for !CONFIG_BLK_DEV_ZONED Johannes Thumshirn
2021-01-30 11:26 ` [PATCH for-next 2/2] btrfs: fix double free in btrfs_get_dev_zone_info Johannes Thumshirn
2021-02-01 17:42 ` [PATCH for-next 0/2] Fix compilation and checker errors in zoned series David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox