Skip to contentSkip to conversation

btrfs: fix chunk map leak in btrfs_map_block() after btrfs_chunk_map_num_copies()

PATCH In review Mark Harmstone 3 participants 3 messages Feb 20

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: fix chunk map leak in btrfs_map_block() after btrfs_chunk_map_num_copies()

Fix a chunk map leak in btrfs_map_block(): if we return early with -EINVAL, we're not freeing the chunk map that we've just looked up.

Fixes 0ae653fbec2b ("btrfs: reduce chunk_map lookups in btrfs_map_block()")
---
 fs/btrfs/volumes.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/btrfs/volumes.c +4 -2
index 1bd3464ccdd8..a1f0fccd552c 100644
@@ -7096,8 +7096,10 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
 	}
 
 	num_copies = btrfs_chunk_map_num_copies(map);
-	if (io_geom.mirror_num > num_copies)
-		return -EINVAL;
+	if (io_geom.mirror_num > num_copies) {
+		ret = -EINVAL;
+		goto out;
+	}
 
 	map_offset = logical - map->start;
 	io_geom.raid56_full_stripe_start = (u64)-1;
Signature · 1 line
2.52.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Mark Harmstone

Fix a chunk map leak in btrfs_map_block(): if we return early with -EINVAL, we're not freeing the chunk map that we've just looked up.

Fixes 0ae653fbec2b ("btrfs: reduce chunk_map lookups in btrfs_map_block()")

Side note: if there's a Fixes tag, we don't need a CC stable tag anymore nowadays.

Quoted 24 lines
---
 fs/btrfs/volumes.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/btrfs/volumes.c +4 -3
index 1bd3464ccdd8..a1f0fccd552c 100644
@@ -7096,8 +7096,10 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
        }
 
        num_copies = btrfs_chunk_map_num_copies(map);
-       if (io_geom.mirror_num > num_copies)
-               return -EINVAL;
+       if (io_geom.mirror_num > num_copies) {
+               ret = -EINVAL;
+               goto out;
+       }
 
        map_offset = logical - map->start;
        io_geom.raid56_full_stripe_start = (u64)-1;
--

2.52.0

maintainer
#2 lore raw
Quoted 5 lines · Filipe Manana
Quoted 4 lines · Mark Harmstone

Fix a chunk map leak in btrfs_map_block(): if we return early with -EINVAL, we're not freeing the chunk map that we've just looked up.

Quoted 8 lines
Quoted 3 lines
Fixes 0ae653fbec2b ("btrfs: reduce chunk_map lookups in btrfs_map_block()")

Side note: if there's a Fixes tag, we don't need a CC stable tag anymore nowadays.

Not true at all, please read:

https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html

You HAVE to have a cc: stable if you know you want it to be added to a stable tree. If you do not do that, you are at the mercy of "when Greg and Sasha get bored and attempt to pick up things that maintainers forgot about".

thanks,

greg k-h